Change Check Timeperiod for services

Hello together,

if the Check Timeperiod at a host is for example: 06:00_bis_19:00_5_Tage, we are able to take over the the Check Timeperiod for for the ping test:

root@icinga_server:~# cat /etc/icinga2/conf.d/services.conf

apply Service “ping4” {
import “generic-service”

  check_command = "ping4"

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

But we are not able to take over the Check Timeperiod from the host to the other services.

We tried in different configfiles and in the director. But either it has no effect or just a temporary effect.

It would be great if someone could tell us how to go about this.

Thanks and Greetings

Hi @tom2,

Not sure if:
if (host.check_period) {
is a good way to program this


It seems to be valid syntax. So that is great.

We do other things with if else statements like this:

  if (host.vars.env == "DEV") {
     import "generic-service"
  } else if (host.vars.env == "PROD") {
     import "generic-service-wp"
  }

So I found this:

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

Hope it will help you in the right direction :smiley:

Hi, thanks for your reply, I’m his collegue.
We know so far that the syntax works, since we’re using it for service apply rules defined in /etc/icinga2/.

Though, how do we add this if condition to services created by Icinga Director?

Hi @Tobias,

Welcome to the community! have you seen this page:

I only run the director in a vagrant box not in production as the configuring it in text is way easier for a linux person :slight_smile: so It will probably take ma a while to figure it out exactly how to get this done as I have yet found the need for it in a VM

Thanks for the link to that page. Though, that doesnt help with our current problem.

We’d need to know how to alter the configuration for the services created by the director to be able to inherit the check_period of the host.
So, we probably need someone in here with knowledge ofthe director itself.

We tried to change the configuration in different files like:
/var/lib/icinga2/api/zones/director-global/director# nano service_apply.conf
And also in several other files. But it had not at all an effect.

The change in this file temporarily caused the desired change in the check time period in the services:
/var/lib/icinga2/api/packages/director/32c25012-3b3c-495f-83db-5d0c4fea3ff1/zones.d/director-global/service_apply.conf

But the change was only effective as long as the temporary, generic folder 32c25012-3b3c-495f-83db-5d0c4fea3ff1 and subfolders were present.

It would be great if someone could tell us how or at which service_apply.conf we can add permanent changes.

Issue is solved. Tobias found the solution:

nano /etc/icingaweb2/enabledModules/director/library/Director/Objects/IcingaService.php

    $suffix .= "\n    if (host.check_period) {\n        check_period = host.check_period\n    }\n";