mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
telegram
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
SSH_PASSWD=
|
SSH_PASSWD=
|
||||||
|
|
||||||
# Direct subdomain, using Let's Encrypt certificates
|
# Direct subdomain, using Let's Encrypt certificates
|
||||||
DOMAIN_LE=le.openfreemap.org
|
DOMAIN_LE=
|
||||||
|
|
||||||
# Let's Encrypt account email
|
# Let's Encrypt account email
|
||||||
LE_EMAIL=
|
LE_EMAIL=
|
||||||
@@ -17,5 +17,14 @@ SKIP_PLANET=false
|
|||||||
|
|
||||||
# --- Let's Encrypt DNS related variables, not needed for self-hosting
|
# --- Let's Encrypt DNS related variables, not needed for self-hosting
|
||||||
|
|
||||||
DOMAIN_LEDNS = direct.openfreemap.org
|
DOMAIN_LEDNS=direct.openfreemap.org
|
||||||
|
|
||||||
|
# --- host list
|
||||||
|
|
||||||
|
HTTP_HOST_LIST=
|
||||||
|
|
||||||
|
|
||||||
|
# --- Load Balancer script
|
||||||
|
|
||||||
|
TELEGRAM_BOT_TOKEN=
|
||||||
|
TELEGRAM_BOT_CHAT_ID=
|
||||||
@@ -5,6 +5,7 @@ import json
|
|||||||
import click
|
import click
|
||||||
import requests
|
import requests
|
||||||
from loadbalancer_lib.curl import pycurl_get, pycurl_status
|
from loadbalancer_lib.curl import pycurl_get, pycurl_status
|
||||||
|
from loadbalancer_lib.telegram_ import telegram_send_message
|
||||||
|
|
||||||
|
|
||||||
AREAS = ['planet', 'monaco']
|
AREAS = ['planet', 'monaco']
|
||||||
@@ -25,7 +26,7 @@ def run():
|
|||||||
|
|
||||||
with open('/data/ofm/config/loadbalancer.json') as fp:
|
with open('/data/ofm/config/loadbalancer.json') as fp:
|
||||||
c = json.load(fp)
|
c = json.load(fp)
|
||||||
print(c)
|
# print(c)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results_by_ip = {}
|
results_by_ip = {}
|
||||||
@@ -37,12 +38,14 @@ def run():
|
|||||||
|
|
||||||
for host_ip, host_ok in results_by_ip.items():
|
for host_ip, host_ok in results_by_ip.items():
|
||||||
if not host_ok:
|
if not host_ok:
|
||||||
print(f'{host_ip} ERROR')
|
message = f'ERROR with host: {host_ip}'
|
||||||
# TODO send message
|
print(message)
|
||||||
|
telegram_send_message(message, c['telegram_bot_token'], c['telegram_chat_id'])
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
message = f'ERROR with loadbalancer: {e}'
|
||||||
# TODO send message
|
print(message)
|
||||||
|
telegram_send_message(message, c['telegram_bot_token'], c['telegram_chat_id'])
|
||||||
|
|
||||||
|
|
||||||
def run_area(c, area):
|
def run_area(c, area):
|
||||||
@@ -52,7 +55,7 @@ def run_area(c, area):
|
|||||||
|
|
||||||
results = dict()
|
results = dict()
|
||||||
|
|
||||||
for host_ip in c['load_balance_host_list']:
|
for host_ip in c['http_host_list']:
|
||||||
try:
|
try:
|
||||||
check_host(c['domain_ledns'], host_ip, area, deployed_version)
|
check_host(c['domain_ledns'], host_ip, area, deployed_version)
|
||||||
results[host_ip] = True
|
results[host_ip] = True
|
||||||
|
|||||||
14
scripts/loadbalancer/loadbalancer_lib/telegram_.py
Normal file
14
scripts/loadbalancer/loadbalancer_lib/telegram_.py
Normal 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)
|
||||||
@@ -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)
|
|
||||||
@@ -223,14 +223,14 @@ def setup_ledns_writer(c):
|
|||||||
|
|
||||||
def setup_loadbalancer(c):
|
def setup_loadbalancer(c):
|
||||||
domain_ledns = dotenv_val('DOMAIN_LEDNS').lower()
|
domain_ledns = dotenv_val('DOMAIN_LEDNS').lower()
|
||||||
load_balance_host_list = [
|
http_host_list = [h.strip() for h in dotenv_val('HTTP_HOST_LIST').split(',') if h.strip()]
|
||||||
h.strip() for h in dotenv_val('LOAD_BALANCE_HOST_LIST').split(',') if h.strip()
|
|
||||||
]
|
|
||||||
assert (CONFIG_DIR / 'cloudflare.ini').exists()
|
assert (CONFIG_DIR / 'cloudflare.ini').exists()
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
'domain_ledns': domain_ledns,
|
'domain_ledns': domain_ledns,
|
||||||
'load_balance_host_list': load_balance_host_list,
|
'http_host_list': http_host_list,
|
||||||
|
'telegram_bot_token': dotenv_val('TELEGRAM_BOT_TOKEN'),
|
||||||
|
'telegram_bot_chat_id': dotenv_val('TELEGRAM_BOT_CHAT_ID'),
|
||||||
}
|
}
|
||||||
|
|
||||||
config_str = json.dumps(config, indent=2, ensure_ascii=False)
|
config_str = json.dumps(config, indent=2, ensure_ascii=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user