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 external checks

To further extend Zabbix functionality, we can use our own custom scripts, which are used by Zabbix external checks. Not everything that you want to monitor will always be standard in Zabbix, though a lot is. There's always something that could be missing, and external checks are just the way to bypass some of these.

Getting ready

For this recipe, we are going to need just our Zabbix server. We can create an item on our lar-book-centos host, which is our Zabbix server monitored host.

How to do it…

  1. First let's create a script that we will execute in /usr/lib/zabbix/externalscripts/ called test_external with the following command:
    vim /usr/lib/zabbix/externalscripts/test_external

    Add the following code to this file and save:

    #!/bin/bash
    echo $1

    Tip

    Make sure Zabbix server can execute the script by adding the right permissions to the file. The zabbix user on your Linux server needs to be able to access and execute the file.

  2. Let's navigate to our host to create a new item. Navigate to Configuration | Hosts, select our host, lar-book-centos, and click the Create item button. We want this item to get the following variables:
    Figure 2.33 – Zabbix item configuration page

    Figure 2.33 – Zabbix item configuration page

  3. After adding this new item, let's navigate to Monitoring | Hosts and check the Latest data page for our host. We should get our Test variable returned by our script as Value in Zabbix, as shown in the following screenshot:
Figure 2.34 – Zabbix Latest data page

Figure 2.34 – Zabbix Latest data page

Tip

Use the macros in the frontend as variables to send data from your frontend to your scripts. You can further automate your checks with this to enhance your external checks.

How it works…

External checks seem like they have a steep learning curve, but they are actually quite simple from the Zabbix side. All we do is send a command to an external script and expect a result output:

Figure 2.35 – Zabbix server external script communication diagram

Figure 2.35 – Zabbix server external script communication diagram

Like in our example, we sent the value Test to our script, which the script then in turn echoed back to use as $1.

When you have good knowledge of a programming language such as Python, for example, we can use this function to build a lot more expansion to our Zabbix capabilities. A simple yet powerful tool to work with.