-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhealth_probe.py
executable file
·34 lines (27 loc) · 1.41 KB
/
health_probe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
from healthcheck.health_check import start_health_check, EventHandler, HealthStatus
from utils.logger import Logger
from utils.telegram import TelegramHandler
from constants import (STICKER_ID_KK_MORRI, TELEGRAM_API_TOKEN,
CONVERSATIONS,
ADA_URL,
HEALTHCHECK_SLEEP_AMOUNT,
HEALTHCHECK_ANOMALY_THRESHOLD)
class BackupHandler(EventHandler):
def __init__(self, logger, telegram_handler):
self.telegram_handler = telegram_handler
self.logger = logger
def broadcast(self, message, service_name, status):
# we only care about ada right now
if service_name != 'Ada': return
if status == HealthStatus.UP:
self.logger.log("It's a miracle! Ada is back to life")
self.telegram_handler.broadcast('Meu serviço principal foi restaurado. Estou de volta!')
else:
self.logger.log('Ada is ded. Sending telegram message...')
self.telegram_handler.broadcast(f"I don't feel so good... estou rodando como backup", sticker=STICKER_ID_KK_MORRI)
if __name__ == '__main__':
logger = Logger(None)
handler = TelegramHandler(logger, TELEGRAM_API_TOKEN, CONVERSATIONS)
backup_handler = BackupHandler(logger, handler)
start_health_check(logger, backup_handler, {'Ada': ADA_URL}, HEALTHCHECK_SLEEP_AMOUNT, HEALTHCHECK_ANOMALY_THRESHOLD)