Struggling to apply check_period to a host


I have read through the docs:

And other threads:
https:// community.icinga. com/t/set-time-period-for-all-services-belonging-to-a-certain-host/673
https:// community.icinga. com/t/failing-to-understand-how-notification-time-period-and-service-check-time-period-work-together/2818

But I can’t follow how to weld check_period and Hosts together; it’s just not fitting in my head.

So I have this host:

object Host "cas-test.internal" {
/* Import the default host template defined in `templates.conf`. */
import "generic-host"

/* Specify the address attributes for checks e.g. `ssh` or `http`. */
address = "cas-test.internal"
vars.http_vhost = "$address$"

/* Set custom attribute `os` for hostgroup assignment in `groups.conf`.
vars.os = "Linux"*/

/* Define http vhost attributes for service apply rules in `services.conf`. */
vars.http_vhosts["http"] = {
http_uri = "/login?user=username&pass=passwd"

/* Define notification mail attributes for notification apply rules in `notifications.conf`. */
vars.notification["mail"] = {
/* The UserGroup `icingaadmins` is defined in `users.conf`. */
groups = [ "icingaadmins" ]

And this timeperiod defined:

object TimePeriod "tst-cas" {
import "legacy-timeperiod"

display_name = "Icinga 2 tst-cas TimePeriod"
ranges = {
"monday"    = "08:05-19:55"
"tuesday"   = "08:05-19:55"
"wednesday" = "08:05-19:55"
"thursday"  = "08:05-19:55"
"friday"    = "08:05-19:55"

How do I apply timeperiod “tst-cas” as the only times to run checks on this host and its services?
I’ve tried adding check_period = “tst-cas” to the Host block and also period = “tst-cas” the vars.notification block.

Any help appreciated.

Thank you.

Adding it to the host block should apply it to the host check specifically, in this case most likely “hostalive” since you’re importing the generic template.

To apply it to services, you could try making it a host variable and assigning it. Something like this on the host object:

vars.check_period = "tst-cas"

and then on the service object:

if (host.vars.check_period) {
  check_period = host.vars.check_period
} else {
  check_period = "24x7"

This should get the service to inherit whatever check_period you wanted for the host. I prefer to do this in my notification objects and let the checks keep running. Are you just trying out the feature or are you stuck on something?

1 Like