Extending agents

Now that you know how to install and configure a Zabbix agent, let's go a bit deeper into the monitoring aspect of the agent. A monitoring system would quickly reach its limits if we don't expand it with our own checks. Many companies require specific checks that are not available as item on our agent. There are a few ways to extend Zabbix, one solution is to work with user parameters. We will see how to extend our agent to monitor beyond the limits of Zabbix.

Getting ready

We need a Zabbix server and a Zabbix agent properly configured. The easiest way is probably by making use of the Zabbix agent that is installed on your Zabbix server.

How to do it …

  1. First thing we can do is extend our agent with user parameters. This must be done in the zabbix_agentd.conf file.
  2. Extend the agent with the UserParameter option such as in this example:
    UserParameter=mysql.threads,mysqladmin -u root -p<password> status|cut -f3 -d":"|cut -f1 -d"Q"
  3. This will return the number of MySQL threads to item mysql.threads (-p is only needed if you have configured a MySQL root password).
  4. Restart the Zabbix agent after you have saved the configuration file.
  5. In our Zabbix server create a new item on the host where we have added the UserParameter option.
  6. Add a new Name, example Mysql threads.
  7. Select Type; this can be Zabbix agent or Zabbix agent (active).
  8. Create a new item Key named mysql.threads.
  9. Select as Type of information Numeric (unsigned).
  10. For Data type we select Decimal.
  11. All other settings can be left as is.
  12. Go to latest data page Monitoring | Latest data and after some time, your item Mysql Threads will be populated with a number.
    How to do it …

How it works

The UserParameter option that we put in the agent config file has the following syntax:

UserParameter=<key>,<command>

As you can see is the first option, a key; the key is necessary when configuring an item. You can enter a key here of your own choice, but the key must be unique for each host.

Later when we configure our item in Zabbix, we make use of the same key for our item Key. We can make use of points and or underscores but no spaces or other special characters.

Behind our key we put a , followed with a command. This command is the command that's going to be executed by the Zabbix agent. In this example, we used a MySQL command. Of course, Zabbix is not limited to MySQL alone. We could check for example, some parameters from our OS.

There's more...

You can also pass options to the UserParameter via the Zabbix server.

UserParameter = some.key[*],somescript.sh $1 $2

The [*] in our key will make it possible for us to determine an unlimited number of items starting with some.key parameter when we create our item in the Zabbix server:

some.key[1] , some.key[2]

The value in our Key will then be passed in our script as $1, $2, and so on.

To make things more understandable, let's have a look at how we can improve our example mysql.threads.

UserParameter=mysql.threads[*],mysqladmin -u$1 -p$2 status|cut -f3 -d":"|cut -f1 -d"Q"

If we now add in Zabbix a item with key mysql.threads[root,password] then $1 will be root and $2 will be our password.

Remember that the Zabbix agent will run all UserParameter as the user you configured Zabbix to run as. Normally this will be the user zabbix. Sometimes the command you want to execute needs root privileges. To ensure that the Zabbix agent is allowed to execute such programs you can make use of the sudo command. Add the appropriate program in the /etc/sudoers file with visudo.

Zabbix ALL = (ALL) NOPASSWD: /usr/bin/someprogram

Also, make sure that you comment the rule Defaults requiretty. Else you will get error messages in the log file telling you that you are required to have a tty.

Simple checks

In this topic, we will explain you the use of simple checks in Zabbix. Simple checks are checks that can be run from the Zabbix server without the need of a Zabbix agent on the host.

Getting ready

For simple checks, we need a Zabbix server properly configured with super administrator rights. We don't need a Zabbix agent for this setup. What we do need is a host where we can test our simple check. This can be any device as long as it is reachable on the network by our Zabbix server.

How to do it …

  1. On the Zabbix host that we want to check we create a new item. Go to Configuration | Hosts | Item | Create item (Remember normally in production we create items in templates but for our test a local item if just fine).
  2. First thing to do in our item is put a visible Name for our item.
  3. The we select the item Type. In our case this will be Simple check.
  4. Next thing we do is replace the options in our Key in my case I removed the first option target so the Host Interface selected will be used. If you don't want to use the options then you can just put the , and not fill in the option such as <target>, <packet> and so on.
  5. <target> : Host IP address or DNS name.
  6. <packets> : Number of packets (default is 3, min is 1).
  7. <interval> : Time between successive packets in milliseconds (default is 1000 ms, min is 20 ms).
  8. <size> : packet size in bytes (default is 56 bytes on x86, 68 bytes on x86_64, min is 24 bytes).
  9. <timeout> : timeout in ms (default is 500 ms, min is 50 ms).
  10. Then with the Select button we select a Key for our item from the list of standard available keys. In this example I will make use of the icmpping item.
  11. User name and Password are only used in simple checks for VMware monitoring.
  12. Next we select the Type of information. This will be Numeric (unsigned) as we have selected icmpping as key we will only get a value back of 0 or 1.
  13. Data type in our case will be Decimal.
  14. All other values should be fine as they are:
    How to do it …

How it works

Zabbix simple checks, checks by ICMP ping or by port scan if a host is online and whether the service accepts connections. There is no need for a Zabbix agent to use this method of checking. The Zabbix server is 100 percent responsible for the complete process. The return values of the simple checks are either 1 or 0 (numerically unsigned) when we check the availability of a host or port. When we do performance checks the value returned will be measured in seconds (numeric (float)). When this check fails, a value of 0 will be returned.

There's more...

Zabbix relies on fping and fping6 for the icmppingsec, icmpping and icmppingloss checks. Make sure that fping6 is available and the proper SUID permissions are set.

# which fping (this command will there us where the location of fping is)
/sbin/fping
# ll /sbin/fping
-rwsr-xr-x. 1 root root 32960 Oct 26 11:40 /sbin/fping

(Make sure that permissions for user are set to rws as in this example).

As fping is a third party tool Zabbix relies on, there can be some issue. Depending on your distribution, another version of fping with different options can be installed. With fping3, this issue should be resolved. Users of RHEL 6.x and 7.x or derivatives can be sure that the correct version comes with their distribution.

Tip

It's possible to use Zabbix with ping instead of fping, however fping is more efficient and can ping several hosts simultaneously. So it's better to stay with fping. If fping always returns 0 as value to Zabbix, please check SELinux. (https://www.zabbix.com/forum/showthread.php?t=40523).

See also

Zabbix supports more than just the icmpping item. For a full list with all options in detail, take a look at the Zabbix documentation.

If you make use of IPv6 then you need to have fping6 installed on your system.

https://www.zabbix.com/documentation/2.4/manual/config/items/itemtypes/simple_checks.

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

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