Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions alerts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SLACK_WEBHOOK_URL=<YOUR_SLACK_WEBHOOK_URL>

# Variables for contract_alerts.sh
RPC_URL=<YOUR_RPC_URL>
CONTRACT_ADDRESS=<YOUR_CONTRACT_ADDRESS>
NEW_BATCH_TOPIC=<YOUR_NEW_BATCH_TOPIC>
VERIFIED_BATCH_TOPIC=<YOUR_VERIFIED_BATCH_TOPIC>

# Variables for process_errors_alerts.sh
SERVICE=<YOUR_SERVICE>
EXPRESSION=<GREP_EXPRESSION>
34 changes: 34 additions & 0 deletions alerts/contract_alerts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Load env file from $1 path
source $1

# Function to send slack message
# @param message
function send_slack_message() {
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"$1\"}" \
$SLACK_WEBHOOK_URL
}

while :
do
last_block=$(cast block --rpc-url $RPC_URL -f number)
printf "Last block: %s\n" $last_block

from_block=$(($last_block - 10))

new_batch_logs=$(cast logs --rpc-url $RPC_URL --from-block $from_block --address $CONTRACT_ADDRESS $NEW_BATCH_TOPIC)
if [ -z "$new_batch_logs" ]; then
printf "No new batches logs found\n"
send_slack_message "🚨 ALERT: No new batches in Service Manager since block $from_block"
fi

verified_batch_logs=$(cast logs --rpc-url $RPC_URL --from-block $from_block --address $CONTRACT_ADDRESS $VERIFIED_BATCH_TOPIC)
if [ -z "$verified_batch_logs" ]; then
printf "No verified batches logs found\n"
send_slack_message "🚨 ALERT: No new verified batches in Service Manager since block $from_block"
fi

sleep 100
done
8 changes: 8 additions & 0 deletions alerts/process_errors_alerts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

source $1

journalctl -feu "$SERVICE" -n 0 | while read LINE; do
(echo "$LINE" | grep -e "$EXPRESSION") && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$SLACK_WEBHOOK_URL";
done