Re-notification interval based on time period


Say you have a notification apply rule defined with interval set to 1h. I would like to change the re-notification interval based on current time being within defined timeperiod. Something like this

if current_time is within 9to5 timeperiod; then
interval = 1h
interval = 0

I tried to use two separate notification apply rules but it tat approach has it problems. Is this doable using single notification apply statement and some kind of condition?

I have not tried this use case but perhaps you can get it to work similar to time dependent thresholds for services.

Haven’t tried it but maybe:

apply Notification "notification-name" to Host {
    import "some-notification"
    users = ["username"]

    interval = {
       if (get_time_period("9to5Timeperiod").is_inside) {
          return 1
       } else {
          return 0

     assign where something

Am unsure if you need to return ‘1h’, but I know 0 works without an ‘h’

It would need {{ and }} for returning a lambda so it is executed on every access of the interval.

And 0 works because durations are only a special form of number so without a unit it is in second, so it would result in interval 1s which is perhaps to much spam! :wink:

But except from this, this was what I had in mind.

Thank you! I’ll give it a try and report back :slight_smile:

I am unable to assign lamba directly to the interval like this: interval = {{ something }}. It give me this error:

Error: Error while evaluating expression: Can't convert 'Object of type 'Function'' to a floating point number

With this syntax Icinga 2 is happy but it is probably incorrect since it always sets the interval to 0:

interval = vars.dynamic_interval
vars.dynamic_interval = {{
  if (get_time_period("9to6").is_inside) {
    return 1h
  } else {
    return 2h

I can do this:

interval = if (get_time_period("9to6").is_inside) {
    return 1h
  } else {
    return 2h

but here the iterval is alway 1800 which is the icinga2 default value