Skip to content

Instantly share code, notes, and snippets.

@zhum
Forked from crashdump/zbx-exim-stats.sh
Last active November 28, 2020 13:03
Show Gist options
  • Save zhum/fc93b0a2e53397a4a51ed8bf7e9bca5f to your computer and use it in GitHub Desktop.
Save zhum/fc93b0a2e53397a4a51ed8bf7e9bca5f to your computer and use it in GitHub Desktop.
A simple Zabbix statistics pusher for Zabbix-5. zbx-exim-stats.sh should be set to crontab, template should be imported.
#!/bin/bash
# Set Variables
EXIMLOG=/var/log/exim4/mainlog
MYLOG=/tmp/exim_status.log
OFFSETFILE=/tmp/eximstatusoffset.dat
EXIMSTATS="/usr/sbin/eximstats -emptyok"
LOGTAIL=/usr/sbin/logtail
ZABBIX_SENDER=/usr/bin/zabbix_sender
ZABBIX_CONF=/etc/zabbix/zabbix_agentd.conf
TMP1=$(mktemp)
TMP2=$(mktemp)
function zsend {
echo "$1 $2"
$ZABBIX_SENDER -c $ZABBIX_CONF -k $1 -o $2
}
$LOGTAIL -f $EXIMLOG -o $OFFSETFILE > $TMP1
$EXIMSTATS -t0 -nvr $TMP1 > $TMP2
echo "Errors 0 0" >> $TMP2
zsend exreceived `grep -m 1 Received $TMP2|awk '{print $3}'`
zsend exdelivered `grep -m 1 Delivered $TMP2|awk '{print $3}'`
zsend exerrors `grep -m 1 Errors $TMP2|awk '{print $3}'`
zsend exbytesreceived `grep -m 1 "Received" $TMP2|awk '{print $2}'`
zsend exbytesdelivered `grep -m 1 "Delivered" $TMP2|awk '{print $2}'`
zsend exmailqueue `mailq | grep -c "[a-A0-9]"`
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_privprotocol/>
<snmpv3_authprotocol/>
<snmpv3_contextname/>
<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_privprotocol/>
<snmpv3_authprotocol/>
<snmpv3_contextname/>
<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_privprotocol/>
<snmpv3_authprotocol/>
<snmpv3_contextname/>
<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_privprotocol/>
<snmpv3_authprotocol/>
<snmpv3_contextname/>
<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_privprotocol/>
<snmpv3_authprotocol/>
<snmpv3_contextname/>
<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_privprotocol/>
<snmpv3_authprotocol/>
<snmpv3_contextname/>
<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_privprotocol/>
<snmpv3_authprotocol/>
<snmpv3_contextname/>
<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