|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# ENV VARIABLES: |
| 4 | +# - REPETITIONS |
| 5 | +# - EXPLORER_URL |
| 6 | +# - SENDER_ADDRESS |
| 7 | +# - RPC_URL |
| 8 | +# - EXPLORER_URL |
| 9 | +# - NETWORK |
| 10 | +# - PRIVATE_KEY |
| 11 | +# - VERIFICATION_WAIT_TIME |
| 12 | +# - LOGS_BLOCK_RANGE |
| 13 | +# - PAGER_DUTY_KEY |
| 14 | +# - PAGER_DUTY_EMAIL |
| 15 | +# - PAGER_DUTY_SERVICE_ID |
| 16 | +# - SLACK_WEBHOOK_URL |
| 17 | + |
| 18 | +# Load env file from $1 path |
| 19 | +source "$1" |
| 20 | + |
| 21 | +# Determine log file name based on current date |
| 22 | +LOG_FILE="./alerts/notification_logs/log_$(date +"%Y_%m_%d").txt" |
| 23 | + |
| 24 | +batches=0 |
| 25 | +submitted_total=0 |
| 26 | +verified_total=0 |
| 27 | +eth_total="0" |
| 28 | +usd_total="0" |
| 29 | + |
| 30 | +# Read the log file entries and generate a summary |
| 31 | +if [[ -f "$LOG_FILE" ]]; then |
| 32 | + while IFS= read -r line; do |
| 33 | + case "$line" in |
| 34 | + *"SUCCESS:"*) |
| 35 | + batches=$((batches + 1)) |
| 36 | + |
| 37 | + proofs_submitted=$(printf '%s\n' "$line" \ |
| 38 | + | grep -oE '[0-9]+ proofs submitted' \ |
| 39 | + | head -1 \ |
| 40 | + | cut -d' ' -f1) |
| 41 | + if [[ -n "$proofs_submitted" ]]; then |
| 42 | + submitted_total=$((submitted_total + proofs_submitted)) |
| 43 | + fi |
| 44 | + |
| 45 | + proofs_verified=$(printf '%s\n' "$line" \ |
| 46 | + | grep -oE '\([0-9]+ sent\)' \ |
| 47 | + | grep -oE '[0-9]+' \ |
| 48 | + | head -1) |
| 49 | + if [[ -n "$proofs_verified" ]]; then |
| 50 | + verified_total=$((verified_total + proofs_verified)) |
| 51 | + fi |
| 52 | + |
| 53 | + eth_spent=$(printf '%s\n' "$line" \ |
| 54 | + | sed -n 's/.*Spent \([0-9.]*\) ETH.*/\1/p') |
| 55 | + if [[ -n "$eth_spent" ]]; then |
| 56 | + eth_total=$(echo "$eth_total + $eth_spent" | bc -l) |
| 57 | + fi |
| 58 | + |
| 59 | + usd_spent=$(printf '%s\n' "$line" \ |
| 60 | + | sed -n 's/.*(\$ *\([0-9.]*\)).*/\1/p') |
| 61 | + if [[ -n "$usd_spent" ]]; then |
| 62 | + usd_total=$(echo "$usd_total + $usd_spent" | bc -l) |
| 63 | + fi |
| 64 | + ;; |
| 65 | + esac |
| 66 | + done < "$LOG_FILE" |
| 67 | + |
| 68 | + summary=$( |
| 69 | + printf "Proof Submission Summary - %s\n" "$(date +'%Y-%m-%d %H:%M:%S')" |
| 70 | + echo "----------------------------------------" |
| 71 | + printf "Processed batches : %d\n" "$batches" |
| 72 | + printf "Proofs submitted : %d\n" "$submitted_total" |
| 73 | + printf "Proofs verified : %d\n" "$verified_total" |
| 74 | + printf "Total spent (ETH) : %.12f ETH\n" "$eth_total" |
| 75 | + printf "Total spent (USD) : $ %.2f\n" "$usd_total" |
| 76 | + echo "----------------------------------------" |
| 77 | + ) |
| 78 | + |
| 79 | + echo "$summary" |
| 80 | + |
| 81 | + # Send the summary to Slack |
| 82 | + if [[ -n "$SLACK_WEBHOOK_URL" ]]; then |
| 83 | + safe_summary=$(printf '%s\n' "$summary" | sed 's/"/\\"/g') |
| 84 | + curl -s -X POST -H 'Content-type: application/json' \ |
| 85 | + --data "{\"text\":\"$safe_summary\"}" \ |
| 86 | + "$SLACK_WEBHOOK_URL" >/dev/null 2>&1 |
| 87 | + fi |
| 88 | +else |
| 89 | + echo "Proof Submission Summary - $(date +'%Y-%m-%d %H:%M:%S')" |
| 90 | + echo "----------------------------------------" |
| 91 | + echo "No log file found for today: $LOG_FILE" |
| 92 | + echo "----------------------------------------" |
| 93 | +fi |
0 commit comments