Matrix handler initial
This commit is contained in:
parent
f69ef64fce
commit
73b5ff36cd
35
handlers/matrix/matrix.py
Normal file
35
handlers/matrix/matrix.py
Normal file
@ -0,0 +1,35 @@
|
||||
from matrix_client.client import MatrixClient
|
||||
import json
|
||||
import sys
|
||||
|
||||
# Load config
|
||||
conf = json.load('/etc/sensu/handlers/notifications/matrix.json')
|
||||
|
||||
# Sensu event JSON
|
||||
sensu_json = sys.stdin.read()
|
||||
sensu_event = json.loads(sensu_json)
|
||||
|
||||
# Status codes
|
||||
statuses = {
|
||||
'2': '**CRITICAL**: ',
|
||||
'1': '*WARNING*: ',
|
||||
'0': 'OK: '
|
||||
}
|
||||
|
||||
# Event information
|
||||
client = sensu_event['client']['name']
|
||||
check = sensu_event['check']['name']
|
||||
output = sensu_event['check']['output']
|
||||
status = statuses[sensu_event['check']['status']]
|
||||
|
||||
# Message text
|
||||
text = status + client + "\n" + output
|
||||
|
||||
# Initialize Matrix client
|
||||
client = MatrixClient(conf['homeserver'])
|
||||
token = client.login_with_password(username=conf['username'],
|
||||
password=conf['password'])
|
||||
# Join to Room
|
||||
room = client.join_room(conf['room'])
|
||||
|
||||
room.send_text(text)
|
Loading…
Reference in New Issue
Block a user