||||||||||||||||||||
48 Setting Up Zabbix Monitoring
2. Now let's edit the following value to change this host to an active agent:
ServerActive=127.0.0.1
3. Change ServerActive to the IP of the Zabbix server that will monitor this
passive agent and also change Hostname to lar-book-agent:
Hostname=lar-book-agent
4. Now restart the Zabbix agent 2 process:
systemctl restart zabbix-agent2.service
5. Now move to the frontend of your Zabbix server and let's add another host with a
template to do active checks instead of passive ones.
6. First, let's rename our passive host. To do that, go to Configuration | Hosts in your
Zabbix frontend and click the host we just created. Change Host name as follows:
Figure 2.5 – The Zabbix host configuration page for host lar-book-agent_passive
We are doing this because for an active Zabbix agent, the hostname in the file needs
to match our Zabbix server.
7. Go to Configuration | Hosts in your Zabbix frontend and click Create host in the
top-right corner.
||||||||||||||||||||
||||||||||||||||||||
Setting up Zabbix agent 2 monitoring 49
8. Now let's create the host as follows:
Figure 2.6 – The Zabbix host configuration page for host lar-book-agent
9. Also, make sure to add the correct template, named Template OS Linux by
Zabbix agent active:
Figure 2.7 – The Zabbix host template page for host lar-book-agent
Please note that the ZBX icon won't turn green for an active agent. But when we navigate
to Monitoring | Hosts and check Latest data, we can see our active data coming in.
Technet24
||||||||||||||||||||
||||||||||||||||||||
50 Setting Up Zabbix Monitoring
Tip
As you might have noticed just now, a Zabbix agent can run in both passive
and active mode. Keep this in mind when creating your Zabbix agent
templates, as you might want to combine the check types.
How it works…
Now that we have configured our Zabbix agents and know how they should be set up,
let's see how the different modes work.
Passive agent
The passive agent works by collecting data from our host with the Zabbix agent. Every
time an item on our host reaches its interval, the Zabbix server asks the Zabbix agent what
the value is now:
Figure 2.8 – Communication diagram between server and passive agent
Active agent
The active agent works by sending data from the Zabbix agent to Zabbix server. Every
time an item on our agent reaches its interval, the agent will send the value to our server.
We can also use this to send a notification to our server faster when something goes
wrong:
Figure 2.9 – Communication diagram between server and active agent
||||||||||||||||||||
||||||||||||||||||||
Working with SNMP monitoring 51
As mentioned, we can use both types of checks at the same time, giving us the freedom to
configure every type of check we could possibly need. Our setup would then look like this:
Figure 2.10 – Communication diagram between server and both agent types
See also
There's a lot of new stuff going on under the hood of Zabbix agent 2; if you're interested
in learning more about the core of Zabbix agent 2, check out this cool blog post by Alexey
Petrov: https://blog.zabbix.com/magic-of-new-zabbix-agent/8460/.
Working with SNMP monitoring
Now let's do something I enjoy most when working with Zabbix: build SNMP monitoring.
My professional roots lie in network engineering, and I have worked a lot with SNMP
monitoring to monitor all these different network devices.
Getting ready
To get started, we need the two Linux hosts we used before in the previous recipes:
• Our Zabbix server host
• The host we used in the previous recipe to monitor via the Zabbix active agent
Technet24
||||||||||||||||||||
||||||||||||||||||||
52 Setting Up Zabbix Monitoring
How to do it…
Monitoring via SNMP polling is easy and very powerful. We will start by configuring
SNMPv3 on our monitored Linux host:
1. Let's start by issuing the following commands to install SNMP on our host:
For RHEL-based systems:
dnf install net-snmp net-snmp-utils
systemctl stop snmpd
For Debian-based systems:
apt-get install net-snmp net-snmp-utils
systemctl stop snmpd
2. Now let's create the new SNMPv3 user we will use to monitor our host. Please note
that we'll be using insecure passwords, but make sure to use secure passwords for
your production environments. Issue the following command:
net-snmp-create-v3-user -ro -A my_authpass -X my_privpass
-a SHA -x AES snmpv3user
This will create an SNMPv3 user with the username snmpv3user, the
authentication password my_authpass, and the privilege password my_
privpass.
3. Now restart the snmpd daemon and enable it at boot:
systemctl restart snmpd.service
systemctl enable snmpd.service
This is all we need to do on the Linux host side; we can now go to the Zabbix
frontend to configure our host. Go to Configuration | Hosts in your Zabbix
frontend and click Create host in the top-right corner.
||||||||||||||||||||
||||||||||||||||||||
Working with SNMP monitoring 53
4. Now fill in the host configuration page:
Figure 2.11 – Zabbix host configuration page for host lar-book-agent_snmp
5. Make sure to add the right out-of-the-box template as shown in the following
screenshot:
Figure 2.12 – Zabbix host template page for host lar-book-agent_snmp
Technet24
||||||||||||||||||||
||||||||||||||||||||
54 Setting Up Zabbix Monitoring
Tip
While upgrading from an earlier Zabbix version to Zabbix 5, you won't get
all the new out-of-the-box templates. If you feel like you are missing some
templates, you can download them at the Zabbix Git repository: https://
git.zabbix.com/projects/ZBX/repos/zabbix/browse/
templates.
6. We are using some macros in our configuration here for the username and
password. We can use these macros to actually add a bunch of hosts with the same
credentials. This is very useful, for instance, if you have a bunch of switches with the
same SNMPv3 credentials.
Let's fill in the macros under Administration | General and use the dropdown to
select Macros. Fill in the macros like this:
Figure 2.13 – Zabbix global macro page with SNMP macros
A cool new feature in Zabbix 5 is the ability to hide macros in the frontend; do keep
in mind that these values are still unencrypted in the Zabbix database.
7. Use the dropdown to change {$SNMPv3_AUTH} and {$SNMPv3_PRIV} to
Secret text:
Figure 2.14 – Zabbix secure text dropdown for SNMP auth and priv macros
||||||||||||||||||||
||||||||||||||||||||
Working with SNMP monitoring 55
8. Now after applying these changes, we should be able to monitor our Linux server
via SNMPv3. Let's go to Monitoring | Hosts and check the Latest data page for our
new host:
Figure 2.15 – SNMP latest data for host lar-book-agent_snmp
How it works…
When we create a host as we did in step 4, Zabbix polls the host using SNMP. Polling
SNMP like this works with SNMP OIDs. For instance, when we poll the item called Free
memory, we ask the SNMP agent running on our Linux host to show us the value for
1.3.6.1.4.1.2021.4.6.0. That value is then returned to us on the Zabbix server:
Figure 2.16 – Diagram showing communication between Zabbix server and SNMP host
Of course, SNMPv3 adds authentication and encryption to this process.
SNMP OIDs work in a tree structure, meaning every number behind the dot can contain
another value. For example, see this for our host:
1.3.6.1.4.1.2021.4 = UCD-SNMP-MIB::memory
Technet24
||||||||||||||||||||
||||||||||||||||||||
56 Setting Up Zabbix Monitoring
If we poll that Define acronym, we get several OIDs back:
.1.3.6.1.4.1.2021.4.1.0 = INTEGER: 0
.1.3.6.1.4.1.2021.4.2.0 = STRING: swap
.1.3.6.1.4.1.2021.4.3.0 = INTEGER: 1679356 kB
.1.3.6.1.4.1.2021.4.4.0 = INTEGER: 1674464 kB
.1.3.6.1.4.1.2021.4.5.0 = INTEGER: 1872872 kB
.1.3.6.1.4.1.2021.4.6.0 = INTEGER: 184068 kB
That includes our 1.3.6.1.4.1.2021.4.6.0 OID with the value that contains our
free memory. This is how SNMP is built, like a tree.
Creating Zabbix simple checks and the Zabbix
trapper
In this recipe, we will go over two checks that can help you built some more customized
setups. The Zabbix simple checks provide you with an easy way to monitor some specific
data. The Zabbix trapper combines with Zabbix sender to get data from your hosts into
the server, allowing for some scripting options. Let's get started.
Getting ready
To create these checks, we will need a Zabbix server and a Linux host to monitor. We can
use the host with a Zabbix agent and SNMP monitoring from the previous recipes.
Do note for these checks that we do not actually need the Zabbix agent.
How to do it…
Working with simple checks is quite simple, as the name suggests, so let's start.
||||||||||||||||||||
||||||||||||||||||||
Creating Zabbix simple checks and the Zabbix trapper 57
Creating simple checks
We will create a simple check to monitor whether a service is running and accepting TCP
connections on a certain port:
1. To get this done, we will need to create a new host in Zabbix frontend. Go to
Configuration | Hosts in your Zabbix frontend and click Create host in the
top-right corner.
2. Create a host with the following settings:
Figure 2.17 – Zabbix host configuration page for host lar-book-agent_simple
3. Now go to Configuration | Hosts, click the newly created host, and go to Items. We
want to create a new item here by clicking the Create item button.
Technet24
||||||||||||||||||||