Skip to content

Zabbix template for Exim

LEGACY CONTENT! See actual Ansible repository!

Zabbix Agent 2.2
Exim 4.84

Items (trappers): Mails Delivered, Mails Delivered Bytes, Mails Received, Mails Received Bytes; Mails Rejected, Mails Errors
Items (by agent): Mails in queue.

Triggers: More than 100 Mails in the Queue, More than 500 Mails in the Queue
Graphs: Exim Traffic, Exim Traffic Bytes

Configuration:

/usr/local/etc/zabbix22/zabbix\_agentd.conf

UserParameter=exim.mailqueue,/usr/local/etc/zabbix22/zabbix-exim.sh exim.mailqueue

/usr/local/etc/zabbix22/zabbix-exim.sh

#!/bin/sh
PATH=$PATH:/bin:/usr/bin:/usr/local/bin
ACTION="$1"
EXIM="/usr/local/sbin/exim"

case $ACTION in
    exim.mailqueue)
        result=`sudo $EXIM -bpc`
    ;;
    *)
        result=0
    ;;
esac
echo $result

/usr/local/etc/zabbix22/zabbix-exim-trappers.sh

#!/bin/sh
# FreeBSD 10
# Zabbix agent 2.2
EXIMLOG=/var/log/exim/main.log
OFFSETFILE=/tmp/eximstatusoffset.dat
EXIMSTATS=/usr/local/sbin/eximstats
LOGTAIL=/usr/local/sbin/logtail
ZABBIX_SENDER=/usr/local/bin/zabbix_sender
ZABBIX_CONF=/usr/local/etc/zabbix22/zabbix_agentd.conf
PARTOFLOG=$(mktemp)
STATS=$(mktemp)

# Function to send value to Zabbix server
send2zabbix() {
KEY=$1
VALUE=$2
#echo $KEY $VALUE
$ZABBIX_SENDER -c $ZABBIX_CONF -k $KEY -o $VALUE
}

# Get part of the log
$LOGTAIL -f $EXIMLOG -o $OFFSETFILE > $PARTOFLOG
# Generate exim stats report
$EXIMSTATS -t0 -nvr -nr -nt -nr $PARTOFLOG > $STATS

# I consider it correct to return 0 if there is nothing in the logs.
# If nothing is returned, we will get a nodata() trigger message in Zabbix.
# Relevant for a server that has nothing happening during the polling interval
# (If the eximstats output file for the log part is NOT empty)
if [ -s $STATS ]
then

    send2zabbix exim.received `grep -m 1 Received $STATS | awk '{print $3}'`
    send2zabbix exim.receivedbytes `grep -m 1 Received $STATS | awk '{print $2}'`....
    send2zabbix exim.rejected `grep -m 1 Rejects $STATS | awk '{print $2}'`....
    send2zabbix exim.delivered `grep -m 1 Delivered $STATS | awk '{print $3}'`
    send2zabbix exim.deliveredbytes `grep -m 1 Delivered $STATS | awk '{print $2}'`
    send2zabbix exim.errors `grep -m 1 "Errors encountered:" $STATS | awk '{print $2}'`
....
else
    send2zabbix exim.received 0
    send2zabbix exim.receivedbytes 0....
    send2zabbix exim.rejected 0
    send2zabbix exim.delivered 0
    send2zabbix exim.deliveredbytes 0
    send2zabbix exim.errors 0....
fi

rm $PARTOFLOG
rm $STATS

/etc/cron

# EXIM Statistics for  Zabbix
*/5  *  *  *  *  root  /usr/local/etc/zabbix22/zabbix-exim-trappers.sh 1>/dev/null 2>/dev/null

UPDATE 21.09.2017

  • Cron is no longer used
  • Values are sent in batch, not one by one
  • Trigger values reduced to 10 and 50

UPDATE 29.11.2017

  • Added data item for the number of frozen messages in the queue

LEGACY CONTENT! See actual Ansible repository!

Configuration:

/etc/sudoers.d/sudoers-zabbix

zabbix ALL=(ALL) NOPASSWD:/usr/sbin/exim, /usr/sbin/exipick,/usr/sbin/eximstats, /usr/sbin/logtail, /usr/bin/zabbix_sender

/etc/zabbix/zabbix\_agentd.d/zabbix-exim.conf

UserParameter=exim.ping,/etc/zabbix/scripts/exim-ping.sh

/etc/zabbix/scripts/exim-ping.sh

#!/bin/bash
# Zabbix Exim ping script
EXIMLOG=/var/log/exim4/main.log
OFFSETFILE=/tmp/eximstatusoffset.dat
EXIMSTATS=/usr/sbin/eximstats
EXIM=/usr/sbin/exim
EXIPICK=/usr/sbin/exipick
LOGTAIL=/usr/sbin/logtail
ZABBIX_SENDER=/usr/bin/zabbix_sender
ZABBIX_CONF=/etc/zabbix/zabbix_agentd.conf
PARTOFLOG=$(mktemp)
STATS=$(mktemp)
VALUES=$(mktemp)
# Helper functions
toval() {
# second parameter is value, may arrive empty
if [ "$2" == "" ]
then {
VAL="0"
}
else {
VAL=$2
}
fi
    echo "-" $1 $VAL >>$VALUES
}
# Get part of the log
sudo $LOGTAIL -f $EXIMLOG -o $OFFSETFILE > $PARTOFLOG
# Generate exim stats report
sudo $EXIMSTATS -t0 -h0 -nvr -nr -nt -nr $PARTOFLOG > $STATS 2>/dev/null
# Clear the data file
rm $VALUES
# Fill the file with values for sending
toval exim.mailqueue `sudo $EXIM -bpc`
toval exim.frozen `sudo $EXIPICK -zi | wc -l`
# If the file is empty, the toval function will handle 0 values
toval exim.received `grep -m 1 Received $STATS | awk '{print $3}'`
toval exim.receivedbytes `grep -m 1 Received $STATS | awk '{print $2}'`
toval exim.rejected `grep -m 1 Rejects $STATS | awk '{print $2}'`
toval exim.delivered `grep -m 1 Delivered $STATS | awk '{print $3}'`
toval exim.deliveredbytes `grep -m 1 Delivered $STATS | awk '{print $2}'`
toval exim.errors `grep -m 1 "Errors encountered:" $STATS | awk '{print $3}'`
# Send values to Zabbix server
sudo $ZABBIX_SENDER -c $ZABBIX_CONF -i $VALUES >/dev/null 2>&1
# Cleanup
rm -f $PARTOFLOG
rm -f $STATS
rm -f $VALUES
#
echo 1
# end of file