aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2017-06-27 14:58:07 +0200
committerDavid Runge <dave@sleepmap.de>2017-06-27 14:58:07 +0200
commit24e8c2de3e32450acff63af2bad49756dc4dc1ee (patch)
treef8c8c8c07acdc54d546feb2c60558d51a80f6598
parent32a18ea803262e9663e35da7f783565584b0ae0e (diff)
downloaddotfiles-24e8c2de3e32450acff63af2bad49756dc4dc1ee.tar.gz
dotfiles-24e8c2de3e32450acff63af2bad49756dc4dc1ee.tar.bz2
dotfiles-24e8c2de3e32450acff63af2bad49756dc4dc1ee.tar.xz
dotfiles-24e8c2de3e32450acff63af2bad49756dc4dc1ee.zip
bin/get_mail_stats: Add functionality to get stats for last week and last month.
-rwxr-xr-xbin/get_mail_stats79
1 files changed, 63 insertions, 16 deletions
diff --git a/bin/get_mail_stats b/bin/get_mail_stats
index 2a07b73..0fcf20d 100755
--- a/bin/get_mail_stats
+++ b/bin/get_mail_stats
@@ -3,20 +3,67 @@
set -euo pipefail
IFS=$'\n\t'
-set +e
-postfix_received=$(journalctl --since "0:00" _EXE=/usr/lib/postfix/bin/smtpd|grep "proxy-accept"| wc -l)
-rbl_dropped=$(journalctl --since "0:00" -u postfix |grep "Service unavailable"|wc -l)
-spampd_clean=$(journalctl --since "0:00" -u spampd| grep "clean message"| wc -l)
-spampd_spam=$(journalctl --since "0:00" -u spampd| grep "identified spam"| wc -l)
-sieve_spam=$(journalctl --since "0:00" _EXE=/usr/lib/dovecot/dovecot-lda| grep "Spam"| wc -l)
-postfix_sent=$(journalctl --since "0:00" _EXE=/usr/lib/postfix/bin/smtp |grep "sent"| wc -l)
-date=$(date -I)
-set -e
+time_frame=""
+postfix_received=""
+rbl_dropped=""
+spampd_clean=""
+spampd_spam=""
+sieve_spam=""
+postfix_sent=""
-echo "Mail statistics for $(hostname) on $date"
-echo "Received total: $postfix_received"
-echo "RBL dropped: $rbl_dropped"
-echo "Spampd clean: $spampd_clean"
-echo "Spampd spam: $spampd_spam"
-echo "Sieve spam: $spampd_spam"
-echo "Sent: $postfix_sent"
+function set_range()
+{
+ case $1 in
+ "month")
+ time_frame=$(date --date="last month" -I)
+ ;;
+ "week")
+ time_frame=$(date --date="last week" -I)
+ ;;
+ "day")
+ time_frame=$(date -I)
+ ;;
+ esac
+}
+
+function get_stats()
+{
+ set +e
+ postfix_received=$(journalctl -S "$time_frame" _EXE=/usr/lib/postfix/bin/smtpd|grep "proxy-accept"| wc -l)
+ rbl_dropped=$(journalctl -S "$time_frame" -u postfix |grep "Service unavailable"| wc -l)
+ spampd_clean=$(journalctl -S "$time_frame" -u spampd| grep "clean message"| wc -l)
+ spampd_spam=$(journalctl -S "$time_frame" -u spampd| grep "identified spam"| wc -l)
+ sieve_spam=$(journalctl -S "$time_frame" _EXE=/usr/lib/dovecot/dovecot-lda| grep "Spam"| wc -l)
+ postfix_sent=$(journalctl -S "$time_frame" _EXE=/usr/lib/postfix/bin/smtp |grep "sent"| wc -l)
+ set -e
+}
+
+function print_stats()
+{
+ echo "Mail statistics for $(hostname) since $time_frame"
+ echo "Received total: $postfix_received"
+ echo "RBL dropped: $rbl_dropped"
+ echo "Spampd clean: $spampd_clean"
+ echo "Spampd spam: $spampd_spam"
+ echo "Sieve spam: $spampd_spam"
+ echo "Sent: $postfix_sent"
+}
+
+case ${@} in
+ "-w")
+ set_range "week"
+ ;;
+ "-m")
+ set_range "month"
+ ;;
+ "-d")
+ set_range "day"
+ ;;
+ *)
+ set_range "day"
+ ;;
+esac
+
+get_stats
+print_stats
+exit 0