update struct

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

4
.dockerignore Normal file
View File

@ -0,0 +1,4 @@
monitor.service
README.md
docker-compose.yml
.env

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

8
dockerized/Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM python:3.10-alpine3.20
WORKDIR /monitor
COPY monitor.py .
COPY requirements.txt .
RUN pip install --no-cache-dir -r ./requirements.txt
CMD ["python", "monitor.py"]

View File

@ -0,0 +1,15 @@
version: '3.8'
# Переменные из .env будут подставлены автоматически
# Если .env нет, можно указать явно: docker-compose --env-file .custom.env up
services:
monitor:
image: monitor:latest
container_name: monitor
environment:
- TARGET_DOMAINS=${TARGET_DOMAINS} # Список доменов через запятую
- TARGET_PROTOCOL=${TARGET_PROTOCOL}
- TARGET_SSL_VERIFY=${TARGET_SSL_VERIFY}
- BOT_TOKEN=${BOT_TOKEN}
- BOT_CHATID=${BOT_CHATID}

64
dockerized/monitor.py Normal file
View File

@ -0,0 +1,64 @@
import requests
import os
import time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # insecure warn disable
domains = os.getenv("TARGET_DOMAINS", "").split(',')
domains = [d.strip() for d in domains if d.strip()]
protocol = os.getenv("TARGET_PROTOCOL", "https://")
verify_domain = bool(os.getenv("TARGET_SSL_VERIFY", "True"))
token = os.getenv("BOT_TOKEN", "")
chatid = int(os.getenv("BOT_CHATID", ""))
if not domains or not token or not chatid:
print("Error: Plese set domains, tg token, and tg chat id")
exit(1)
print(domains)
timeout_domains = []
def CheckDomain(domain):
try:
r = requests.get(f"{protocol}{domain}", verify=verify_domain) # 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)
if __name__ == "__main__":
master()

View File

@ -0,0 +1,2 @@
requests
python-daemon