14 |
rodolico |
1 |
#!/usr/bin/env bash
|
|
|
2 |
|
|
|
3 |
# see
|
|
|
4 |
# http://lifeisabug.com/postfix-statistical-graphs-zabbix-using-passive-checks/
|
|
|
5 |
|
|
|
6 |
MAILLOG=/var/log/mail.log
|
|
|
7 |
PFOFFSETFILE=/tmp/zabbix-postfix-offset.dat
|
|
|
8 |
PFSTATSFILE=/tmp/postfix_statsfile.dat
|
|
|
9 |
TEMPFILE=$(mktemp)
|
|
|
10 |
PFLOGSUMM=/usr/sbin/pflogsumm
|
|
|
11 |
LOGTAIL=/usr/sbin/logtail
|
|
|
12 |
|
|
|
13 |
PFVALS=( 'received' 'delivered' 'forwarded' 'deferred' 'bounced' 'rejected' 'held' 'discarded' 'reject_warnings' 'bytes_received' 'bytes_delivered' 'queued' )
|
|
|
14 |
|
|
|
15 |
[ ! -e "${PFSTATSFILE}" ] && touch "${PFSTATSFILE}" && chown zabbix:zabbix "${PFSTATSFILE}"
|
|
|
16 |
|
|
|
17 |
printvalues() {
|
|
|
18 |
key=$1
|
|
|
19 |
pfkey=$(echo "$1" | tr '_' ' ')
|
|
|
20 |
value=$(grep -m 1 "${pfkey}" $TEMPFILE | awk '{print $1}' | awk '/k|m/{p = /k/?1:2}{printf "%d\n", int($1) * 1024 ^ p}')
|
|
|
21 |
old_value=$(grep -e "^${key};" "${PFSTATSFILE}" | cut -d ";" -f2)
|
|
|
22 |
# modified by RWR to NOT add queued keys, but simply store them
|
|
|
23 |
if [ -n "$old_value" -a "$1" == 'queued' ]; then
|
|
|
24 |
sed -i -e "s/^${key};${old_value}/${key};${value}/" "${PFSTATSFILE}"
|
|
|
25 |
else
|
|
|
26 |
if [ -n "${old_value}" ]; then
|
|
|
27 |
sed -i -e "s/^${key};${old_value}/${key};$((${old_value}+${value}))/" "${PFSTATSFILE}"
|
|
|
28 |
else
|
|
|
29 |
echo "${key};${value}" >> "${PFSTATSFILE}"
|
|
|
30 |
fi
|
|
|
31 |
fi
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
if [ -n "$1" ]; then
|
|
|
35 |
key=$(echo ${PFVALS[@]} | grep -wo $1)
|
|
|
36 |
if [ -n "${key}" ]; then
|
|
|
37 |
value=$(grep -e "^${key};" "${PFSTATSFILE}" | cut -d ";" -f2)
|
|
|
38 |
echo "${value}"
|
|
|
39 |
else
|
|
|
40 |
rm "${TEMPFILE}"
|
|
|
41 |
exit 2
|
|
|
42 |
fi
|
|
|
43 |
else
|
|
|
44 |
"${LOGTAIL}" -f"${MAILLOG}" -o"${PFOFFSETFILE}" | "${PFLOGSUMM}" -h 0 -u 0 --bounce_detail=0 --deferral_detail=0 --reject_detail=0 --no_no_msg_size --smtpd_warning_detail=0 > "${TEMPFILE}"
|
|
|
45 |
# modified by RWR to process the mail queue also
|
|
|
46 |
echo `/usr/bin/mailq | /bin/grep -v "Mail queue is empty" | /bin/grep -c '^[0-9A-Z]'` queued >> "${TEMPFILE}"
|
|
|
47 |
for i in "${PFVALS[@]}"; do
|
|
|
48 |
printvalues "$i"
|
|
|
49 |
done
|
|
|
50 |
fi
|
|
|
51 |
|
|
|
52 |
rm "${TEMPFILE}"
|