forked from erfjab/holderbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitoring.py
60 lines (46 loc) · 3.04 KB
/
monitoring.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pyrogram import *
from pyrogram.types import *
from pyrogram.errors.exceptions import *
from Function.db import *
import time , requests , json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
app = Client(
"noder",
api_id=26410400,
api_hash="408bf51732560cb81a0e32533b858cbf",
bot_token=DEF_GET_BOT_TOKEN())
with app :
while True :
try :
BOSS_CHATID , NODE_STATUS , CHECK_NORMAL , CHECK_ERROR = DEF_MONITORING_DATA ()
PANEL_USER, PANEL_PASS, PANEL_DOMAIN = DEF_IMPORT_DATA (BOSS_CHATID)
if NODE_STATUS == "on" :
NODE_HAVE_A_PROBLEM = False
PANEL_TOKEN = DEF_PANEL_ACCESS(PANEL_USER, PANEL_PASS, PANEL_DOMAIN)
URL = f"{PANEL_DOMAIN}/api/nodes"
RESPONCE = requests.get(url=URL , headers=PANEL_TOKEN , verify=False)
if RESPONCE.status_code == 200 :
RESPONCE_DATA = RESPONCE.json()
for NODE in RESPONCE_DATA :
if NODE.get("status") == "error" or NODE.get("status") == "connecting" :
TEXT = f"<b>❗ (Checker) boss of one of the servers crashed. To prevent spamming, server monitoring has been stopped and will be restarted after <code>{CHECK_ERROR}</code> seconds.</b>"
TEXT += f"\n\n<b>NODE NAME : </b><code>{NODE.get('name')}</code>\n<b>NODE ID : </b><code>{NODE.get('id')}</code>\n<b>NODE IP : </b><code>{NODE.get('address')}</code>\n<b>ERROR MESSAGE : </b><code>{NODE.get('message')}</code>"
NODE_HAVE_A_PROBLEM = True
app.send_message(chat_id=BOSS_CHATID , text=TEXT , parse_mode=enums.ParseMode.HTML)
url = f"{PANEL_DOMAIN}/api/{NODE.get('id')}/reconnect"
RESPONCE = requests.get(url=URL , headers=PANEL_TOKEN , verify=False)
if RESPONCE.status_code == 200 :
app.send_message(chat_id=BOSS_CHATID , text='<b>(Checker) ✅ Automatic reconnection!</b>' , parse_mode=enums.ParseMode.HTML)
else:
app.send_message(chat_id=BOSS_CHATID , text='<b>(Checker) ❌ Automatic reconnection!</b>' , parse_mode=enums.ParseMode.HTML)
if NODE_HAVE_A_PROBLEM is True :
time.sleep(int(CHECK_ERROR))
else :
time.sleep(int(CHECK_NORMAL))
else :
time.sleep(60)
except Exception as e :
app.send_message(chat_id=BOSS_CHATID , text=f"<b>❌ (Checker) Monitoring Error :</b>\n<pre>{str(e)}</pre>" , parse_mode=enums.ParseMode.HTML)
time.sleep(60)
pass