Friday, May 8, 2015

ICINGA2: Disable ping check for hosts

Sometimes you need to monitor services on a server where ICMP is not feasible to check whether the host is up. In Icinga2, even if you change your host definition to use 

check_command = "dummy"

it will still do a ping4 service check on the host. The issue is with the definition of the ping4 service as it will apply the ping4 service checks to all hosts that have "address" set.

One of the ways to bypass this is to change the ping4 service line to the following:

assign where host.address && host.vars.ping == "yes"

This way we can add a variable to only allow certain hosts to be pinged. This solution will force you to add the variable

vars.ping = "yes"

for every host you want checked via the ping4 service. An easier way is to modify the generic-host template to include the vars.ping = "yes" variable. You also need to create another template let us say generic-host-no-ping to not have the variable set to "yes" and to use the "dummy" check service which will always return 0 (OK)

template Host "generic-host-no-ping" {
   max_check_attempts = 5
   check_interval = 1m
   retry_interval = 30s
   check_command = "dummy"
   vars.ping = "no"
 }

Now when you create your host definition you just need to import the correct template.

5 comments:

Unknown said...

Man, you are the best! I'm icinga 1.x user and icinga 2 seems to me a little mess.
But with simple article like yours ... I got it!
Cheers,
Valentin from Bulgaria

The Mad Innovator said...

Thanks, after 3 hours of tries to get it to work I found this solution!

Unknown said...

Or just do this on the ping4 service:

assign where host.address && !host.vars.no_ping

Then you don't need two templates and only on the servers where you don't want the ping check you specify vars.no_ping == "true"

Anonymous said...

Magnus, your solution works great. There is just a problem with the syntax.

vars.no_ping == "true" should be vars.no_ping = "true"

Stefano C. - YouAndTech said...

Hi There,
I found another solution.

you can set ping4 service as follows:

apply Service "ping4" {
import "generic-service"
check_command = "ping4"
assign where host.address && host.check_command == "hostalive"

}

In this way you can create new host template using different check command and pig4 service will be disabled.

Cheers

Stefano Cau
YouAndTech
www.youandtech.it