# How to add notification\_periods to Host and Service objects

**URL:** <https://community.icinga.com/t/how-to-add-notification-periods-to-host-and-service-objects/499>\
**Category:** Icinga Director\
**Tags:** notifications\
**Created:** [March 1, 2019, 3:22pm UTC](https://community.icinga.com/t/how-to-add-notification-periods-to-host-and-service-objects/499 "2019-03-01T15:22:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohrly](https://community.icinga.com/letter_avatar_proxy/v4/letter/o/4af34b/32.png) [@ohrly](https://community.icinga.com/u/ohrly)\
**Post date:** [March 1, 2019, 3:22pm UTC](https://community.icinga.com/t/how-to-add-notification-periods-to-host-and-service-objects/499/1 "2019-03-01T15:22:02Z")

</div>

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](https://icinga.com/docs/icinga2/latest/doc/03-monitoring-basics/#apply-notifications-to-hosts-and-services)  
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…** 🤣

If you have another idea, please reply!

best regards  
Hendrik

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [March 11, 2019, 2:19pm UTC](https://community.icinga.com/t/how-to-add-notification-periods-to-host-and-service-objects/499/2 "2019-03-11T14:19:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ohrly](https://community.icinga.com/letter_avatar_proxy/v4/letter/o/4af34b/32.png) [@ohrly](https://community.icinga.com/u/ohrly)\
**Post date:** [March 13, 2019, 3:23pm UTC](https://community.icinga.com/t/how-to-add-notification-periods-to-host-and-service-objects/499/3 "2019-03-13T15:23:50Z")

</div>

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:

```auto
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.
