How to add notification_periods to Host and Service objects

Hi Community,
how do you add the notification_period to Host and Service objects?
The Director has no option for this (or I did miss it?): as shown here in the second code block
The Director has only a drop down for this option… No custom var option.
I have only one idea but it is more a dirty workaround:
Adding a notification for every contact(group) multiplied with every timeperiod the contact is using, like this:

  • name: contact1_24x7
    • Time period = 24x7
    • assign where: host.vars.notification_period = 24x7
  • name: contact1_workhours
    • Time period = workhours
    • assign where: host.vars.notification_period = workhours
  • name: contact1_nonworkhours
    • Time period = nonworkhours
    • assign where: host.vars.notification_period = nonworkhours
  • name: contact2_24x7
    • Time period = 24x7
    • assign where: host.vars.notification_period = 24x7
  • name: contact2_workhours
    • Time period = workhours
    • assign where: host.vars.notification_period = workhours
  • name: contact2_nonworkhours
    • Time period = nonworkhours
    • assign where: host.vars.notification_period = nonworkhours

This utilizes the custom var in the host object (for services this should be done analog) and filters the right hosts for each notification apply rule. BUT this means an insane amount of busy work and I hope there is another way… :rofl:

If you have another idea, please reply!

best regards
Hendrik

Notifications are dedicated objects in Icinga 2, and as such, the period must be defined as attribute on them. Typically you’ll have apply rules in place with generic period filters then plus assigned users and user groups. I’m wondering about the example, can you summarize the requirement in a more abstracted way with host/service relations to notifications, periods and users?

Cheers,
Michael

Thanks for replying, we want to define host specific time-periods with the custom host variable “notification_period”. I search a way to override the notification period with host variables within the Director configuration, like in this code example:

apply Notification "host-mail-admins" to Host {
  import "mail-host-notification"
  if (host.vars.notification_period) {
    period = host.vars.notification_period
  }
  user_groups = [ "admins" ]
  assign where host.address
}

In Director the time period field is a dropdown list with defined time-periods. There is no option to use the custom host variable.

My possibility as far as I know:
The first option: side-load a conf file to the Director config, which handles the notification objects. This is not a good option for the uninitiated colleague! Not my Favorite, because we want to do the config in Director.

The second option: this is the method from my first post, but this will get annoying soon. If I have 2 groups and 2 periods it is manageable:

Time periods:

  • 24x7 (as standard period)
  • custom1 (from host.vars.notification_period)
  • custom2 (from host.vars.notification_period)

contacts:

  • group1
  • group2
notification contact period filter
any-24x7 all 24x7 assign where ! host.vars.notification_period
group1-custom1 group1 custom1 assign where host.vars.notification_period == “custom1”
group2-custom1 group2 custom1 assign where host.vars.notification_period == “custom1”
group1-custom2 group1 custom2 assign where host.vars.notification_period == “custom2”
group2-custom2 group2 custom2 assign where host.vars.notification_period == “custom2”

So I have to define something around (((contacts + groups) * timeperiods) + 1) objects for this method.

I search a third (better) option!

Thank you for your time.