How to configure max_check_attempts for all services of one host?

I want to increase max_check_attempts for one of my hosts and all its services (it is on an unstable network link, and is generating a lot of unnecessary notifications).

I managed to do this with the following configuration:

# in templates.conf
template Host "generic-host" {
  max_check_attempts = 3
  check_interval = 1m
  retry_interval = 30s
}

template Service "generic-service" {
  max_check_attempts = 5
  check_interval = 1m
  retry_interval = 30s
  if (host.name == "host-in-question") {
    max_check_attempts = 20
    check_interval = 1m
    retry_interval = 1m
  }
}

# in other.conf
object Host "host-in-question" {
  import "generic-host"
  max_check_attempts = 15
  check_interval = 1m
  retry_interval = 1m
  # unimportant configuration omitted
}

I had to add this ugly check inside generic-service because I have lots of different Services that are created using apply rules. But is there a cleaner way, is there a way to change max_check_attempts for all services of some host without polluting generic-service configuration?

Hello,

You can set a varibale like vars.service_check_attempts = whatever in you host file and then do this in your services after the import of the generic-template or any other template that sets max_check_attempts

if (host.vars.service_check_attempts) {
   max_check_attempts = host.vars.service_check_attempts
}

So the check attempts will only be set for service other then in the template if the variable exists on the host object.

Regards,
Carsten

Yes, that’s much better. I added the “if” statements directly to the generic-service to avoid duplicating the code in all other service definitions.

Thanks!