diff --git a/serviceData.py b/serviceData.py index 59e741a..f8f42de 100644 --- a/serviceData.py +++ b/serviceData.py @@ -25,6 +25,9 @@ class ServiceData: elif self.serviceData[host]["status_type"] == "UNKNOWN": msg = "{}, état de {} inconnu ({})".format(maintainer, host, text) + + elif self.serviceData[host]["status_type"] == "CUSTOM": + msg = "{}, nouvelle notification de {} ({})".format(maintainer, host, text) elif self.serviceData[host]["status_type"] == "RECOVERY": msg = "{}, problème résolu sur {} ({})".format(maintainer, host, text) @@ -59,41 +62,30 @@ class ServiceData: def push(self, msg): - # Get current time - curtime = datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S") - - # separate dest and message - destmuc, rmsg = msg.split("|") - - # separate and parse lines - cutmsg_l0 = rmsg.split("\n")[0].split(" ") - cutmsg_l1 = rmsg.split("\n")[1].split("-") - - # get the status of location - status_type = cutmsg_l0[0].replace(" ", "") - status_state = cutmsg_l0[-1].replace(" ", "") - - # get the location - location = "" - for i in range(len(cutmsg_l0) - 2): - location += cutmsg_l0[i+1] + " " - location = location[:-1] - - # check if message is about a service or host - if len(location.split("/")) > 1: - host, service = location.split("/") - else: - host = location - service = False - - text = status_state + ": " + cutmsg_l1[1].split("(")[0][1:] - - raw = rmsg.split("\n")[1] - - print("Dest: %s, Msg: %s" % (destmuc, rmsg)) - print("Status: %s" % (status_type + " (" + status_state + ")")) - print("Host: %s, Service: %s" % (host, service)) - print("Text: %s" % (text)) + # $notification.type$|$host.display_name$/$service.name$|$service.state$|$service.output$|$notification.author$|$notification.comment$ + # EX: cominfra@salons.a-lec.org|CUSTOM|ctrlv.chalec.org/SSH server|CRITICAL|connect to address ctrlv.chalec.org and port 22: Connexion refusée|neox@a-lec.org|AGAIN + try: + # Get current time + curtime = datetime.datetime.now().strftime("%m/%d/%Y, %H:%M:%S") + + # Get all params + destmuc, status_type, location, status_state, text, sender, comment = msg.split("|") + print("Dest: %s, Msg: %s" % (destmuc, msg)) + print("Status: %s" % (status_type + " (" + status_state + ")")) + + # check if message is about a service or host + if len(location.split("/")) > 1: + host, service = location.split("/") + else: + host = location + service = False + print("Host: %s, Service: %s" % (host, service)) + + print("Text: %s" % (text)) + + except Exception as e: + print("ERROR in serviceData.push():" + str(e)) + return # Is that host known if host in self.serviceData: @@ -148,7 +140,6 @@ class ServiceData: self.serviceData[host][service]["status_state"] = status_state self.serviceData[host][service]["status_type"] = status_type self.serviceData[host][service]["text"] = text - self.serviceData[host][service]["raw"] = raw self.serviceData[host][service]["needUpdate"] = True maintainer = self.serviceData[host]["maintainer"] @@ -175,8 +166,8 @@ class ServiceData: self.maintainerData[maintainer][host] = [] self.maintainerData[maintainer][host].append( - curtime + ": " + service + "/" + raw - ) + "%s [%s]: %s %s (%s %s)" % (curtime, status_state, service, text, sender, comment) + ) print(self.serviceData) print("Flushing...")