|
| 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 | +DATE=$(date -d "yesterday" +"%Y_%m_%d") |
| 22 | + |
| 23 | +# Determine log file name based on current date |
| 24 | +LOG_FILE="./alerts/notification_logs/log_$DATE.txt" |
| 25 | + |
| 26 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 27 | +cd "$SCRIPT_DIR" |
| 28 | +cd .. |
| 29 | + |
| 30 | +batches=0 |
| 31 | +submitted_total=0 |
| 32 | +submitted_by_aligned=0 |
| 33 | +verified_total=0 |
| 34 | +unverified_total=0 |
| 35 | +eth_by_aligned="0" |
| 36 | +usd_by_aligned="0" |
| 37 | +eth_total="0" |
| 38 | +usd_total="0" |
| 39 | + |
| 40 | +# Read the log file entries and generate a summary |
| 41 | +if [[ -f "$LOG_FILE" ]]; then |
| 42 | + while IFS= read -r line; do |
| 43 | + case "$line" in |
| 44 | + *"SUCCESS:"*) |
| 45 | + batches=$((batches + 1)) |
| 46 | + |
| 47 | + proofs_submitted=$(printf '%s\n' "$line" \ |
| 48 | + | grep -oE '[0-9]+ proofs submitted' \ |
| 49 | + | head -1 \ |
| 50 | + | cut -d' ' -f1) |
| 51 | + if [[ -n "$proofs_submitted" ]]; then |
| 52 | + submitted_total=$((submitted_total + proofs_submitted)) |
| 53 | + verified_total=$((verified_total + proofs_submitted)) |
| 54 | + fi |
| 55 | + |
| 56 | + proofs_submitted_by_aligned=$(printf '%s\n' "$line" \ |
| 57 | + | grep -oE '\([0-9]+ sent\)' \ |
| 58 | + | grep -oE '[0-9]+' \ |
| 59 | + | head -1) |
| 60 | + if [[ -n "$proofs_submitted_by_aligned" ]]; then |
| 61 | + submitted_by_aligned=$((submitted_by_aligned + proofs_submitted_by_aligned)) |
| 62 | + fi |
| 63 | + |
| 64 | + eth_spent=$(printf '%s\n' "$line" \ |
| 65 | + | sed -n 's/.*Spent \([0-9.]*\) ETH.*/\1/p') |
| 66 | + if [[ -n "$eth_spent" ]]; then |
| 67 | + eth_total=$(echo "$eth_total + $eth_spent" | bc -l) |
| 68 | + eth_by_aligned=$(echo "$eth_by_aligned + $eth_spent / $proofs_submitted * $proofs_submitted_by_aligned" | bc -l) |
| 69 | + fi |
| 70 | + |
| 71 | + usd_spent=$(printf '%s\n' "$line" \ |
| 72 | + | sed -n 's/.*(\$ *\([0-9.]*\)).*/\1/p') |
| 73 | + if [[ -n "$usd_spent" ]]; then |
| 74 | + usd_total=$(echo "$usd_total + $usd_spent" | bc -l) |
| 75 | + usd_by_aligned=$(echo "$usd_by_aligned + $usd_spent / $proofs_submitted * $proofs_submitted_by_aligned" | bc -l) |
| 76 | + fi |
| 77 | + ;; |
| 78 | + *"FAILURE:"*) |
| 79 | + batches=$((batches + 1)) |
| 80 | + |
| 81 | + proofs_submitted=$(printf '%s\n' "$line" \ |
| 82 | + | grep -oE '[0-9]+ proofs submitted' \ |
| 83 | + | head -1 \ |
| 84 | + | cut -d' ' -f1) |
| 85 | + if [[ -n "$proofs_submitted" ]]; then |
| 86 | + submitted_total=$((submitted_total + proofs_submitted)) |
| 87 | + unverified_total=$((unverified_total + proofs_submitted)) |
| 88 | + fi |
| 89 | + |
| 90 | + proofs_submitted_by_aligned=$(printf '%s\n' "$line" \ |
| 91 | + | grep -oE '\([0-9]+ sent\)' \ |
| 92 | + | grep -oE '[0-9]+' \ |
| 93 | + | head -1) |
| 94 | + if [[ -n "$proofs_submitted_by_aligned" ]]; then |
| 95 | + submitted_by_aligned=$((submitted_by_aligned + proofs_submitted_by_aligned)) |
| 96 | + fi |
| 97 | + |
| 98 | + eth_spent=$(printf '%s\n' "$line" \ |
| 99 | + | sed -n 's/.*Spent \([0-9.]*\) ETH.*/\1/p') |
| 100 | + if [[ -n "$eth_spent" ]]; then |
| 101 | + eth_total=$(echo "$eth_total + $eth_spent" | bc -l) |
| 102 | + eth_by_aligned=$(echo "$eth_by_aligned + $eth_spent / $proofs_submitted * $proofs_submitted_by_aligned" | bc -l) |
| 103 | + fi |
| 104 | + |
| 105 | + usd_spent=$(printf '%s\n' "$line" \ |
| 106 | + | sed -n 's/.*(\$ *\([0-9.]*\)).*/\1/p') |
| 107 | + if [[ -n "$usd_spent" ]]; then |
| 108 | + usd_total=$(echo "$usd_total + $usd_spent" | bc -l) |
| 109 | + usd_by_aligned=$(echo "$usd_by_aligned + $usd_spent / $proofs_submitted * $proofs_submitted_by_aligned" | bc -l) |
| 110 | + fi |
| 111 | + esac |
| 112 | + done < "$LOG_FILE" |
| 113 | + |
| 114 | + summary=$( |
| 115 | + printf "Daily Proof Submission Summary\n" |
| 116 | + printf "From %s 00:00 to %s 23:59\n" "$DATE" "$DATE" |
| 117 | + echo "----------------------------------------------------" |
| 118 | + printf "Processed batches: %d\n" "$batches" |
| 119 | + printf "Total Proofs submitted: %d\n" "$submitted_total" |
| 120 | + printf "Total Proofs verified: %d\n" "$verified_total" |
| 121 | + printf "Total Proofs not verified: %d\n" "$unverified_total" |
| 122 | + printf "Submitted by Aligned: %d\n" "$submitted_by_aligned" |
| 123 | + printf "Submitted by 3rd parties: %d\n" "$((submitted_total - submitted_by_aligned))" |
| 124 | + echo "----------------------------------------------------" |
| 125 | + printf "Spent by Aligned (ETH): %.12f ETH\n" "$eth_by_aligned" |
| 126 | + printf "Spent by Aligned (USD): $ %.2f\n" "$usd_by_aligned" |
| 127 | + printf "Spent by 3rd parties (ETH): %.12f ETH\n" "$(echo "$eth_total - $eth_by_aligned" | bc -l)" |
| 128 | + printf "Spent by 3rd parties (USD): $ %.2f\n" "$(echo "$usd_total - $usd_by_aligned" | bc -l)" |
| 129 | + printf "Total spent (ETH): %.12f ETH\n" "$eth_total" |
| 130 | + printf "Total spent (USD): $ %.2f\n" "$usd_total" |
| 131 | + echo "----------------------------------------------------" |
| 132 | + ) |
| 133 | + |
| 134 | + echo "$summary" |
| 135 | + |
| 136 | + # Send the summary to Slack |
| 137 | + if [[ -n "$SLACK_WEBHOOK_URL" ]]; then |
| 138 | + safe_summary=$(printf '%s\n' "$summary" | sed 's/"/\\"/g') |
| 139 | + curl -s -X POST -H 'Content-type: application/json' \ |
| 140 | + --data "{\"text\":\"\`\`\`$safe_summary\`\`\`\"}" \ |
| 141 | + "$SLACK_WEBHOOK_URL" >/dev/null 2>&1 |
| 142 | + fi |
| 143 | +else |
| 144 | + echo "Proof Submission Summary - $DATE" |
| 145 | + echo "----------------------------------------" |
| 146 | + echo "No log file found for today: $LOG_FILE" |
| 147 | + echo "----------------------------------------" |
| 148 | +fi |
0 commit comments