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,
"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

14
main.py
View File

@ -14,25 +14,27 @@ from bot import MUCBot
from data import DataStore
from localServer import LocalServer
if __name__ == '__main__':
def cleanExit():
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):
def signalHandler(sig, frame):
log.info("Exiting...")
cleanExit()
if __name__ == '__main__':
# 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