icinga2-checks/matrix-host-notification.py

41 lines
1.9 KiB
Python
Raw Normal View History

2023-04-21 23:54:16 -06:00
import argparse
import checker.synapse_client as synapse_client
from checker.notify import build_msg
parser = argparse.ArgumentParser(description='')
parser.add_argument('--user', required=True, help='User ID for the bot.')
parser.add_argument('--pw', required=True, help='Password for the bot.')
parser.add_argument('--hs', required=True, help='Homeserver of the bot.')
parser.add_argument('--room', required=True, help='The room the bot should send its messages in.')
parser.add_argument('--auth-file', help="File to cache the bot's login details to.")
parser.add_argument('--longdatetime', required=True, help='$icinga.long_date_time$')
parser.add_argument('--hostname', required=True, help='$host.name$')
parser.add_argument('--hostdisplayname', required=True, help='$host.display_name$')
parser.add_argument('--hoststate', required=True, help='$host.state$')
parser.add_argument('--hostoutput', required=True, help='$host.output$')
parser.add_argument('--notificationtype', required=True, help='$notification.type$')
parser.add_argument('--hostaddress', required=False, help='$address$')
parser.add_argument('--notificationauthor', required=False, help='$notification.author$')
parser.add_argument('--notificationcomment', required=False, help='$notification.comment$')
parser.add_argument('--icinga2weburl', required=False, help='$notification.icingaweb2url$')
args = parser.parse_args()
if __name__ == '__main__':
msg = build_msg(
host_name=args.hostname,
host_display_name=args.hostdisplayname,
state=args.hoststate,
date_str=args.longdatetime,
output=args.hostoutput,
address=args.hostaddress,
comment=args.notificationcomment,
author=args.notificationauthor,
icinga2_url=args.icinga2weburl
)
access_token, client = synapse_client.login(args.user, args.pw, args.hs, args.auth_file, args.room)
synapse_client.send_msg(client, args.room, msg)