forked from dogechain-lab/blockscout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert_syncing.sh
executable file
·56 lines (44 loc) · 1.13 KB
/
alert_syncing.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
56
#!/bin/bash
# Usage: $0 network alert_receiver_url
# Simple alert from some webhook url would do this job.
# curl and jq must be installed.
NETWORK=$1
RECEIVER_URL=$2
HOSTNAME=$((hostname))
IP=$((hostname -i))
HOST="http://127.0.0.1:4000"
PROJECT_NAME="DogeChain"
PROGRAM_NAME="blockscout"
SLEEP_MINUTE=1
generate_post_data()
{
local now=$(date +%F'T'%T'Z')
eval local content="$1"
cat <<EOT
{
"msgtype": "text",
"text": {
"content": "$PROJECT_NAME(network: $NETWORK)\n$content\ntimestamp: $now"
}
}
EOT
}
post_alarm() {
curl $RECEIVER_URL \
-H "Content-Type: application/json" \
-d "${1}"
}
query_current_block() {
local ret=$(curl -H "content-type: application/json" -X POST -d '{"id":0,"jsonrpc":"2.0","method":"eth_blockNumber","params":[]}' "$HOST/api/eth-rpc" | jq -r .result)
echo $ret
}
# query block num
block1=$(query_current_block)
# take a little break for increasement
sleep $((SLEEP_MINUTE*60))
# query another block num
block2=$(query_current_block)
if [[ "$block1" -eq "$block2" ]]; then
content="block stop upgrading after $(echo $((block1)))"
post_alarm "$(generate_post_data \${content})"
fi