bundles/icinga2: add some emoji to sent SMS, don't send output via SMS if everything is fine
All checks were successful
bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2021-02-19 14:01:45 +01:00
parent bb661b391b
commit 2bccbf9ded
Signed by: kunsi
GPG key ID: 12E3D2136B818350

View file

@ -11,6 +11,14 @@ from sys import argv
SIPGATE_USER='${node.metadata['icinga2']['sipgate_user']}'
SIPGATE_PASS='${node.metadata['icinga2']['sipgate_pass']}'
STATUS_TO_EMOJI = {
'critical': '🔥',
'down': '🚨🚨🚨',
'ok': '🆗',
'up': '👌',
'warning': '⚡⚡',
}
parser = ArgumentParser(
prog='icinga_notification_wrapper',
description='Icinga2 Notification Wrapper',
@ -59,13 +67,27 @@ def log_to_syslog(message):
def notify_per_sms():
message = {
'message': 'ICINGA: {host}{service} is {state}: {output}'.format(
if args.state.lower() in ['up', 'ok']:
output_text = ''
else:
output_text = '\n\n{}'.format(args.output)
if args.state.lower() in STATUS_TO_EMOJI:
message_text = '{emoji} {host}{service} {emoji}{output}'.format(
emoji=STATUS_TO_EMOJI[args.state.lower()],
host=args.host_name,
service=('/'+args.service_name if args.service_name else ''),
state=args.state.upper(),
output=args.output
),
output=output_text,
)
else:
message_text = 'ICINGA: {host}{service} is {state}{output}'.format(
host=args.host_name,
service=('/'+args.service_name if args.service_name else ''),
state=args.state.upper(),
output=output_text,
)
message = {
'message': message_text,
'smsId': 's0', # XXX what does this mean? Documentation is unclear
'recipient': args.sms
}