Gunnar: Thanks, that solution does work. Just to reiterate for anyone reading this later, this is a decent way to exclude services for specific nodes without creating a bunch of distinct "ignore" variables:
(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 "ping4" in host.vars.ignore_service Jeff Jeff Williams Senior Consultant, Shadow-Soft Phone: 404.620.3629 Mobile: 678.907.9740 Email: [email protected] Website: www.shadow-soft.com Address: 8302 Dunwoody Place, Suite 100, Altanta, GA 30350 <http://www.linkedin.com/company/shadow-soft> <http://twitter.com/ShadowSoftNews> <http://www.facebook.com/shadowsoftgroup/> On Fri, Apr 8, 2016 at 7:53 AM, Jeff Williams <[email protected]> wrote: > Thanks for your response Gunnar. I actually did try: > > ignore where "ping4" in host.vars.ignore_service > > with similar results. I won't be back to my office to try again until > Monday, but I appreciate your explanation of why I cannot refer to the > Service object attributes (how they do not exist yet) -- that totally makes > sense now (not that I'm not disappointed!) > > Jeff > > On Thu, Apr 7, 2016 at 12:46 AM, Gunnar Beutner <[email protected] > > wrote: > >> 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 >> > > -- 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
