|
| 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 |
0 commit comments