-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathaggregation_mode_alerts.sh
More file actions
executable file
·73 lines (63 loc) · 2.03 KB
/
aggregation_mode_alerts.sh
File metadata and controls
executable file
·73 lines (63 loc) · 2.03 KB
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
66
67
68
69
70
71
72
73
#!/bin/bash
# ENV_VARIABLES
#
# - CONTRACT_ADDRESS
# - Holesky: 0xe84CD4084d8131841CE6DC265361f81F4C59a1d4
# - Stage: 0x7Eace34A8d4C4CacE633946C6F7CF4BeF3F33513
# - AGGREGATED_PROOF_VERIFIED_TOPIC (0xfe3e9e971000ab9c80c7e06aba2933aae5419d0e44693e3046913e9e58053f62)
# - RPC_URL
# - LOGS_BLOCK_RANGE (25hs -> 7500 blocks)
# - SLEEP_TIME
# - PAGER_DUTY_KEY
# - PAGER_DUTY_EMAIL
# - PAGER_DUTY_SERVICE_ID
# - SLACK_WEBHOOK_URL
# - TELEGRAM_CHAT_ID
# - TELEGRAM_BOT_TOKEN
# Load env file from $1 path
source "$1"
# Function to send slack message
# @param message
function send_slack_message() {
. alerts/slack.sh "$1"
}
# Function to send telegram message
# @param message
function send_telegram_message() {
. alerts/telegram.sh "$1"
}
# Function to send PagerDuty alert
# @param message
function send_pagerduty_alert() {
. alerts/pagerduty.sh "$1"
}
# Flags to avoid sending multiple alerts
no_new_aggregation_alert=false
while :
do
last_block=$(cast block --rpc-url $RPC_URL -f number)
printf "Last block: %s\n" $last_block
from_block=$(($last_block - $LOGS_BLOCK_RANGE))
new_aggregated_proofs_logs=$(cast logs --rpc-url $RPC_URL --from-block $from_block --address $CONTRACT_ADDRESS $AGGREGATED_PROOF_VERIFIED_TOPIC)
if [ -z "$new_aggregated_proofs_logs" ]; then
printf "No new aggregated proofs logs found\n"
if [ "$no_new_aggregation_alert" = false ]; then
message="🚨 $NETWORK ALERT Aggregation Mode: No new aggregated proofs since block $from_block"
printf "$message\n"
send_slack_message "$message"
send_telegram_message "$message"
send_pagerduty_alert "$message"
fi
no_new_aggregation_alert=true
else
printf "New aggregated proofs logs found\n"
if [ "$no_new_aggregation_alert" = true ]; then
message="🟩 $NETWORK INFO Aggregation Mode: Aggregated proofs creation resumed since block $from_block"
printf "$message\n"
send_slack_message "$message"
send_telegram_message "$message"
fi
no_new_aggregation_alert=false
fi
sleep $SLEEP_TIME
done