Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Zabbix 5 IT Infrastructure Monitoring Cookbook

You're reading from   Zabbix 5 IT Infrastructure Monitoring Cookbook Explore the new features of Zabbix 5 for designing, building, and maintaining your Zabbix setup

Arrow left icon
Product type Paperback
Published in Feb 2021
Publisher Packt
ISBN-13 9781800202238
Length 428 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Brian van Baekel Brian van Baekel
Author Profile Icon Brian van Baekel
Brian van Baekel
Nathan Liefting Nathan Liefting
Author Profile Icon Nathan Liefting
Nathan Liefting
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Chapter 1: Getting Started with Zabbix and User Management 2. Chapter 2: Setting Up Zabbix Monitoring FREE CHAPTER 3. Chapter 3: Working with Triggers and Alerts 4. Chapter 4: Building Your Own Structured Templates 5. Chapter 5: Visualizing Data, Inventory, and Reporting 6. Chapter 6: Using Discovery for Automatic Creation 7. Chapter 7: Setting Up Zabbix Proxies 8. Chapter 8: Integrating Zabbix with External Services 9. Chapter 9: Extending Zabbix Functionality with Custom Scripts and the Zabbix API 10. Chapter 10: Maintaining Your Zabbix Setup 11. Chapter 11: Advanced Zabbix Database Management 12. Chapter 12: Bringing Zabbix to the Cloud with Zabbix Cloud Integration 13. Other Books You May Enjoy

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.

You have been reading a chapter from
Zabbix 5 IT Infrastructure Monitoring Cookbook
Published in: Feb 2021
Publisher: Packt
ISBN-13: 9781800202238
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime