Set time period for all services belonging to a certain host

Hi there,

I am not sure if this is the right place to ask but I hope that you can still help me :sweat_smile:
Basically my question is if it is possible to set a time period for a host and all its service in one step? I wasn’t able to find such an option or any tutorial online.

Best regards

1 Like

Hi,

do you mean the attribute check_period or are you referring to notifications and their period attribute?

Cheers,
Michael

Hi @dnsmichi,

I do mean the check_period attribute. For example I used the 9to5 timeperiod for a specific host and wanted to apply this to all its services. I hope this makes it clearer :slight_smile:

1 Like

Hi brehman,

take a look into the docs: https://icinga.com/docs/icinga2/latest/doc/08-advanced-topics/#timeperiods

You can use your own timeperiod in hosts or services:

object TimePeriod "04to06" {
  import "legacy-timeperiod"
  display_name = "04to06"
  ranges = {
        "monday"        = "04:00-06:00"
        "tuesday"       = "04:00-06:00"
        "wednesday"     = "04:00-06:00"
        "thursday"      = "04:00-06:00"
        "friday"        = "04:00-06:00"
        "saturday"      = "04:00-06:00"
        "sunday"        = "04:00-06:00"
  }
}

apply Service "yourservice-" for (backup_name in host.vars.backup) {
    import "generic-service"

	check_period =		"04to06"
	check_interval =	1h
    
	check_command = 	"nrpe"
    vars.nrpe_command =             "check_backup"
	vars.nrpe_arguments =   		backup_name
    vars.nrpe_timeout_unknown =     true // -u
    vars.nrpe_no_ssl =              true // -n

    vars.backup = backup_name

    assign where host.name == "yourhost"
}
1 Like

Hi,

this can be achieved with apply rules where you have access to the host object, e.g. like this:

apply Service "..." {

  if (host.check_period != "") {
    check_period = host.check_period
  }

  //...
}

Cheers,
Michael

2 Likes

Hi @dnsmichi ,

we are using the icinga director and it seems that kind of apply Service cannot be configured via director.
The following method is used to create new hosts with services.

  • Host is based on a host template
  • All the services on the host will be placed via a serviceset which is added to the host template
  • For specific devices another host template is added which adds the snmp community string
  • For other hosts there will be a SLA and we want to deploy those SLA’s also via one more host template

host-templates

is it possible to do that this way or do we need to rethink our template structure?

best regards,
Nicolas

Hi,

well, conditions in the DSL are not the way the Director works, that’s true. Instead, I would suggest to use a service template here and import that on-demand into the specific services.

If that doesn’t work, it might be a good idea to leave the checks active in this period, and modify the notification apply rules, setting the period attribute. That still shows the checks, but prevents the notifications outside of your support times.

Cheers,
Michael