import pickle # Isengard commands def cmdping(owners, nick, text, sbuf): """ Ping command. """ return "pong !" def cmdhelp(owners, nick, text, sbuf): """ Ping command. """ global commandtable msg = "Je suis Isengard, le bot de supervision de ce salon.\n" msg += "\n" msg += "Voici la liste de mes commandes disponibles : \n" for cmd in commandtable: msg += "- " + cmd + "\n" return msg def cmdmainteneur(owners, nick, text, sbuf): """ Change maintainer for an host """ if not nick in owners: return "désolé mais vous n'êtes pas autorisé à utiliser cette commande." try: splittedtext = text.split(" ") # print maintainer if len(splittedtext) == 2: host = splittedtext[1] return "le responsable de cette machine est " \ + sbuf.serviceData[host]["maintainer"] if len(splittedtext) == 3: host = splittedtext[1] maintainer = splittedtext[2] sbuf.serviceData[host] = {} sbuf.serviceData[host]["destmuc"] = None sbuf.serviceData[host]["status_state"] = None sbuf.serviceData[host]["status_type"] = None sbuf.serviceData[host]["text"] = None sbuf.serviceData[host]["raw"] = None sbuf.serviceData[host]["needUpdate"] = False sbuf.serviceData[host]["maintainer"] = maintainer return "le responsable est à présent " \ + sbuf.serviceData[host]["maintainer"] except Exception as e: print(repr(e)) return "Erreur à l'exécution" return "Syntaxe invalide" def cmdsave(owners, nick, text, sbuf): """ Save """ if not nick in owners: return "désolé mais vous n'êtes pas autorisé à utiliser cette commande." try: with open('current_buffer', 'wb') as current_buffer_file: pickle.dump(sbuf.serviceData, current_buffer_file) return "OK" except Exception as e: print(repr(e)) return "Erreur à l'exécution" def cmdload(owners, nick, text, sbuf): """ Save """ if not nick in owners: return "désolé mais vous n'êtes pas autorisé à utiliser cette commande." try: with open('current_buffer', 'rb') as current_buffer_file: sbuf.serviceData = pickle.load(current_buffer_file) return "OK" except Exception as e: print(repr(e)) return "Erreur à l'exécution" def cmdhist(owners, nick, text, sbuf): """ Check history for a maintainer """ if not nick in sbuf.maintainerData or len(sbuf.maintainerData[nick]) == 0: return "pas d'historique disponible pour vous." msg = "voici historique pour le mainteneur %s (vous) :\n" % nick for host in sbuf.maintainerData[nick]: msg += "\nHôte %s:" % host for serviceline in sbuf.maintainerData[nick][host]: msg += "- %s" % serviceline + "\n" sbuf.maintainerData[nick] = {} return msg # Commands commandtable = { "help" : cmdhelp, "hist" : cmdhist, "load" : cmdload, "mainteneur" : cmdmainteneur, "ping" : cmdping, "save" : cmdsave, }