Skip to content

Commit 49ba124

Browse files
authored
feat: add alerts for ServiceManager contract (#291)
1 parent 1193400 commit 49ba124

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

alerts/.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SLACK_WEBHOOK_URL=<YOUR_SLACK_WEBHOOK_URL>
2+
3+
# Variables for contract_alerts.sh
4+
RPC_URL=<YOUR_RPC_URL>
5+
CONTRACT_ADDRESS=<YOUR_CONTRACT_ADDRESS>
6+
NEW_BATCH_TOPIC=<YOUR_NEW_BATCH_TOPIC>
7+
VERIFIED_BATCH_TOPIC=<YOUR_VERIFIED_BATCH_TOPIC>
8+
9+
# Variables for process_errors_alerts.sh
10+
SERVICE=<YOUR_SERVICE>
11+
EXPRESSION=<GREP_EXPRESSION>

alerts/contract_alerts.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Load env file from $1 path
4+
source $1
5+
6+
# Function to send slack message
7+
# @param message
8+
function send_slack_message() {
9+
curl -X POST -H 'Content-type: application/json' \
10+
--data "{\"text\":\"$1\"}" \
11+
$SLACK_WEBHOOK_URL
12+
}
13+
14+
while :
15+
do
16+
last_block=$(cast block --rpc-url $RPC_URL -f number)
17+
printf "Last block: %s\n" $last_block
18+
19+
from_block=$(($last_block - 10))
20+
21+
new_batch_logs=$(cast logs --rpc-url $RPC_URL --from-block $from_block --address $CONTRACT_ADDRESS $NEW_BATCH_TOPIC)
22+
if [ -z "$new_batch_logs" ]; then
23+
printf "No new batches logs found\n"
24+
send_slack_message "🚨 ALERT: No new batches in Service Manager since block $from_block"
25+
fi
26+
27+
verified_batch_logs=$(cast logs --rpc-url $RPC_URL --from-block $from_block --address $CONTRACT_ADDRESS $VERIFIED_BATCH_TOPIC)
28+
if [ -z "$verified_batch_logs" ]; then
29+
printf "No verified batches logs found\n"
30+
send_slack_message "🚨 ALERT: No new verified batches in Service Manager since block $from_block"
31+
fi
32+
33+
sleep 100
34+
done

alerts/process_errors_alerts.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
source $1
4+
5+
journalctl -feu "$SERVICE" -n 0 | while read LINE; do
6+
(echo "$LINE" | grep -e "$EXPRESSION") && curl -X POST --silent --data-urlencode \
7+
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$SLACK_WEBHOOK_URL";
8+
done

0 commit comments

Comments
 (0)