Skip to content

Commit d2c297b

Browse files
JuArceMauroToscano
andauthored
infra(alerts): add alerts for aggregation mode (#1906)
Co-authored-by: Mauro Toscano <[email protected]>
1 parent 99b447d commit d2c297b

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

alerts/.env.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ NETWORK=<NETWORK>
3232
PRIVATE_KEY=<SENDER_PRIVATE_KEY>
3333
VERIFICATION_WAIT_TIME=<TIME_TO_WAIT_FOR_VERIFICATION>
3434
LOGS_BLOCK_RANGE=<LOGS_BLOCK_RANGE>
35+
36+
# Variables for aggregation_mode_alerts.sh
37+
CONTRACT_ADDRESS=<YOUR_CONTRACT_ADDRESS>
38+
AGGREGATED_PROOF_VERIFIED_TOPIC=0xfe3e9e971000ab9c80c7e06aba2933aae5419d0e44693e3046913e9e58053f62
39+
RPC_URL=<YOUR_RPC_URL>
40+
LOGS_BLOCK_RANGE=7500
41+
SLEEP_TIME=3600
42+
PAGER_DUTY_KEY=<YOUR_PAGER_DUTY_KEY>
43+
PAGER_DUTY_EMAIL=<YOUR_PAGER_DUTY_EMAIL>
44+
PAGER_DUTY_SERVICE_ID=<YOUR_PAGER_DUTY_SERVICE_ID>
45+
SLACK_WEBHOOK_URL=<YOUR_SLACK_WEBHOOK_URL>
46+
TELEGRAM_BOT_TOKEN=<YOUR_TELEGRAM_BOT_TOKEN>
47+
TELEGRAM_CHAT_ID=<YOUR_TELEGRAM_CHAT_ID>

alerts/aggregation_mode_alerts.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# ENV_VARIABLES
4+
#
5+
# - CONTRACT_ADDRESS
6+
# - Holesky: 0xe84CD4084d8131841CE6DC265361f81F4C59a1d4
7+
# - Stage: 0x7Eace34A8d4C4CacE633946C6F7CF4BeF3F33513
8+
# - AGGREGATED_PROOF_VERIFIED_TOPIC (0xfe3e9e971000ab9c80c7e06aba2933aae5419d0e44693e3046913e9e58053f62)
9+
# - RPC_URL
10+
# - LOGS_BLOCK_RANGE (25hs -> 7500 blocks)
11+
# - SLEEP_TIME
12+
# - PAGER_DUTY_KEY
13+
# - PAGER_DUTY_EMAIL
14+
# - PAGER_DUTY_SERVICE_ID
15+
# - SLACK_WEBHOOK_URL
16+
# - TELEGRAM_CHAT_ID
17+
# - TELEGRAM_BOT_TOKEN
18+
19+
# Load env file from $1 path
20+
source "$1"
21+
22+
# Function to send slack message
23+
# @param message
24+
function send_slack_message() {
25+
. alerts/slack.sh "$1"
26+
}
27+
28+
# Function to send telegram message
29+
# @param message
30+
function send_telegram_message() {
31+
. alerts/telegram.sh "$1"
32+
}
33+
34+
# Function to send PagerDuty alert
35+
# @param message
36+
function send_pagerduty_alert() {
37+
. alerts/pagerduty.sh "$1"
38+
}
39+
40+
# Flags to avoid sending multiple alerts
41+
no_new_aggregation_alert=false
42+
43+
while :
44+
do
45+
last_block=$(cast block --rpc-url $RPC_URL -f number)
46+
printf "Last block: %s\n" $last_block
47+
48+
from_block=$(($last_block - $LOGS_BLOCK_RANGE))
49+
50+
new_aggregated_proofs_logs=$(cast logs --rpc-url $RPC_URL --from-block $from_block --address $CONTRACT_ADDRESS $AGGREGATED_PROOF_VERIFIED_TOPIC)
51+
if [ -z "$new_aggregated_proofs_logs" ]; then
52+
printf "No new aggregated proofs logs found\n"
53+
if [ "$no_new_aggregation_alert" = false ]; then
54+
message="🚨 $NETWORK ALERT Aggregation Mode: No new aggregated proofs since block $from_block"
55+
printf "$message\n"
56+
send_slack_message "$message"
57+
send_telegram_message "$message"
58+
send_pagerduty_alert "$message"
59+
fi
60+
no_new_aggregation_alert=true
61+
else
62+
printf "New aggregated proofs logs found\n"
63+
if [ "$no_new_aggregation_alert" = true ]; then
64+
message="🟩 $NETWORK INFO Aggregation Mode: Aggregated proofs creation resumed since block $from_block"
65+
printf "$message\n"
66+
send_slack_message "$message"
67+
send_telegram_message "$message"
68+
fi
69+
no_new_aggregation_alert=false
70+
fi
71+
72+
sleep $SLEEP_TIME
73+
done

alerts/telegram.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Function to send telegram message
2+
# @param message
3+
curl -s -X POST https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage \
4+
-d chat_id=$TELEGRAM_CHAT_ID \
5+
-d text="$1" \
6+
-d disable_notification=true
7+

0 commit comments

Comments
 (0)