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 simple checks
We will create a simple check to monitor whether a service is running and accepting TCP connections on a certain port:
- 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.
- Create a host with the following settings:
- 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.
We will create a new item with the following values, and after doing, so we will click the Add button at the bottom of the page:
Important note
We are adding the item key net.tcp.services[SSH,22] here. The port in this case is optional, as we can specify the service SSH with a different port if we would want to.
- Now we should be able to see whether our server is accepting SSH connections on port
22
on our Latest data screen. Navigate to Monitoring | Hosts and check the Latest data screen for our new value:
That's all there is to creating your simple checks in Zabbix. Now let's move on to the Zabbix trapper item.
Creating a trapper
We can do some cool stuff with Zabbix trapper items once we get more advanced setups. But for now, let's create an item on our lar-book-agent_simple host:
- Go to Configuration | Hosts and click the host, then go to Items. We want to create a new item here again by clicking the Create item button.
Now let's create the following item and click the Add button:
- If we go to the CLI of our monitored server, we can now execute the following to install Zabbix sender:
dnf install zabbix-sender
- After installation, we can use Zabbix sender to send some information to our server:
zabbix_sender -z 10.16.16.152 -p 10051 -s "lar-book-agent_simple" -k trap -o "Let's test this book trapper"
Now we should be able to see whether our monitored host has sent out the Zabbix trap and the Zabbix server has received this trap for processing.
- Navigate to Monitoring | Hosts and check the Latest data screen for our new value:
There it is, our Zabbix trap in our Zabbix frontend.
How it works…
Now that we have built our new items, let's see how they work by diving into the theoretical side of Zabbix simple checks and trappers.
Simple checks
Zabbix simple checks are basically a list of built-in checks made for monitoring certain values. There is a list and description available on the Zabbix documentation wiki: https://www.zabbix.com/documentation/current/manual/config/items/itemtypes/simple_checks.
All of these checks are performed by the Zabbix server to collect data from a monitored host. For example, when we do the Zabbix simple check to check whether a port is open, our Zabbix server requests simply checks whether it can reach that port.
This means that if your monitored host's firewall is blocking port 22
from Zabbix server, we'll get a service is down value. However, this does not mean that SSH isn't running on the server itself:
Tip
Keep in mind that working with simple checks is dependent on external factors such as the firewall settings on the monitored host. When you build a custom simple check, make sure to check these factors as well.
Trappers
When working with Zabbix sender, we are doing exactly the opposite of most checks. We are building an item on our Zabbix server, which allows us to capture trap items. This allows us to build some custom checks to send data to our Zabbix server from a monitored host:
Let's say, for instance, that you want to build a custom Python script that, at the end of running the scripts, sends output to Zabbix server. We could ask Python to send this data with Zabbix sender, and suddenly you'd have this data available for processing on the Zabbix server.
We can really extend our options with Zabbix trapper and customize our Zabbix server even further.