Skip to content

Instantly share code, notes, and snippets.

@RoBo-OnGitHub
Forked from crashdump/zbx-exim-stats.sh
Last active March 23, 2021 21:32
Show Gist options
  • Save RoBo-OnGitHub/97127185ec7a3c73cb369262ed99cc8b to your computer and use it in GitHub Desktop.
Save RoBo-OnGitHub/97127185ec7a3c73cb369262ed99cc8b to your computer and use it in GitHub Desktop.
A simple Zabbix statistics pusher. It check and report these values: - Number of running processes exim4 (trigger if 0) - Mails Queue Size (trigger if >500 and >1000) - Mails Received - Mails Error - Mails Received Size in Bytes - Mails Delivered - Mails Delivered Size in BytesImport the template. Assign to you hosts. Cron the .sh.. You're good …
#!/bin/bash
#
# The purpose of this script is to regularly send statistics of exim to a Zabbix server
#
# Updated by RoBo on 2021-03-23
# This is how you can make use of this script:
# Enable "ServerActive" option (zabbix_agentd.conf)
# Try "Hostname" option (zabbix_agentd.conf)
# You need following applications to be installed:
# # Either logtail or logcheck
# # zabbix-sender
# Use your packet manager to install. Like yum under CentOS/Redhat: 'yum install logcheck zabbix-sender'
#
# Then import template 'zbx-exim-stats.template.xml' to your Zabbix-Server
# Kudo's go to
# crashdump, for providing the first coding: https://gist.github.com/crashdump
# jchavezb, for solving the snmpv3 template issue: https://www.zabbix.com/forum/zabbix-help/391402-importing-template-issue#post416712
# wosc, for silincing the script: https://gist.github.com/crashdump/5697771#gistcomment-2321518
# Set user specific variables
EXIMLOG=/var/log/exim/mainlog
MYLOG=/tmp/exim_status.log
EXIM=/sbin/exim
EXIMSTATS=/usr/sbin/eximstats
LOGTAIL=/usr/sbin/logtail
ZABBIX_SENDER=/usr/bin/zabbix_sender
ZABBIX_CONF=/etc/zabbix/zabbix_agentd.conf
OFFSETFILE=/tmp/eximstatusoffset.dat
# Set application specific variables
TMP1=$(mktemp)
TMP2=$(mktemp)
exrec=0
exdev=0
exmq=0
CLIENT_HOST=$(hostname)
##############################
#echo TMP1 $TMP1
#echo TMP2 $TMP2
zsend() {
# echo "$1 $2"
$ZABBIX_SENDER -s $CLIENT_HOST -c $ZABBIX_CONF -k $1 -o $2 >/dev/nul
}
if !($LOGTAIL -f $EXIMLOG -o $OFFSETFILE > $TMP1); then
exit 1
fi
if [ $(wc -l $TMP1|cut -d' ' -f1) -eq 0 ]; then
# echo "ERROR: $TMP1 empty"
exit 1
fi
if !($EXIMSTATS -emptyok -t0 -nvr $TMP1 > $TMP2); then
# echo "ERROR: $EXIMSTATS -t0 -nvr $TMP1"
exit 2
fi
echo "Errors 0 0" >> $TMP2
exrec=$(grep -m 1 Received $TMP2|awk '{print $3}')
[ -z $exrec ] && exrec=0
exdev=$(grep -m 1 Delivered $TMP2|awk '{print $3}')
[ -z $exdev ] && exdev=0
exerr=$(grep -m 1 Errors $TMP2|awk '{print $3}')
[ -z $exerr ] && exerr=0
exbrec=$(grep -m 1 "Received" $TMP2|awk '{print $2}')
[ -z $exbrec ] && exbrec=0
exbdev=$(grep -m 1 "Delivered" $TMP2|awk '{print $2}')
[ -z $exbdev ] && exbrec=0
# The number of messaged in the queue
#exmq=$(mailq | grep -c "[a-A0-9]")
exmq=$($EXIM -bpc)
[ -z $exmq ] && exmq=0
zsend exreceived $exrec
zsend exdelivered $exdev
zsend exerrors $exerr
zsend exbytesreceived $exbrec
zsend exbytesdelivered $exbdev
zsend exmailqueue $exmq
rm $TMP1
rm $TMP2
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2013-06-03T12:18:47Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template OS Linux - Exim Advanced</template>
<name>Template OS Linux - Exim Advanced</name>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>Exim</name>
</application>
</applications>
<items>
<item>
<name>Mails Delivered</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>exdelivered</key>
<delay>180</delay>
<history>60</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<snmpv3_contextname/>
<snmpv3_authprotocol/>
<snmpv3_privprotocol/>
<logtimefmt/>
<formula>0</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Exim</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Mails Delivered Size in Bytes</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>exbytesdelivered</key>
<delay>180</delay>
<history>60</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>B</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<snmpv3_contextname/>
<snmpv3_authprotocol/>
<snmpv3_privprotocol/>
<logtimefmt/>
<formula>0</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Exim</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Mails Error</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>exerrors</key>
<delay>180</delay>
<history>60</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<snmpv3_contextname/>
<snmpv3_authprotocol/>
<snmpv3_privprotocol/>
<logtimefmt/>
<formula>0</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Exim</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Mails Queue Size</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>exmailqueue</key>
<delay>0</delay>
<history>90</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<snmpv3_contextname/>
<snmpv3_authprotocol/>
<snmpv3_privprotocol/>
<logtimefmt/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description>mailq reported mail queue size</description>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Exim</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Mails Received</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>exreceived</key>
<delay>180</delay>
<history>60</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<snmpv3_contextname/>
<snmpv3_authprotocol/>
<snmpv3_privprotocol/>
<logtimefmt/>
<formula>0</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Exim</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Mails Received Size in Bytes</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>exbytesreceived</key>
<delay>180</delay>
<history>60</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units>B</units>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<snmpv3_contextname/>
<snmpv3_authprotocol/>
<snmpv3_privprotocol/>
<logtimefmt/>
<formula>0</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Exim</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>Number of running processes $1</name>
<type>7</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>proc.num[exim4]</key>
<delay>180</delay>
<history>60</history>
<trends>365</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<snmpv3_contextname/>
<snmpv3_authprotocol/>
<snmpv3_privprotocol/>
<logtimefmt/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>Exim</name>
</application>
</applications>
<valuemap/>
</item>
</items>
<discovery_rules/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
<triggers>
<trigger>
<expression>{Template OS Linux - Exim Advanced:proc.num[exim4].last(0)}&lt;1</expression>
<name>Exim process is not running on {HOSTNAME}</name>
<url/>
<status>0</status>
<priority>4</priority>
<description>The number of running processes called 'exim4' is 0. This indicates that the Exim server is not working appropriately.</description>
<type>0</type>
<dependencies/>
</trigger>
<trigger>
<expression>{Template OS Linux - Exim Advanced:exmailqueue.last(0)}&gt;500</expression>
<name>More than 500 Mails in the Queue</name>
<url/>
<status>0</status>
<priority>2</priority>
<description/>
<type>0</type>
<dependencies/>
</trigger>
<trigger>
<expression>{Template OS Linux - Exim Advanced:exmailqueue.last(0)}&gt;1000</expression>
<name>More than 1000 Mails in the Queue</name>
<url/>
<status>0</status>
<priority>4</priority>
<description/>
<type>0</type>
<dependencies/>
</trigger>
<trigger>
<expression>{Template OS Linux - Exim Advanced:exdelivered.nodata(900)}=1 | {Template OS Linux - Exim Advanced:exbytesdelivered.nodata(900)}=1 | {Template OS Linux - Exim Advanced:exerrors.nodata(900)}=1 | {Template OS Linux - Exim Advanced:exmailqueue.nodata(900)}=1 | {Template OS Linux - Exim Advanced:exreceived.nodata(900)}=1 | {Template OS Linux - Exim Advanced:exbytesreceived.nodata(900)}=1</expression>
<name>No data received from {HOST.NAME} for 15 minutes</name>
<url/>
<status>0</status>
<priority>2</priority>
<description/>
<type>0</type>
<dependencies/>
</trigger>
</triggers>
<graphs>
<graph>
<name>Exim Errors</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>0</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>1</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>2</drawtype>
<color>009900</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template OS Linux - Exim Advanced</host>
<key>exerrors</key>
</item>
</graph_item>
</graph_items>
</graph>
<graph>
<name>Exim Statistics</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>0</show_work_period>
<show_triggers>0</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>1</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>2</drawtype>
<color>009900</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template OS Linux - Exim Advanced</host>
<key>exreceived</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>2</drawtype>
<color>0000EE</color>
<yaxisside>1</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template OS Linux - Exim Advanced</host>
<key>exdelivered</key>
</item>
</graph_item>
</graph_items>
</graph>
<graph>
<name>Exim Traffic Size</name>
<width>900</width>
<height>200</height>
<yaxismin>0.0000</yaxismin>
<yaxismax>100.0000</yaxismax>
<show_work_period>0</show_work_period>
<show_triggers>1</show_triggers>
<type>0</type>
<show_legend>1</show_legend>
<show_3d>0</show_3d>
<percent_left>0.0000</percent_left>
<percent_right>0.0000</percent_right>
<ymin_type_1>1</ymin_type_1>
<ymax_type_1>0</ymax_type_1>
<ymin_item_1>0</ymin_item_1>
<ymax_item_1>0</ymax_item_1>
<graph_items>
<graph_item>
<sortorder>0</sortorder>
<drawtype>2</drawtype>
<color>009900</color>
<yaxisside>0</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template OS Linux - Exim Advanced</host>
<key>exbytesreceived</key>
</item>
</graph_item>
<graph_item>
<sortorder>1</sortorder>
<drawtype>2</drawtype>
<color>0000DD</color>
<yaxisside>1</yaxisside>
<calc_fnc>2</calc_fnc>
<type>0</type>
<item>
<host>Template OS Linux - Exim Advanced</host>
<key>exbytesdelivered</key>
</item>
</graph_item>
</graph_items>
</graph>
</graphs>
</zabbix_export>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment