Help with timeperiods is_inside after upgrade

Good day

I need some help here as we can not seem to figure this one out.

We recently upgraded icinga from 2.4 to version 2.10.

However after the upgrade, some of the time specific monitors no longer work and we can not seem to figure out why this is happening.

One of the processes in short needs to pass different parameters to the check based on the time of day due to the system being busier during the day than during the evenings.

Currently the check is setup as follows :

Service Defiinition:

apply Service "Asterisk - Time Since Last Pcap" {

#  import "generic-service"

  import "voice-service"

  check_command = "nrpe"

  vars.nrpe_command = "check_last_pcap"

  if (host.vars.env == "dev") {

    vars.nrpe_arguments = [ "999999 999999" ]

  } else if (get_time_period("EightToEight5Days").is_inside) {

    vars.nrpe_arguments = [ "10800 14400" ]

  }

  assign where host.vars.type == "voice-worker"

}

This was changed yesterday as follows as part of testing the service in order to find the problem:

  if (host.vars.env == "dev") {
   vars.nrpe_arguments = [ "999999 999999" ]
  } else { vars.nrpe_arguments = {{
    if (get_time_period("EightToEight5Days").is_inside) {
      return [ "10800 14400" ] }
  }}
  }

However, the check is still passing the incorrect parameters during the evening.

I would really appreciate it if someone can guide us in order to figure out what needs to be changed to get this working again.

Hi,

TimePeriod#is_inside only works at runtime, the following block is evaluated at startup/config compile time, and as such will never give the expected results:

  } else if (get_time_period("EightToEight5Days").is_inside) {

    vars.nrpe_arguments = [ "10800 14400" ]

  }

That being said, nrpe_arguments is a single element inside an array. I doubt that this works as intended.

It has never worked in 2.4 nor following up versions, the values where just calculated from the application start time, and sometimes this was during the timeperiod, and sometimes restart happened outside.

So to speak, you want different nrpe_arguments based on specific static or runtime evaluated states.

  if (host.vars.dev == "dev") {
    vars.nrpe_arguments = [ "999999", "999999" ] //note the array elements
  } else {
     vars.nrpe_arguments = {{  //runtime evaluated custom var, when the check execution actually happens
       if (get_timeperiod("EightToEight5Days").is_inside)) {
         return [ "10800", "14400" ]
       } else {
          //define a default value
          return [ "000000", "000000" ]
       }
     }}
  }

Cheers,
Michael