import datetime import logging from systemd.journal import JournalHandler # Logging log = logging.getLogger(__name__) log.addHandler(JournalHandler()) log.setLevel(logging.INFO) class HostData: """ Data related to notifications related to a given host """ def __init__(self, name): self.name = name # Concerning services self.serviceLastType = "" self.serviceLastStatus = "" self.serviceLastText = "" # Concerning host self.lastType = "" self.lastStatus = "" # Tools self.linkedMUC = "" self.notifCount = 0 self.needUpdate = False self.maintainer = "Tout le monde" class DataStore: def __init__(self, linkedBot): log.info("Created DataStore") self.knownHosts = {} self.knownMaintainers = {} self.linkedBot = linkedBot def push(self, msg): # TYPE|HOST/SERVICE|STATE|OUTPUT|SENDER|COMMENT # 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))