Change max_check_attempts depending on state

Hello.

I’ve been looking for information about how I could increasing the value of max_check_attempts of a service depending on its status. I want to increase it ONLY when the state be UNKNOWN.

This is what I added to my service config file:

if (state == 3) {
max_check_attempts = 10
} else {
max_check_attempts = 3
}

But it simply increases max_check_attempts to 10 to all states (CRITICAL and UNKNOWN) … :frowning:

Maybe what I want to do it’s just not possible …
Thanks a lot for helping in advance.

Regards.

The if is evaluated during configuration so it is always depending on the state during reload. For an evaluation during runtime you need the attribute to return a function. But I am not sure if this works for this specific attribute.

This would look similar to this:

max_check_attempts = {{
  if (state == 3) {
     return 10
  } else {
     return 3
  }
}}

Thanks for the suggestion Dirk.

Unfortunately the checkconfig detects a config error. :frowning:

[2022-04-04 09:40:59 -0500] critical/config: Error: Error while evaluating expression: Can’t convert ‘Object of type ‘Function’’ to a floating point number.

Regards.

Then this unfortunately only works for custom variables. :frowning: