Hi Jeff,

There are a few problems with your config:

1. (…) == true is redundant. The ‚in‘ operator already returns a boolean value.

2. ‚this‘ does usually refer to the object you’re creating (e.g. the service in 
your case). However, by their very nature assign/ignore rules have to behave 
differently: There simply is no object yet, because these rules are evaluated 
before the object is created. ‚this‘ in an assign/ignore filter is actually 
just an empty dictionary - as opposed to a reference to the new object:

Breakpoint encountered.
Location: in /Users/gunnar/i2/etc/icinga2/conf.d/test.conf: 9:3-9:10
/Users/gunnar/i2/etc/icinga2/conf.d/test.conf(7): apply Service "http" {
/Users/gunnar/i2/etc/icinga2/conf.d/test.conf(8):  assign where {
/Users/gunnar/i2/etc/icinga2/conf.d/test.conf(9):   debugger
                                                    ^^^^^^^^
/Users/gunnar/i2/etc/icinga2/conf.d/test.conf(10):   return (this.name in 
host.vars.ignore_services) == true
/Users/gunnar/i2/etc/icinga2/conf.d/test.conf(11):  }
You can inspect expressions (such as variables) by entering them at the prompt.
To leave the debugger and continue the program use "$continue".
<1> => this.name
null
<2> => this
{
}


Try this instead: ignore where „ping4“ in host.vars.ignore_service

Kind regards,
Gunnar Beutner




On 06/04/16 19:04, "icinga-users on behalf of Jeff Williams" 
<[email protected] on behalf of [email protected]> 
wrote:

>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 <http://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 <http://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 <http://ic1.example.com>" {
>  import "generic-do-droplet"
>  address = "ic1.example.com <http://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 <http://host.name> + "!" +
>this.name <http://this.name>)
>  log((this.name <http://this.name> in host.vars.ignore_service) == true)
>  assign where host.address && host.name <http://host.name> != NodeName
>  ignore where (this.name <http://this.name> in host.vars.ignore_service) == 
> true
>}
>
>
>(icinga2 daemon -C)
>
>information/config: ic1.example.com <http://ic1.example.com>!ping4
>information/config: true
>information/config: icm1.example.com <http://icm1.example.com>!ping4
>information/config: false
>
>(command line test output):
># icinga2 object list --type Service | grep Object.*ping4
>Object 'ic1.example.com <http://ic1.example.com>!ping4' of type 'Service':
>Object 'icm1.example.com <http://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.
>
>
>
>

-- 
Gunnar Beutner
Senior Developer

NETWAYS GmbH | Deutschherrnstr. 15-19 | D-90429 Nuernberg
Tel: +49 911 92885-0 | Fax: +49 911 92885-77
CEO: Julian Hein, Bernd Erk | AG Nuernberg HRB18461
http://www.netways.de | [email protected]

** OSDC 2016 - April - netways.de/osdc **
** OSBConf 2016 - September - osbconf.org **
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users

Reply via email to