-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_hourly.sh
executable file
·86 lines (69 loc) · 3.02 KB
/
report_hourly.sh
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
#!/bin/bash
#
# Daily Report
# by Ken O. Burtch
# Produce the daily email report as well as update the web dashboard.
#############################################################################
# If a non-empty string, runs the report for testing.
DRY_RUN=
# The location of the web dashboard.
cd "utils"
WEBROOT=`/usr/local/bin/spar export_dashboard_file_path.sp`
if [ -z "$WEBROOT" ] ; then
echo "Could not lookup web dashboard location" 2>&1
exit 1
fi
cd ..
# Yesterday, and just after midnight today
REPORT_DATE_TODAY=`date '+%m/%d'`" 00:"
REPORT_DATE_YESTERDAY=`date --date 'yesterday' '+%m/%d'`
TMP_DIR="run"
TMP1="$TMP_DIR""/""tmp1.$$"
TMP2="$TMP_DIR""/""tmp2.$$"
TMP3="$TMP_DIR""/""tmp3.$$"
TMP_BLK="$TMP_DIR""/""tmp_blk"
HS="$WEBROOT""/""hourly_summary.frag"
# For the ipset block list, there's 8 lines of headers
CURRENT_BLOCKS=`/sbin/ipset -L blocklist | wc -l`
let "CURRENT_BLOCKS=CURRENT_BLOCKS-8"
TOTAL_ON_FILE=`cat /root/ssds/data/blocking_cnt.txt`
TOTAL_LOGINS=`cat /root/ssds/data/login_cnt.txt`
DISK_USAGE=`du -sh /root/ssds/data | cut -f1`
if [ "$CURRENT_BLOCKS" -gt 25000 ] ; then
BGCOLOR="background-color: red"
elif [ "$CURRENT_BLOCKS" -gt 12000 ] ; then
BGCOLOR="background-color: orange"
elif [ "$CURRENT_BLOCKS" -eq 0 ] ; then
BGCOLOR="background-color: red"
fi
echo > "$HS"
echo '<div class="kpi_box">' >> "$HS"
echo '<div class="kpi_header">'"<b>Last Hour</b></div>" >> "$HS"
echo '<div style="width:100%; height: 100%">' >> "$HS"
echo '<table style="border: none; padding: 0; border-collapse: collapse; margin:0 auto">' >> "$HS"
BLOCKS_LIMIT=`/usr/local/bin/spar utils/export_blocks_limit.sp`
BGCOLOR="background-color: transparent"
if [ $CURRENT_BLOCKS -ge "$BLOCKS_LIMIT" ] ; then
BGCOLOR="background-color: red"
/usr/local/bin/spar utils/blocks_limit.sp
fi
echo "<tr>" >> "$HS"
echo '<td class="kpi_layout"><span class="plain_data" style="'"$BGCOLOR"'">'"$CURRENT_BLOCKS""</span>""</td><td>"'<span class="plain_light">'" Currently Blocked""</span>""</td>" >> "$HS"
echo "</tr><tr>" >> "$HS"
echo '<td class="kpi_layout"><span class="plain_data">'"$TOTAL_ON_FILE""</span>""</td><td>"'<span class="plain_light">'" Monitored""</span>""</td>" >> "$HS"
echo "</tr><tr>" >> "$HS"
echo '<td style="text-align:right; min-width: 50px; padding-right: 3px;">''<span class="plain_data">'"$TOTAL_LOGINS""</span>""</td><td>""<span class="plain_light">""Usernames""</span>""</td>" >> "$HS"
echo "</tr><tr>" >> "$HS"
SPACE_LIMIT=`/usr/local/bin/spar utils/export_space_limit.sp`
BGCOLOR="background-color: transparent"
DISK_USAGE=`echo "$DISK_USAGE" | cut -d. -f1` # number could be float
TMP="${DISK_USAGE%M}" # Strip units (M) from amount
if [ $TMP -ge "$SPACE_LIMIT" ] ; then
BGCOLOR="background-color: red"
/usr/local/bin/spar utils/space_limit.sp
fi
echo '<td class="kpi_layout">''<span class="plain_data" style="'"$BGCOLOR"'">'"$DISK_USAGE""</span>""</td><td>"'<span class="plain_light">'"Storage Used""</span>""</td>" >> "$HS"
echo "</tr>" >> "$HS"
echo "</table>" >> "$HS"
echo "</div>" >> "$HS"
echo "</div>" >> "$HS"