Service scheduled downtime error


(Lucas Possamai) #1

Hi.

I’m trying to schedule downtime for a specific service as below.

/etc/icinga2/zones.d/master/downtimes.conf:

apply ScheduledDowntime "backup-downtime" to Service {
  author = "icingaadmin"
  comment = "Scheduled downtime for backup"

  service_name = "load"

  ranges = {
    monday = "01:30-05:00" 
    tuesday = "01:30-05:00" 
    wednesday = "01:30-05:00"
    thursday = "01:30-05:00"
    friday = "01:30-05:00"
    saturday = "01:30-05:00"
    sunday = "01:30-05:00"
  }

  assign where host.vars.backup == "yes"
}

Error when icinga2 daemon -C:

[2019-01-14 13:18:03 +1300] critical/config: Error: An object with type 'ScheduledDowntime' and name 'db2.datacentre.example.com!load!downtime-backup' already exists (in /etc/icinga2/zones.d/master/downtimes.conf: 5:1-5:52), new declaration: in /etc/icinga2/zones.d/master/downtimes.conf: 5:1-5:52
Location: in /etc/icinga2/zones.d/master/downtimes.conf: 5:1-5:52
/etc/icinga2/zones.d/master/downtimes.conf(3):  */
/etc/icinga2/zones.d/master/downtimes.conf(4): 
/etc/icinga2/zones.d/master/downtimes.conf(5): apply ScheduledDowntime "downtime-backup" to Service {
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/master/downtimes.conf(6):   author = "icingaadmin"
/etc/icinga2/zones.d/master/downtimes.conf(7):   comment = "Scheduled downtime for backup"

db2.conf:

object Host "db2.datacentre.example.com" {
    import "generic-host"
[...]
    vars.backup = "yes"

When querying Icinga’s API to double check there isn’t any downtime already scheduled:

root@icinga:/etc/icinga2/zones.d/master# curl -k -s -u root:root -H 'Accept: application/json' -X GET 'https://localhost:5665/v1/objects/downtimes'
{"results":[]}

What am I doing wrong?

Cheers!


(Lucas Possamai) #2

I may have found the problem? Should I set it up like this?

apply Service for (disk => config in host.vars.disks) { 

    import "generic-service"                                           

    /* Used by the ScheduledDowntime apply rule in `downtimes.conf`. */
    vars.backup_downtime = "yes"
apply ScheduledDowntime "backup-downtime" to Service {
  author = "icingaadmin"
  comment = "Scheduled downtime for backup"


  ranges = {
    monday = "01:30-05:00" 
    tuesday = "01:30-05:00" 
    wednesday = "01:30-05:00"
    thursday = "01:30-05:00"
    friday = "01:30-05:00"
    saturday = "01:30-05:00"
    sunday = "01:30-05:00"
  }

  assign where service.vars.backup_downtime == "yes"
}

will test it


#3
apply ScheduledDowntime "backup-downtime" to Service {
  service_name = "load"
...
  assign where host.vars.backup == "yes"
}

What you do is you create a ScheduledDowntime object for every service where host.vars.backup == “yes”. If a host has 5 services you create 5 ScheduledDowntime objects. Then you set the service_name in each of those 5 ScheduledDowntime object to “load”, i.e. you are trying to create 5 identical ScheduledDowntime objects which fails with the error message you see.

What you probably want is to schedule a downtime for all services of hosts which have the vars.backup set to yes. You have to omit the “service_name = load” from your configuration. Using the apply to Service you assign a ScheduledDowntime for each service of your host. Icinga2 automatically uses the service name of each service in each scheduled downtime.

If you only want to scheduled the downtime for service “load” then you have to extend the assign where to check for the service_name.