External checks

Just when you thought things couldn't get any better, you notice that Zabbix has support for external checks. This means that Zabbix will run a script or a binary from a specific location, without the need of any agent running on the host that we want to monitor.

Getting ready

For this setup, we need our Zabbix server with a host that can be reached by the Zabbix server. There is no need to install a Zabbix agent on the host as we will make use of our own scripts to run some checks.

How to do it …

  1. Creating external checks is very easy in Zabbix. First thing we need to verify is where to put them on our Zabbix server. This can be done by looking in the configuration file of the Zabbix server in the zabbix_server.conf file. Here we see the option ExternalScripts where we can specify the location or use the standard one:
    ExternalScripts=/usr/lib/zabbix/externalscripts
  2. In this location, we will place our script. For example we could check the number of cores available on our host. So let's create a script cores.sh with the following content:
    #!/bin/bash
    nproc
  3. Next step is to make our script executable; this can be done by the command:
    chmod +x
  4. Next we need to make it accessible by our Zabbix server. Remember Zabbix runs as user zabbix and group zabbix so we need to change the user and the group.
    chown zabbix:zabbix cores.sh
  5. Next step is to create our item for the host that we want to check.
  6. For the Name, we put something that links us with the item we want to monitor such as Number of CPU Cores.
  7. Then we select for Type, External check.
  8. The Key is the name of our script; in our case cores.sh[].
  9. The values that we get back is numeric and decimal so Type of information and Data type can be left as is, together with all other options.
    How to do it …

How it works

This example was pretty easy, but it should give you an idea of the possibilities of external checks. It's important that our scripts are placed in the correct directory as defined in our zabbix_server.conf file and that the script has the correct rights, so that Zabbix can read and execute the script.

Next step is to create an item in Zabbix and select the Type, External check and add a key with the exact same name as our script.

There's more...

It is important to remember that external checks cannot take too much time to run. If a script takes more than 5 seconds, Zabbix will then mark the item as unsupported.

If your scripts needs input such as a variable then you can pass this variable in your item key between the []. For example, myscript.sh["var1","var2",...].

It is also possible to make use of macros. For example, running a script that sends the IP address with some variable could be done easily like this:

myscript.sh["{HOST.IP}","var1"]

Tip

If you monitor your host from a proxy, then you need to make sure that the script is on the proxy that the host monitors. In that case, it will be the proxy running the script.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.255.139