We are using PRTG to monitor our system and decided to add a new sensor for our Postfix mail server. After a bit of searching, I found this nice howto for Zabbix and I did a small modification on the scrip to generate as output a XML for SSH Script Advanced sensor. Only thing you have to run this script is pflogsumm and logtail.
#!/usr/bin/env bash MAILLOG=/var/log/mail.log PFOFFSETFILE=/tmp/postfix-offset.dat PFSTATSFILE=/tmp/postfix_statsfile.dat TEMPFILE=$(mktemp) TODAY=$(date +'%b %d') PFLOGSUMM=/home/telni/pflogsumm/pflogsumm.pl LOGTAIL=/home/telni/logtail/logtail PFVALS=( 'received' 'delivered' 'forwarded' 'deferred' 'bounced' 'rejected' 'held' 'discarded' 'reject_warnings' 'bytes_received' 'bytes_delivered' ) [ ! -e "${PFSTATSFILE}" ] && touch "${PFSTATSFILE}" && chown telni:telni "${PFSTATSFILE}" printvalues() { key=$1 pfkey=$(echo "$1" | tr '_' ' ') value=$(grep -m 1 "${pfkey}" $TEMPFILE | awk '{print $1}' | awk '/k|m/{p = /k/?1:2}{printf "%d\n", int($1) * 1024 ^ p}') old_value=$(grep -e "^${key};" "${PFSTATSFILE}" | cut -d ";" -f2) if [ -n "${old_value}" ]; then sed -i -e "s/^${key};${old_value}/${key};$((${old_value}+${value}))/" "${PFSTATSFILE}" if [[ ${key} =~ bytes.* ]]; then echo -e " <result>\n <channel>${key}</channel>\n <value>$((${value}/1024))</value>\n </result>" else echo -e " <result>\n <channel>${key}</channel>\n <value>${value}</value>\n </result>" fi else echo "${key};${value}" >> "${PFSTATSFILE}" echo -e " <result>\n <channel>${key}</channel>\n <value>0</value>\n </result>" fi } echo "<prtg>" "${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}" for i in "${PFVALS[@]}"; do printvalues "$i" done echo "</prtg>" rm "${TEMPFILE}"
Hi there, looks very interesting, and I get a lot of fine numbers out, but I get an error for each number:
sed: -e expression #1, char 12: unterminated `s’ command
But as I can see the command is terminated, so I’m a bit at a loss, it’s on CentOS 7
Do you have a solution for it?
Please check carefully all the quote symbols (” or ‘).