I have run into something that looks to me like a bug and wanted to run it
past everyone before submitting it.

In defining my hosts and services, sometimes I just need to not assign a
service check to a host because it's just never going to work. I started by
doing this:

(in my host template, defining the default)
vars.ignore_ping4 = false

(in my specific Host definition)
vars.ignore_ping4 = true

(in my ping4 Service definition)
ignore where host.vars.ignore_ping4 == true

This works -- if the host sets vars.ignore_ping4 to true the service does
not get assigned to it. But it does not scale pleasantly if you want to be
able to ignore a variety of services. So I thought "Fine, I can use an
array or a dictionary to define which services I need to ignore."

(in my host template, defining the default)
vars.ignore_service = []

(in my specific Host definition)
vars.ignore_service = ["ping4"]

(in my ping4 Service definition)
ignore where (this.name in host.vars.ignore_service) == true

This passes the config check, but is never true (thus never ignored). I
have added logging to my service so that I can see the values while going
through config check and they are exactly as I expected.

Has anyone else run into trouble using arrays within an "ignore where" or
"apply where"? I have coded this using arrays, dictionaries and functions
and cannot get any of them to not assign the service to the host.

Excerpts from my definitions, "ic1.example.com" is the host I'm working on:
(template)
template Host "generic-host" {
  max_check_attempts = 3
  check_interval = 1m
  retry_interval = 30s

  vars.ignore_disk = false
  vars.ignore_swap = false
  vars.ignore_ping4 = false

  vars.ignore_service = []

  check_command = "hostalive"
}

(host)
object Host "ic1.example.com" {
  import "generic-do-droplet"
  address = "ic1.example.com"
  vars.remote_host = name
  check_command = "ssh"
  vars.ignore_service = ["ping4"]
  vars.http_vhosts["http"] = {
    http_uri = "/"
  }
}

(service)
apply Service "ping4" {
  import "generic-service"
  check_command = "ping4"
  log(host.name + "!" + this.name)
  log((this.name in host.vars.ignore_service) == true)
  assign where host.address && host.name != NodeName
  ignore where (this.name in host.vars.ignore_service) == true
}

(icinga2 daemon -C)
information/config: ic1.example.com!ping4
information/config: true
information/config: icm1.example.com!ping4
information/config: false

(command line test output):
# icinga2 object list --type Service | grep Object.*ping4
Object 'ic1.example.com!ping4' of type 'Service':
Object 'icm1.example.com!ping4' of type 'Service':
#

-- 

The information contained in this message and any attachments is 
confidential and proprietary.  It is intended only for the named 
recipient(s).  If you received this message in error, please notify us 
immediately and be aware that any disclosure, copying, distribution, or use 
of the contents of this information is strictly prohibited. 


_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users

Reply via email to