Unable to use check_ping due to syntax problems


(Dennis) #1

Currently, I am trying to write a check_ping service to try something. Here’s the check command as defined in commands.conf:

object CheckCommand "check_ping" {
	command = [ PluginDir + "/check_ping"]

	arguments = {
		"-H" = {
			value = "$host_to_ping$"
			description = "Website URL to check."
			required = true
		}
		"-w" = {
			value = "$ping_warn$"
			description = "Warning threshold in seconds, packet loss."
			required = true
		}
		"-c" = {
			value = "$ping_crit$"
			description = "Critical threshold in seconds, packet loss."
			required = true
		}
		"-t" = {
			value = "$ping_timeout$"
			description = "Timeout in seconds (10s default)."
		}
		"-4" = {
			set_if = "$use_v4$"
			description = "Use v4 if set to true."
		}
		"-6" = {
			set_if = "$use_v6$"
			description = "Use v6 if set to true."
		}
	}
}

Here’s the relevant part in services.conf:

apply Service "Check Ping to Master" {
	import "generic_service"
	check_command = "check_ping"
	notes_url = "https://www.monitoring-plugins.org/doc/man/check_ping.html"

	vars.host_to_ping = "monitor03.xyz.ch"
	vars.ping_warn = 500,20%
	vars.ping_crit = 1000,40%
	vars.ping_timeout = 10
	vars.use_v4 = true

	assign where match("*puppet_client*", host.vars.role)
}

No matter what I do, I get all kinds of errors that the arguments are incorrect. The above produces the following output:

critical/config: Error: syntax error, unexpected new-line
Location: in /etc/icinga2/zones.d/global-templates/services.conf: 175:0-175:0
/etc/icinga2/zones.d/global-templates/services.conf(173):  vars.host_to_ping = "monitor03.xyz.ch"
/etc/icinga2/zones.d/global-templates/services.conf(174):  vars.ping_warn = 5,20%
/etc/icinga2/zones.d/global-templates/services.conf(175):  vars.ping_crit = 10,40%
                                                          ^
/etc/icinga2/zones.d/global-templates/services.conf(176):  vars.ping_timeout = 10
/etc/icinga2/zones.d/global-templates/services.conf(177):  vars.use_v4 = true

When I try to move the % sign to the command definition, I get the following error:

critical/config: Error: Value computed is not used.
Location: in /etc/icinga2/zones.d/global-templates/services.conf: 174:21-174:22
/etc/icinga2/zones.d/global-templates/services.conf(172): 
/etc/icinga2/zones.d/global-templates/services.conf(173):  vars.host_to_ping = "monitor03.xyz.ch"
/etc/icinga2/zones.d/global-templates/services.conf(174):  vars.ping_warn = 5,20
                                                                              ^^
/etc/icinga2/zones.d/global-templates/services.conf(175):  vars.ping_crit = 10,40
/etc/icinga2/zones.d/global-templates/services.conf(176):  vars.ping_timeout = 10

Running it from the command line works just fine (pinging a different server so as to not ping localhost):

root@monitor03:/etc/icinga2/zones.d# /usr/lib/nagios/plugins/check_ping -H "monitor04.xyz.ch" -w 10,20% -c 20,40%
PING OK - Packet loss = 0%, RTA = 0.29 ms|rta=0.288000ms;10.000000;20.000000;0.000000 pl=0%;20;40;0

Nothing I do seems to work. I’ve tried escaping the colon or percent sign, yet it only throws an error that the \ is unexpected. The user running the script has the correct permissions, too. Am I overlooking something very simple or what’s going on here…?


#2

Have you tried : ?

    vars.ping_warn = "500,20%"
    vars.ping_crit = "1000,40%"

(Dennis) #3

Hey, thank you, that worked. I’ve tried all kinds of string versions, but for some reason I must have missed that. Feeling a little dumb now :slight_smile:

When I tried using strings I usually ended up with the following in Icingaweb2:

<wpl> (5, 20%) must be an integer percentage
check_ping: Could not parse arguments
Usage:
check_ping -H <host_address> -w <wrta>, <wpl>% -c <crta>, <cpl>%
 [-p packets] [-t timeout] [-4

#4

Everyone lost time on this kind of issue. “Simple” issue but hard to find :smiley: