From 8b916ad74dd7d62eb719806d7a5e846366a05f9b Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 5 Dec 2024 13:59:33 +0900 Subject: [PATCH 1/2] add node ip to alerting --- modules/alert_bot.py | 3 +++ mytoncore/mytoncore.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/alert_bot.py b/modules/alert_bot.py index aea45732..d84d5e92 100644 --- a/modules/alert_bot.py +++ b/modules/alert_bot.py @@ -83,6 +83,7 @@ def __init__(self, ton, local, *args, **kwargs): self.validator_module = None self.inited = False self.hostname = None + self.ip = None self.token = self.ton.local.db.get("BotToken") self.chat_id = self.ton.local.db.get("ChatId") self.last_db_check = None @@ -113,6 +114,7 @@ def send_alert(self, alert_name: str, *args, **kwargs): ❗️ MyTonCtrl Alert {alert_name} ❗️ Hostname: {self.hostname} +Node IP: {self.ip} Time: {time_} ({int(time.time())}) Severity: {alert.severity} @@ -138,6 +140,7 @@ def init(self): from modules.validator import ValidatorModule self.validator_module = ValidatorModule(self.ton, self.local) self.hostname = get_hostname() + self.ip = self.ton.get_validator_engine_ip() self.set_global_vars() self.inited = True diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 76cf58cd..7523a51a 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -30,7 +30,7 @@ get_timestamp, timestamp2datetime, dec2hex, - Dict + Dict, int2ip ) @@ -3791,6 +3791,13 @@ def GetNetworkName(self): return "unknown" #end define + def get_validator_engine_ip(self): + try: + config = self.GetValidatorConfig() + return int2ip(config['addrs'][0]['ip']) + except: + return None + def GetFunctionBuffer(self, name, timeout=10): timestamp = get_timestamp() buff = self.local.buffer.get(name) From 6b43862e6d97d3663ba8d09ec4d096af39ac45d1 Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 5 Dec 2024 20:20:24 +0900 Subject: [PATCH 2/2] do not send balance alert when out of sync --- modules/alert_bot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/alert_bot.py b/modules/alert_bot.py index e55fcc61..2ebf4034 100644 --- a/modules/alert_bot.py +++ b/modules/alert_bot.py @@ -209,6 +209,9 @@ def check_db_usage(self): def check_validator_wallet_balance(self): if not self.ton.using_validator(): return + validator_status = self.ton.GetValidatorStatus() + if not validator_status.is_working or validator_status.out_of_sync >= 20: + return validator_wallet = self.ton.GetValidatorWallet() validator_account = self.ton.GetAccount(validator_wallet.addrB64) if validator_account.balance < 10: