Récupération de déconnexion et non notification des états non graves

This commit is contained in:
Adrien Bourmault 2023-03-17 11:46:15 +01:00
parent 81ac8af5cc
commit 4b127ac1c6
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
2 changed files with 26 additions and 20 deletions

View File

@ -14,6 +14,7 @@ PRIORITY = {
"CRITICAL":2, "CRITICAL":2,
"UNKNOWN": 2, "UNKNOWN": 2,
"DOWN": 3, "DOWN": 3,
"DRBD": 3
} }
@ -158,6 +159,9 @@ class DataStore:
# Service problem # Service problem
else: else:
if "DRBD" in service:
status = "DRBD"
cur_problem = None cur_problem = None
# Look for existing problem # Look for existing problem
@ -191,7 +195,7 @@ class DataStore:
cur.status = worst_problem.status cur.status = worst_problem.status
cur.worst = worst_problem.name cur.worst = worst_problem.name
if PRIORITY[status] >= 2 or ("RECOVERY" in mtype and cur.worst == None): if PRIORITY[status] >= 2:
self.notify(destmuc) self.notify(destmuc)
return return

10
main.py
View File

@ -14,17 +14,17 @@ from bot import MUCBot
from data import DataStore from data import DataStore
from localServer import LocalServer from localServer import LocalServer
if __name__ == '__main__':
def cleanExit(): def cleanExit():
global localservthread global localservthread
localservthread.pleaseStop = True localservthread.pleaseStop = True
time.sleep(1)
# stop tcp server # stop tcp server
sockfd = socket.socket() sockfd = socket.socket()
port = 12346 port = 12346
sockfd.connect(('127.0.0.1', port)) sockfd.connect(('127.0.0.1', port))
sockfd.send(b'') sockfd.send(b'')
sockfd.close() sockfd.close()
time.sleep(1)
exit(0) exit(0)
@ -33,6 +33,8 @@ if __name__ == '__main__':
log.info("Exiting...") log.info("Exiting...")
cleanExit() cleanExit()
if __name__ == '__main__':
# Register SIGINT signal handler # Register SIGINT signal handler
signal.signal(signal.SIGINT, signalHandler) signal.signal(signal.SIGINT, signalHandler)
@ -114,7 +116,8 @@ if __name__ == '__main__':
exit(1) exit(1)
try: try:
xmpp.process() log.info("Launching XMPP connection until disconnection (ERRORS: %s)" % ERRORS)
xmpp.loop.run_until_complete(xmpp.disconnected)
except KeyboardInterrupt: except KeyboardInterrupt:
cleanExit() cleanExit()
except Exception as e: except Exception as e:
@ -122,6 +125,5 @@ if __name__ == '__main__':
if ERRORS >= 3: if ERRORS >= 3:
log.critical("3 consecutive errors. Aborting...") log.critical("3 consecutive errors. Aborting...")
cleanExit() cleanExit()
ERRORS += 1 ERRORS += 1
del xmpp del xmpp