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.
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.
zabbix_agentd.conf
file.UserParameter
option such as in this example:UserParameter=mysql.threads,mysqladmin -u root -p<password> status|cut -f3 -d":"|cut -f1 -d"Q"
mysql.threads
(-p
is only needed if you have configured a MySQL root
password).UserParameter
option.Mysql threads
.Zabbix agent or Zabbix agent (active)
.mysql.threads
.Numeric (unsigned)
.Decimal
.Mysql Threads
will be populated with a number.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.
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
.
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.
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.
Simple check
.<target>
, <packet>
and so on.<target>
: Host IP address or DNS name.<packets>
: Number of packets (default is 3, min is 1).<interval>
: Time between successive packets in milliseconds (default is 1000 ms, min is 20 ms).<size>
: packet size in bytes (default is 56 bytes on x86, 68 bytes on x86_64, min is 24 bytes).<timeout>
: timeout in ms (default is 500 ms, min is 50 ms).icmpping
item.Numeric (unsigned)
as we have selected icmpping
as key we will only get a value back of 0 or 1.Decimal
.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.
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.
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).
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.