update struct

This commit is contained in:
2025-04-05 16:12:13 +05:00
parent b40221582d
commit 4aecc5eddf
8 changed files with 94 additions and 0 deletions

60
hard/monitor.py Normal file
View File

@@ -0,0 +1,60 @@
import requests
import time
import daemon
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # insecure warn disable
domains = ['google.com', '127.0.0.1']
protocol = "https://"
token = "TOKEN_YOU_BOT"
chatid = YOU_CHAT_ID
timeout_domains = []
def CheckDomain(domain):
try:
r = requests.get(f"{protocol}{domain}", verify=False) # verify SSL crt disable
code = int(r.status_code)
return code
except requests.exceptions.ConnectionError:
return 1
except:
return 0
def SendAlert(msg):
response = requests.post(
url='https://api.telegram.org/bot{0}/sendMessage'.format(token),
data={'chat_id': chatid, 'text': msg}
).json()
def master():
while True:
for domain in timeout_domains:
resp = CheckDomain(domain)
print(domain, resp)
if resp == 200:
timeout_domains.remove(domain)
domains.append(domain)
SendAlert(f'✅ RESOLVED ✅\n🔹Domain is avability\n🔹Domain: {domain}')
for domain in domains:
resp = CheckDomain(domain)
print(domain, resp)
if resp != 200:
timeout_domains.append(domain)
domains.remove(domain)
if resp == 1:
SendAlert(f'⚠️ ALARM! ⚠️\n🔹Response: no route to host\n🔹Domain: {domain}')
elif resp == 0:
SendAlert(f'⚠️ ALARM! ⚠️\n🔹Response: other connect error\n🔹Domain: {domain}')
else:
SendAlert(f'⚠️ ALARM! ⚠️\n🔹Response: {resp}\n🔹Domain: {domain}')
time.sleep(20)
def run_daemon():
with daemon.DaemonContext():
master()
if __name__ == "__main__":
run_daemon()

15
hard/monitor.service Normal file
View File

@@ -0,0 +1,15 @@
[Unit]
Description=Monitor Domain Avability
After=network.target
[Service]
Type=simple
User=YOU_USER
Group=YOU_GPOUP
ExecStart=/bin/python3 /you/path/to/monitor.py
ExecStop=kill -9 $PID
Restart=always
[Install]
WantedBy=multi-user.target
Alias=monitor.service