check_ping command is a Nagios plugin that is used to check the ping output of a remote server.
Based on the ping output, you can decide to set certain warning and critical threshold level, based on which Nagios can send notifications to you.
If you’ve installed Nagios from source, you’ll find all the default plugins under /usr/local/nagios/libexec directory.
This tutorial explains how you can use check_ping command with some basic examples.
If you don’t pass any arguments to the check_ping command, it will show all available options as shown below.
# cd /usr/local/nagios/libexec # ./check_ping check_ping: Could not parse arguments Usage:check_ping -H <host_address> -w <wrta>,<wpl>% -c <crta>,<cpl>% [-p packets] [-t timeout] [-4|-6]
1. Basic Usage
Use -H option to specify the hostname or the ip-address of the server for which you like to check the ping command output.
You should also pass both warning and critical threshold limit. If not, you’ll get an error.
Threshold limit for check_ping should be passed as a threshold pair, which has two parts:
- Round trip average, which is called as RTA. This is specified in ms
- Percentage of packet loss, which is called pl. This should be specified as %age.
In the following example, we are checking the ping output for 192.168.1.1 host. The warning limit is 10ms RTA or 2% packet-loss. The critical limit is 20ms or 5% packet loss.
# ./check_ping -H 192.168.1.1 -w 10,2% -c 20,5% PING OK - Packet loss = 0%, RTA = 0.11 ms|rta=0.110000ms;1.000000;2.000000;0.000000 pl=0%;10;20;0
Note: You should specify “%” after the second number in the threshold limit pair.
2. Specify the Number of ECHO Packets
By default the check_ping command will send 5 ICMP ECHO packets. If you like to change this, use -p option.
In the following example, it sends 10 ICMP ECHO packets to the remote host before its output is measured.
# ./check_ping -H 192.168.1.1 -w 10,2% -c 20,5% -p 10 PING OK - Packet loss = 0%, RTA = 0.13 ms|rta=0.129000ms;10.000000;20.000000;0.000000 pl=0%;2;5;0
3. Specify the Connection Timeout
By default the check_ping command will do the connection time out (if it is unable to reach the destination host) after 10 seconds. If you like to change this, use -t option.
In the following example, it will wait for 5 seconds before the connection time-out of the remote host.
# ./check_ping -H 192.168.101.49 -w 10,2% -c 20,5% -t 5 CRITICAL - Host Unreachable (192.168.101.49)
4. Use IPv4 of IPv6
By default, it will use IPv4. So, you really don’t need to specify “-4” (which is optional).
# ./check_ping -H 192.168.1.1 -w 1,10% -c 2,20% -4 PING OK - Packet loss = 0%, RTA = 0.14 ms|rta=0.142000ms;1.000000;2.000000;0.000000 pl=0%;10;20;0
But, when you use IPv6 address, you should use -6 as shown below.
# ./check_ping -H 2002:4559:1FE2::4559:1FE2 -w 1,2% -c 2,5% -6
5. check_ping Error Messages
The following are some possible error messages that you might get when you try to use check_ping command.
Error 1: If you don’t specify warning threshold limit, you’ll get the following error message:
# ./check_ping -H 192.168.1.1 <wrta> was not set check_ping: Could not parse arguments
Error 2: If you don’t specify % at the end of threshold limit pair, you’ll get the following error message:
# ./check_ping -H 192.168.1.1 -w 1,10 check_ping: %s: Warning threshold must be integer or percentage! - 1,10
Error 3: If you don’t specify critical threshold limit, you’ll get the following error message:
# ./check_ping -H 192.168.1.1 -w 1,10% <crta> was not set
Error 4: If the warning threshold limit values is greater than the critical limit value, you’ll get the following error message:
# ./check_ping -H 192.168.1.1 -w 10,10% -c 2,20% <wrta> (10.000000) cannot be larger than <crta> (2.000000)
Error 5: If the specify -6 and give a IPv4 address, you’ll get the following error message:
# ./check_ping -H 192.168.1.1 -w 1,10% -c 2,20% -6 check_ping: Invalid hostname/address - 192.168.1.1