-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathgenerate_send_summary.sh
More file actions
executable file
·132 lines (114 loc) · 4.18 KB
/
generate_send_summary.sh
File metadata and controls
executable file
·132 lines (114 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# ENV VARIABLES:
# - REPETITIONS
# - EXPLORER_URL
# - SENDER_ADDRESS
# - RPC_URL
# - EXPLORER_URL
# - NETWORK
# - PRIVATE_KEY
# - VERIFICATION_WAIT_TIME
# - LOGS_BLOCK_RANGE
# - PAGER_DUTY_KEY
# - PAGER_DUTY_EMAIL
# - PAGER_DUTY_SERVICE_ID
# - SLACK_WEBHOOK_URL
# Load env file from $1 path
source "$1"
DATE=$(date -d "yesterday" +"%Y_%m_%d")
# Determine log file name based on current date
LOG_FILE="./alerts/notification_logs/log_$DATE.txt"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
cd ..
batches=0
submitted_total=0
verified_total=0
unverified_total=0
eth_total="0"
usd_total="0"
# Read the log file entries and generate a summary
if [[ -f "$LOG_FILE" ]]; then
while IFS= read -r line; do
case "$line" in
*"SUCCESS:"*)
batches=$((batches + 1))
proofs_submitted=$(printf '%s\n' "$line" \
| grep -oE '[0-9]+ proofs submitted' \
| head -1 \
| cut -d' ' -f1)
if [[ -n "$proofs_submitted" ]]; then
submitted_total=$((submitted_total + proofs_submitted))
fi
proofs_verified=$(printf '%s\n' "$line" \
| grep -oE '\([0-9]+ sent\)' \
| grep -oE '[0-9]+' \
| head -1)
if [[ -n "$proofs_verified" ]]; then
verified_total=$((verified_total + proofs_verified))
fi
eth_spent=$(printf '%s\n' "$line" \
| sed -n 's/.*Spent \([0-9.]*\) ETH.*/\1/p')
if [[ -n "$eth_spent" ]]; then
eth_total=$(echo "$eth_total + $eth_spent" | bc -l)
fi
usd_spent=$(printf '%s\n' "$line" \
| sed -n 's/.*(\$ *\([0-9.]*\)).*/\1/p')
if [[ -n "$usd_spent" ]]; then
usd_total=$(echo "$usd_total + $usd_spent" | bc -l)
fi
;;
*"FAILURE:"*)
batches=$((batches + 1))
proofs_submitted=$(printf '%s\n' "$line" \
| grep -oE '[0-9]+ proofs submitted' \
| head -1 \
| cut -d' ' -f1)
if [[ -n "$proofs_submitted" ]]; then
submitted_total=$((submitted_total + proofs_submitted))
fi
proofs_unverified=$(printf '%s\n' "$line" \
| grep -oE '\([0-9]+ sent\)' \
| grep -oE '[0-9]+' \
| head -1)
if [[ -n "$proofs_verified" ]]; then
unverified_total=$((verified_total + proofs_verified))
fi
eth_spent=$(printf '%s\n' "$line" \
| sed -n 's/.*Spent \([0-9.]*\) ETH.*/\1/p')
if [[ -n "$eth_spent" ]]; then
eth_total=$(echo "$eth_total + $eth_spent" | bc -l)
fi
usd_spent=$(printf '%s\n' "$line" \
| sed -n 's/.*(\$ *\([0-9.]*\)).*/\1/p')
if [[ -n "$usd_spent" ]]; then
usd_total=$(echo "$usd_total + $usd_spent" | bc -l)
fi
esac
done < "$LOG_FILE"
summary=$(
printf "Daily Proof Submission Summary\n"
printf "From %s 00:00 to %s 23:59\n" "$DATE" "$DATE"
echo "----------------------------------------------------"
printf "Processed batches: %d\n" "$batches"
printf "Proofs submitted: %d\n" "$submitted_total"
printf "Proofs verified: %d\n" "$verified_total"
printf "Proofs not verified: %d\n" "$unverified_total"
printf "Total spent (ETH): %.12f ETH\n" "$eth_total"
printf "Total spent (USD): $ %.2f\n" "$usd_total"
echo "----------------------------------------------------"
)
echo "$summary"
# Send the summary to Slack
if [[ -n "$SLACK_WEBHOOK_URL" ]]; then
safe_summary=$(printf '%s\n' "$summary" | sed 's/"/\\"/g')
curl -s -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"$safe_summary\"}" \
"$SLACK_WEBHOOK_URL" >/dev/null 2>&1
fi
else
echo "Proof Submission Summary - $DATE"
echo "----------------------------------------"
echo "No log file found for today: $LOG_FILE"
echo "----------------------------------------"
fi