In this post, I’ll go over how to set up Zabbix for a SMTP mail server. I assume you have already followed my previous post and have a running Zabbix server.
Preparation
To install the Zabbix agent on a Ubuntu based system, you need to follow step 2.a. from their download instructions. That is, execute
wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb
dpkg -i zabbix-release_5.0-1+focal_all.deb
apt update
on the mail server.
root@smtp:~# wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb --2021-03-04 19:40:15-- https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb Resolving repo.zabbix.com (repo.zabbix.com)… 2604:a880:2:d0::2062:d001, 178.128.6.101 Connecting to repo.zabbix.com (repo.zabbix.com)|2604:a880:2:d0::2062:d001|:443… connected. HTTP request sent, awaiting response… 200 OK Length: 4244 (4.1K) [application/octet-stream] Saving to: 'zabbix-release_5.0-1+focal_all.deb' zabbix-release_5.0-1+focal_al 100%[=================================================>] 4.14K --.-KB/s in 0s 2021-03-04 19:40:16 (429 MB/s) - 'zabbix-release_5.0-1+focal_all.deb' saved [4244/4244] root@smtp:~# dpkg -i zabbix-release_5.0-1+focal_all.deb Selecting previously unselected package zabbix-release. (Reading database … 38747 files and directories currently installed.) Preparing to unpack zabbix-release_5.0-1+focal_all.deb … Unpacking zabbix-release (1:5.0-1+focal) … Setting up zabbix-release (1:5.0-1+focal) … root@smtp:~# apt update Get:1 http://repo.zabbix.com/zabbix/5.0/ubuntu focal InRelease [4930 B] Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease Hit:3 https://packages.inverse.ca/SOGo/nightly/5/ubuntu focal InRelease Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:5 http://repo.zabbix.com/zabbix/5.0/ubuntu focal/main Sources [1193 B] Get:6 http://archive.ubuntu.com/ubuntu focal-security InRelease [109 kB] Get:7 http://repo.zabbix.com/zabbix/5.0/ubuntu focal/main amd64 Packages [3226 B] Get:8 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [841 kB] Get:9 http://archive.ubuntu.com/ubuntu focal-updates/main Translation-en [201 kB] Get:10 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [12.8 kB] Get:11 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [747 kB] Get:12 http://archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [155 kB] Fetched 2189 kB in 2s (1014 kB/s) Reading package lists… Done Building dependency tree Reading state information… Done
Install Packages
Now you can install the agent itself:
root@smtp:~# apt install zabbix-agent Reading package lists… Done Building dependency tree Reading state information… Done The following NEW packages will be installed: zabbix-agent 0 upgraded, 1 newly installed, 0 to remove and 16 not upgraded. Need to get 201 kB of archives. After this operation, 806 kB of additional disk space will be used. Get:1 http://repo.zabbix.com/zabbix/5.0/ubuntu focal/main amd64 zabbix-agent amd64 1:5.0.9-1+focal [201 kB] Fetched 201 kB in 0s (524 kB/s) Selecting previously unselected package zabbix-agent. (Reading database … 38753 files and directories currently installed.) Preparing to unpack …/zabbix-agent_1%3a5.0.9-1+focal_amd64.deb … Unpacking zabbix-agent (1:5.0.9-1+focal) … Setting up zabbix-agent (1:5.0.9-1+focal) … Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service -> /lib/systemd/system/zabbix-agent.service. Processing triggers for man-db (2.9.1-1) … Processing triggers for systemd (245.4-4ubuntu3.4) …
The agent is now installed, and must be configured. Being a mail server, it is accessible from the internet, so we do not need to deviate from default settings too much. You will need to make sure that whatever firewall you use has port 10050 open or forwarded via NAT as necessary to the server. You could also use a Zabbix proxy server on your firewall if you have more than one machine that must talk behind that firewall, but I won’t cover that in this post.
Configuration
In /etc/zabbix/zabbix_agentd.conf; find and modify the following lines as appropriate for your server:
ServerActive=zabbix.example.ca #Zabbix server to connect to Server=zabbix.example.ca #Zabbix server to allow connections from Hostname=smtp.example.ca #name of the machine to be monitored
You will also want to use TLS encryption when using Zabbix over the internet. Generate a pre-shared key, similar to what you use when setting up a home WiFi network:
sh -c "openssl rand -hex 32 > /etc/zabbix/zabbix_agentd.psk"
and remember the value of that key. For example,
405c8307fb55d3ccf77753a5cd19fd47d9ed254b366800e05637b02501b243b8
Open /etc/zabbix/zabbix_agentd.conf again and modify the following lines:
TLSAccept=psk TLSConnect=psk TLSPSKIdentity=SMTP Key TLSPSKFile=/etc/zabbix/zabbix_agentd.psk
Access your Zabbix server and add the host (Configuration → Hosts → Create Host). Set the hostname as you did in /etc/zabbix/zabbix_agentd.conf and assign it a group, such as Linux Servers.

Also critical is using a template to have Zabbix actually monitor something. In this example we’ll use the template Template OS Linux by Zabbix agent.

Lastly, you need to configure the encryption on this side too. Use the same settings as with the agent; you need the preshared key you selected earlier, along with the PSK identity:

Click add, and you should be done! Now just restart the zabbix agent on the mail server to get your settings working…
systemctl restart zabbix-agent
You can check in Monitoring → Latest Data and filter by Hosts to see if the Zabbix server is receiving data from the agent.