Monitoring Postfix in Zabbix

First, configure the Zabbix agent.

Create a file (in the nano editor, press Ctrl+X to exit, and y/n to save or discard changes):

nano /etc/zabbix/zabbix_agentd.d/userparameter_postfix.conf

Add to it:

UserParameter=postfix.maildrop, find /var/spool/postfix/maildrop -type f | wc -l
UserParameter=postfix.deferred, find /var/spool/postfix/deferred -type f | wc -l
UserParameter=postfix.incoming, find /var/spool/postfix/incoming -type f | wc -l
UserParameter=postfix.active, find /var/spool/postfix/active -type f | wc -l
UserParameter=postfix.queue, mailq | grep -v "Mail queue is empty" | grep -c '^[0-9A-Z]'

Alternatively, you can simply add the lines above to the Zabbix agent configuration file.

Also open the Zabbix agent configuration file:

nano /etc/zabbix/zabbix_agentd.conf

We will allow Zabbix agent to work as root with the user specifying:

AllowRoot=1

Restart the Zabbix agent to apply the changes:

sudo /etc/init.d/zabbix-agent restart

Now go to the Zabbix server.
Create a Postfix template, add data items to it, specifying the type – Zabbix agent, and the keys: postfix.maildrop, postfix.deferred, postfix.incoming, postfix.active, postfix.queue.
Create graphics for the created data items.

You can also create a data item that counts the number of Postfix processes by specifying the type – Zabbix agent, and the key:

proc.num[,postfix]

Also create a trigger that tells when processes 0.

Download the ready template here – Zabbix шаблон для Postfix

Join the Conversation

4 Comments

Leave a Reply

  1. By the way, I add one monitor group and use the SGID on /var/spool/postfix/xxx via Ansible playbook, not enable the `AllowRoot=1` args of zabbix-agent.

    “`

    TASK [zabbix-agent.ansible.role : Add monitor group.] *****************************************
    ok: [postfix01]

    TASK [zabbix-agent.ansible.role : Append monitor group to zabbix user.] ***********************
    ok: [postfix01]

    TASK [zabbix-agent.ansible.role : Modify files permission for Postfix monitoring.] ************
    — before
    +++ after
    @@ -1,5 +1,5 @@
    {
    – “group”: 90,
    – “mode”: “0730”,
    + “group”: 1000,
    + “mode”: “02750”,
    “path”: “/var/spool/postfix/maildrop”
    }

    changed: [postfix01] => (item={u’path’: u’/var/spool/postfix/maildrop’, u’state’: u’directory’, u’mode’: u’2750′})
    — before
    +++ after
    @@ -1,5 +1,5 @@
    {
    – “group”: 0,
    – “mode”: “0700”,
    + “group”: 1000,
    + “mode”: “02750”,
    “path”: “/var/spool/postfix/deferred”
    }

    changed: [postfix01] => (item={u’path’: u’/var/spool/postfix/deferred’, u’state’: u’directory’, u’mode’: u’2750′})
    — before
    +++ after
    @@ -1,5 +1,5 @@
    {
    – “group”: 0,
    – “mode”: “0700”,
    + “group”: 1000,
    + “mode”: “02750”,
    “path”: “/var/spool/postfix/incoming”
    }

    changed: [postfix01] => (item={u’path’: u’/var/spool/postfix/incoming’, u’state’: u’directory’, u’mode’: u’2750′})
    — before
    +++ after
    @@ -1,5 +1,5 @@
    {
    – “group”: 0,
    – “mode”: “0700”,
    + “group”: 1000,
    + “mode”: “02750”,
    “path”: “/var/spool/postfix/active”
    }

    changed: [postfix01] => (item={u’path’: u’/var/spool/postfix/active’, u’state’: u’directory’, u’mode’: u’2750′})
    ok: [postfix01] => (item={u’path’: u’/var/spool/postfix/maildrop’, u’recurse’: u’yes’, u’mode’: u’g+r’})
    changed: [postfix01] => (item={u’path’: u’/var/spool/postfix/deferred’, u’recurse’: u’yes’, u’mode’: u’g+r’})
    ok: [postfix01] => (item={u’path’: u’/var/spool/postfix/incoming’, u’recurse’: u’yes’, u’mode’: u’g+r’})
    ok: [postfix01] => (item={u’path’: u’/var/spool/postfix/active’, u’recurse’: u’yes’, u’mode’: u’g+r’})

    “`

  2. Thanks for sharing this information, I will provisioning this configuration in each Postfix servers of company. ?

  3. greetings,

    using your template.

    I am getting data values only from:

    Postfix processes
    Postfix mail queue

    on the rest i receive: Status not supported

    Postfix maildrop queue
    Postfix incoming queue
    Postfix deferred queue
    Postfix active queue

    Value “find: ‘/var/spool/postfix/incoming’: Permission denied
    0” of type “string” is not suitable for value type “Numeric (unsigned)”

    I assume i need give permissions isnt?

    thanks heaps,

    Kpax

    1. Hi,
      You need to actually make your zabbix-agent run as root user, sometimes is enough with the AllowRoot paremeter mentioned in the post, sometimes you need to modify the init.d service or the systemd unit for zabbix-agent