-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_health.py
65 lines (48 loc) · 2.18 KB
/
check_health.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
61
62
63
64
65
import requests
import sys
import os
from dotenv import load_dotenv
load_dotenv()
VALIDATOR_ADDRESS = os.getenv('VALIDATOR_ADDRESS')
TELEGRAM_API_KEY = os.getenv('TELEGRAM_API_KEY')
TELEGRAM_GROUP_ID = os.getenv('TELEGRAM_GROUP_ID')
CHAINS = ['ethereum', 'binance', 'polygon', 'avalanche', 'fantom', 'moonbeam', 'aurora']
def get_validator():
req_data = {"path":"/cosmos/staking/v1beta1/validators","module":"lcd"}
response = requests.post('https://api.axelarscan.io/', json=req_data)
validators = response.json()['validators']
for validator in validators:
if validator['operator_address'] == VALIDATOR_ADDRESS:
return validator
raise Exception('Validator not found')
def is_bonded(validator):
return validator['status'] == 'BOND_STATUS_BONDED'
def is_jailed(validator):
return validator['jailed']
def validator_has_external_chain(chain):
json = {"chain": chain}
try:
response = requests.post('https://api.axelarscan.io/chain-maintainers', json=json)
maintainers = response.json()['maintainers']
except:
return False
return VALIDATOR_ADDRESS in maintainers
def validator_get_missing_external_chains():
return [chain for chain in CHAINS if not validator_has_external_chain(chain)]
def send_telegram_notification(message):
requests.post(f'https://api.telegram.org/bot{TELEGRAM_API_KEY}/sendMessage', json={
'chat_id': TELEGRAM_GROUP_ID,
'text': message,
})
try:
validator = get_validator()
except:
send_telegram_notification('😱 Validator not found in validators list: https://axelarscan.io/validators ⚠️⚠️⚠️')
sys.exit(1)
if is_jailed(validator):
send_telegram_notification('😱🧑⚖️👮🏽♀️⛓️⚖️🚨🚓🚔👮🐕🦺 Validator is jailed: https://axelarscan.io/validators ⚠️⚠️⚠️')
if not is_bonded(validator):
send_telegram_notification('😱 Validator is not bonded: https://axelarscan.io/validators ⚠️⚠️⚠️')
missing_external_chains = validator_get_missing_external_chains()
for missing_chain in missing_external_chains:
send_telegram_notification(f'😱🔗🔗🔗 Validator is missing external chain {missing_chain}: https://axelarscan.io/validators ⚠️⚠️⚠️')