From 2bccbf9ded3dc4d7c96d482e67c7f42305589ae8 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Fri, 19 Feb 2021 14:01:45 +0100 Subject: [PATCH] bundles/icinga2: add some emoji to sent SMS, don't send output via SMS if everything is fine --- .../files/scripts/icinga_notification_wrapper | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/bundles/icinga2/files/scripts/icinga_notification_wrapper b/bundles/icinga2/files/scripts/icinga_notification_wrapper index 1fe43b0..98a3a47 100644 --- a/bundles/icinga2/files/scripts/icinga_notification_wrapper +++ b/bundles/icinga2/files/scripts/icinga_notification_wrapper @@ -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 }