From 18d1b2acf8434cf5190e48e0717a4fe42eaf8566 Mon Sep 17 00:00:00 2001 From: Philipp Dallig Date: Mon, 18 Jun 2018 22:18:05 +0200 Subject: [PATCH] Make the emoji code nicer --- mattermost.py | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/mattermost.py b/mattermost.py index 7b28eae..f4f0048 100755 --- a/mattermost.py +++ b/mattermost.py @@ -25,7 +25,7 @@ import urllib import urllib2 -VERSION = "0.2.2" +VERSION = "0.2.3" TEMPLATE_HOST = "__{notificationtype}__ {hostalias} is {hoststate} - {hostoutput}" # noqa TEMPLATE_SERVICE = "__{notificationtype}__ {hostalias}/{servicedesc} is {servicestate} - {serviceoutput}" # noqa @@ -52,33 +52,25 @@ def parse(): args = parser.parse_args() return args +def emoji(notificationtype): + return { + "RECOVERY": ":white_check_mark:", + "PROBLEM": ":fire:", + "DOWNTIMESTART": ":clock10:", + "DOWNTIMEEND": ":sunny:", + "DOWNTIMEREMOVED": "", + "CUSTOM": ":sound:", + "FLAPPINGSTART": ":cloud:", + "FLAPPINGEND": ":sunny:", + "ACKNOWLEDGEMENT": ":exclamation:", + }.get(notificationtype, "") def make_data(args): template = TEMPLATE_SERVICE if args.servicestate else TEMPLATE_HOST # Emojis - if args.notificationtype == "RECOVERY": - EMOJI = ":white_check_mark:" - elif args.notificationtype == "PROBLEM": - EMOJI = ":fire:" - elif args.notificationtype == "DOWNTIMESTART": - EMOJI = ":clock10:" - elif args.notificationtype == "DOWNTIMEEND": - EMOJI = ":sunny:" - elif args.notificationtype == "DOWNTIMEREMOVED": - EMOJI = "" - elif args.notificationtype == "CUSTOM": - EMOJI = ":sound:" - elif args.notificationtype == "FLAPPINGSTART": - EMOJI = ":cloud:" - elif args.notificationtype == "FLAPPINGEND": - EMOJI = ":sunny:" - elif args.notificationtype == "ACKNOWLEDGEMENT": - EMOJI = ":exclamation:" - else: - EMOJI = "" - text = EMOJI + template.format(**vars(args)) + text = emoji(args.notificationtype) + template.format(**vars(args)) if args.oneline: text = text.splitlines()[0]