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…
- First let's create a script that we will execute in
/usr/lib/zabbix/externalscripts/
calledtest_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.
- 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:
- 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:
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:
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.