This commit is contained in:
Zsolt Ero
2024-06-09 22:27:10 +02:00
parent 1b594bc31c
commit a06ee4c65c
5 changed files with 38 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ import json
import click
import requests
from loadbalancer_lib.curl import pycurl_get, pycurl_status
from loadbalancer_lib.telegram_ import telegram_send_message
AREAS = ['planet', 'monaco']
@@ -25,7 +26,7 @@ def run():
with open('/data/ofm/config/loadbalancer.json') as fp:
c = json.load(fp)
print(c)
# print(c)
try:
results_by_ip = {}
@@ -37,12 +38,14 @@ def run():
for host_ip, host_ok in results_by_ip.items():
if not host_ok:
print(f'{host_ip} ERROR')
# TODO send message
message = f'ERROR with host: {host_ip}'
print(message)
telegram_send_message(message, c['telegram_bot_token'], c['telegram_chat_id'])
except Exception as e:
print(e)
# TODO send message
message = f'ERROR with loadbalancer: {e}'
print(message)
telegram_send_message(message, c['telegram_bot_token'], c['telegram_chat_id'])
def run_area(c, area):
@@ -52,7 +55,7 @@ def run_area(c, area):
results = dict()
for host_ip in c['load_balance_host_list']:
for host_ip in c['http_host_list']:
try:
check_host(c['domain_ledns'], host_ip, area, deployed_version)
results[host_ip] = True

View File

@@ -0,0 +1,14 @@
import requests
def telegram_send_message(message, bot_token, chat_id):
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
payload = {'chat_id': chat_id, 'text': message}
response = requests.post(url, data=payload)
if response.status_code == 200:
print('Message sent successfully!')
else:
print('Failed to send message:', response.text)

View File

@@ -1,12 +0,0 @@
from telegram import Bot
bot = Bot(token='YOUR_BOT_TOKEN')
# Replace 'CHAT_ID' with the chat ID you want to send the message to
chat_id = 'CHAT_ID'
# The message you want to send
message = 'Hello, this is a test message from my bot!'
bot.send_message(chat_id=chat_id, text=message)