blob: f09d198082ba651a1c3b2646192270bb26404705 (
plain)
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
|
#! /usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
time_from=""
time_until="tomorrow"
postfix_received=""
rbl_dropped=""
spampd_clean=""
spampd_spam=""
sieve_spam=""
postfix_sent=""
postgrey_delayed=""
function set_range()
{
case $1 in
"month")
time_from=$(date --date="last month" -I)
;;
"week")
time_from=$(date --date="last week" -I)
;;
"day")
time_from=$(date -I)
;;
"yesterday")
time_from=$(date --date="yesterday" -I)
time_until="today"
esac
}
function get_stats()
{
set +e
postfix_received=$(journalctl -S "$time_from" -U "$time_until" _EXE=/usr/lib/postfix/bin/smtpd|grep "proxy-accept"| wc -l)
rbl_dropped=$(journalctl -S "$time_from" -U "$time_until" -u postfix |grep "Service unavailable"| wc -l)
spampd_clean=$(journalctl -S "$time_from" -U "$time_until" -u spampd| grep "clean message"| wc -l)
spampd_spam=$(journalctl -S "$time_from" -U "$time_until" -u spampd| grep "identified spam"| wc -l)
sieve_spam=$(journalctl -S "$time_from" -U "$time_until" _EXE=/usr/lib/dovecot/dovecot-lda| grep "Spam"| wc -l)
postfix_sent=$(journalctl -S "$time_from" -U "$time_until" _EXE=/usr/lib/postfix/bin/smtp |grep "sent"| wc -l)
postgrey_delayed=$(journalctl -S "$time_from" -U "$time_until" -u postgrey |grep "reason=new"| wc -l)
set -e
}
function print_stats()
{
echo "Mail statistics for $(hostname) since $time_from"
echo "Received total: $postfix_received"
echo "RBL dropped: $rbl_dropped"
echo "Delayed: $postgrey_delayed"
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"
;;
"-y")
set_range "yesterday"
;;
*)
set_range "day"
;;
esac
get_stats
print_stats
exit 0
|