Book Image

Zabbix 5 IT Infrastructure Monitoring Cookbook

By : Nathan Liefting, Brian van Baekel
Book Image

Zabbix 5 IT Infrastructure Monitoring Cookbook

By: Nathan Liefting, Brian van Baekel

Overview of this book

Zabbix offers useful insights into your infrastructure performance and issues and enables you to enhance your monitoring setup with its variety of powerful features. This book covers hands-on, easy-to-follow recipes for using Zabbix 5 for effectively monitoring the performance of devices and applications over networks. The book starts by guiding you through the installation of Zabbix and using the Zabbix frontend. You'll then work your way through the most prominent features of Zabbix and make the right design choices for building a scalable and easily manageable environment. The book contains recipes for building items and triggers for different types of monitoring, building templates, and using Zabbix proxies. As you advance, you’ll learn how to use the Zabbix API for customization and manage your Zabbix server and database efficiently. Finally, you'll find quick solutions to the common and not-so-common problems that you may encounter in your everyday Zabbix monitoring work. By the end of this Zabbix book, you’ll have learned how to use Zabbix for all your monitoring needs and be able to build a solid Zabbix setup by leveraging its key functionalities.
Table of Contents (14 chapters)

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:

  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

    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.

    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:

    Figure 2.18 – Zabbix item port 22 check configuration page for host lar-book-agent_simple

    Figure 2.18 – Zabbix item port 22 check configuration page for host lar-book-agent_simple

    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.

  4. 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:
Figure 2.19 – Zabbix Latest data page for host lar-book-agent_simple, item port 22 check

Figure 2.19 – Zabbix Latest data page for host lar-book-agent_simple, item port 22 check

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:

  1. 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:

    Figure 2.20 – Zabbix item trap receiver configuration screen for host lar-book-agent_simple

    Figure 2.20 – Zabbix item trap receiver configuration screen for host lar-book-agent_simple

  2. If we go to the CLI of our monitored server, we can now execute the following to install Zabbix sender:
    dnf install zabbix-sender
  3. 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.

  4. Navigate to Monitoring | Hosts and check the Latest data screen for our new value:
Figure 2.21 – Zabbix Latest data page for host lar-book-agent_simple, item trap receiver

Figure 2.21 – Zabbix Latest data page for host lar-book-agent_simple, item trap receiver

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:

Figure 2.22 – Zabbix server-to-host communication diagram

Figure 2.22 – Zabbix server-to-host communication diagram

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:

Figure 2.23 – Zabbix server trap receiver diagram

Figure 2.23 – Zabbix server trap receiver diagram

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.