From 4b127ac1c6053412852795c823a292aee7574812 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Fri, 17 Mar 2023 11:46:15 +0100 Subject: [PATCH] =?UTF-8?q?R=C3=A9cup=C3=A9ration=20de=20d=C3=A9connexion?= =?UTF-8?q?=20et=20non=20notification=20des=20=C3=A9tats=20non=20graves?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.py | 6 +++++- main.py | 40 +++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/data.py b/data.py index cffb09f..6c1185a 100644 --- a/data.py +++ b/data.py @@ -14,6 +14,7 @@ PRIORITY = { "CRITICAL":2, "UNKNOWN": 2, "DOWN": 3, + "DRBD": 3 } @@ -158,6 +159,9 @@ class DataStore: # Service problem else: + if "DRBD" in service: + status = "DRBD" + cur_problem = None # Look for existing problem @@ -191,7 +195,7 @@ class DataStore: cur.status = worst_problem.status cur.worst = worst_problem.name - if PRIORITY[status] >= 2 or ("RECOVERY" in mtype and cur.worst == None): + if PRIORITY[status] >= 2: self.notify(destmuc) return diff --git a/main.py b/main.py index 7495fd5..8fb5edc 100755 --- a/main.py +++ b/main.py @@ -14,25 +14,27 @@ from bot import MUCBot from data import DataStore from localServer import LocalServer +def cleanExit(): + global localservthread + localservthread.pleaseStop = True + time.sleep(1) + # stop tcp server + sockfd = socket.socket() + port = 12346 + sockfd.connect(('127.0.0.1', port)) + sockfd.send(b'') + sockfd.close() + time.sleep(1) + + exit(0) + + +def signalHandler(sig, frame): + log.info("Exiting...") + cleanExit() + if __name__ == '__main__': - def cleanExit(): - global localservthread - localservthread.pleaseStop = True - # stop tcp server - sockfd = socket.socket() - port = 12346 - sockfd.connect(('127.0.0.1', port)) - sockfd.send(b'') - sockfd.close() - - exit(0) - - - def signalHandler(sig, frame): - log.info("Exiting...") - cleanExit() - # Register SIGINT signal handler signal.signal(signal.SIGINT, signalHandler) @@ -114,7 +116,8 @@ if __name__ == '__main__': exit(1) try: - xmpp.process() + log.info("Launching XMPP connection until disconnection (ERRORS: %s)" % ERRORS) + xmpp.loop.run_until_complete(xmpp.disconnected) except KeyboardInterrupt: cleanExit() except Exception as e: @@ -122,6 +125,5 @@ if __name__ == '__main__': if ERRORS >= 3: log.critical("3 consecutive errors. Aborting...") cleanExit() - ERRORS += 1 del xmpp