Zabbix, Sendmail and mailq

So Zabbix has a “Template Linux Server”, but it (and any other template) does not give us the option to track the value of a Sendmail mailq on our mail server.
So how to do this?

Necessary starting conditions
Host machine (mail server) MUST have a functioning Zabbix agent.
Zabbix server must “see” Zabbix agent on our mail server (letter “Z” is green for this host).

What should be done on mail server
a. Zabbix account (also named zabbix) must be given root privileges for mailq command (it will not work otherwise). So in file /etc/sudoers we add lines :
Defaults:zabbix !requiretty
zabbix ALL=NOPASSWD:/usr/bin/mailq
b. In folder /etc/zabbix we make a script which gives number of mails in a mailq as a output value :
-rwxr-xr-x 1 zabbix zabbix 154 Sep 15 12:57 mejlkju
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
mejlkju=`sudo mailq | tail -n1 | awk ‘{print $3}’`
echo $mejlkju
c. In Zabbix agent configuration file /etc/zabbix_agentd.conf we add :
Agent MUST be restarted :
# zabbix-agent restart
d. Also change a home directory and shell for zabbix user account in /etc/passwd :
zabbix:x:492:488:Zabbix Monitoring System:/etc/zabbix:/bin/bash
Test your script :
# su – zabbix
-bash-4.1$ ./mejlkju

What should be done on Zabbix server
Make a new “Item” under your mail server.
This Item should have the following characteristics :
Name – sendmail.mailq
Key – sendmail.mailq
Type – zabbix agent
Type of information – numeric (unsigned)

On host (mail) server look in /var/log/zabbix/zabbix_agent.log
On Zabbix server look on – Monitoring/Latest data/search using phrase “sendmailmailq”

A quite useful link.

This entry was posted in Linux and tagged , , . Bookmark the permalink.

Comments are closed.