diff --git a/messagetools.py b/messagetools.py index d3c014b..e407317 100644 --- a/messagetools.py +++ b/messagetools.py @@ -6,7 +6,21 @@ class UnsupportedStruct(Exception): super().__init__(self.message) def make_icinga_message(struct): - pass + + first_line = "{state} - {service} ({host})".format(state=struct.get("state"), + service=struct.get("service_name"), host=struct.get("service_host")) + second_line = struct.get("service_output") or "" + third_line = "Direkt-Link: {link}".format(link=struct.get("icingaeweb_url")) + + if not struct.get("owners") and not struct.get("owner-groups"): + fourth_line = "Notification to: admins (default)" + else: + owners = struct.get("owners") or [] + groups = struct.get("owner-groups") or [] + groups_strings = [ g + "-group" for g in groups ] + fourth_line = "Notification to: " + ", ".join(owners) + " " + ", ".join(groups_strings) + + return "\n".join([first_line, second_line, third_line, fourth_line]) def make_generic_message(struct): pass