Skip to content

Commit 529ffa6

Browse files
authored
Merge pull request #399 from yungwine/bot
update alerts
2 parents 03c35d3 + 6b43862 commit 529ffa6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

modules/alert_bot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(self, ton, local, *args, **kwargs):
8383
self.validator_module = None
8484
self.inited = False
8585
self.hostname = None
86+
self.ip = None
8687
self.token = None
8788
self.chat_id = None
8889
self.last_db_check = 0
@@ -113,6 +114,7 @@ def send_alert(self, alert_name: str, *args, **kwargs):
113114
❗️ <b>MyTonCtrl Alert {alert_name}</b> ❗️
114115
115116
Hostname: <code>{self.hostname}</code>
117+
Node IP: <code>{self.ip}</code>
116118
Time: <code>{time_}</code> (<code>{int(time.time())}</code>)
117119
Severity: <code>{alert.severity}</code>
118120
@@ -140,6 +142,7 @@ def init(self):
140142
from modules.validator import ValidatorModule
141143
self.validator_module = ValidatorModule(self.ton, self.local)
142144
self.hostname = get_hostname()
145+
self.ip = self.ton.get_validator_engine_ip()
143146
self.set_global_vars()
144147
self.inited = True
145148

@@ -206,6 +209,9 @@ def check_db_usage(self):
206209
def check_validator_wallet_balance(self):
207210
if not self.ton.using_validator():
208211
return
212+
validator_status = self.ton.GetValidatorStatus()
213+
if not validator_status.is_working or validator_status.out_of_sync >= 20:
214+
return
209215
validator_wallet = self.ton.GetValidatorWallet()
210216
validator_account = self.ton.GetAccount(validator_wallet.addrB64)
211217
if validator_account.balance < 10:

mytoncore/mytoncore.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
get_timestamp,
3131
timestamp2datetime,
3232
dec2hex,
33-
Dict
33+
Dict, int2ip
3434
)
3535

3636

@@ -3793,6 +3793,13 @@ def GetNetworkName(self):
37933793
return "unknown"
37943794
#end define
37953795

3796+
def get_validator_engine_ip(self):
3797+
try:
3798+
config = self.GetValidatorConfig()
3799+
return int2ip(config['addrs'][0]['ip'])
3800+
except:
3801+
return None
3802+
37963803
def GetFunctionBuffer(self, name, timeout=10):
37973804
timestamp = get_timestamp()
37983805
buff = self.local.buffer.get(name)

0 commit comments

Comments
 (0)