This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
forked from DDeAlmeida/BitCannaTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitcanna_Sign.sh
55 lines (43 loc) · 1.76 KB
/
bitcanna_Sign.sh
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
#! /bin/bash
# Set Enable Email to 1 to enable email notifications and fill in the blanks
ENABLE_EMAIL=0
FROM_ADDRESS=
TO_ADDRESS=
# Number of missed blocks before an email is sent
ALERT_MISSING_BLOCKS=15
export CURRENT_BLOCK=0
#SET ADDRESS VALIDATOR
export ADDRESS=3DC460BB9B0F124D27D013A319719476D980D550
export NOT_SIGNING_COUNT=0
while true;
do
HEIGHT=$(curl --max-time 10 -sSL "http://seed1.bitcanna.io:26657/block" | jq -r '.result.block.header.height')
function send_email_notify
{
if [ "$ENABLE_EMAIL" = 1 ]; then
mail -s "BitCanna Monitor: '$POOL_ID'" -a From:Admin\<$FROM_ADDRESS\> --return-address=$FROM_ADDRESS $TO_ADDRESS <<< 'Validator is Missing Blocks!!
Expected: '$EXPECTED_BLOCKS'
Produced: '$PRODUCED_BLOCKS'
Blocks Missed: '$BLOCKS_MISSED'
Alert Trigger: '$ALERT_MISSING_BLOCKS' Missing Blocks'
fi
}
if [ $CURRENT_BLOCK != $HEIGHT ];
then
VALID_SIGN=$(curl --max-time 10 -sSL "http://seed1.bitcanna.io:26657/block" | jq -r --arg ADDRESS "${ADDRESS}" '.result as $result | .result.block.last_commit.signatures[] | select(.validator_address | . != null and . != "" and . == $ADDRESS) | $result.block.header.height')
if [[ -z "${VALID_SIGN}" ]]; then
date +"%d/%m/%y-%H:%M:%S ❌ Not signing @ Block#${HEIGHT}" >> ~/sign_history_bitcanna.txt
((NOT_SIGNING_COUNT++))
if [ $NOT_SIGNING_COUNT -gt $ALERT_MISSING_BLOCKS ]; then
echo "Restarting the service @ Block#${HEIGHT}"
send_email_notify
sudo systemctl restart bcnad.service
NOT_SIGNING_COUNT=0
fi
else
date +"%d/%m/%y-%H:%M:%S 👍 Signing @ Block#${HEIGHT}" >> ~/sign_history_bitcanna.txt
NOT_SIGNING_COUNT=0
fi
CURRENT_BLOCK=$HEIGHT
fi
done;