One more wrinkle on this topic. In another case, using Gunnar's solution, I also want to only assign the service if a host var is set. Right now, I'm doing this, which doesn't work:

apply Service "bla" {
   assign where {
     var match = [ "a", "b" ]
     var arr = intersection(host.groups, match)
     return arr.len() > 0
   }
} && host.vars.check_flag == true

I've also tried adding an ignore statement instead, which also didn't work:

ignore where host.vars.check_flag != true

I don't always set the check_flag var, only when it is set to true, so maybe that's why the ignore doesn't work? Or does order matter when combining assign and ignore statements?

Any ideas on how I can accomplish this?

Thanks.

On 07/15/2015 10:03 AM, Seth Galitzer wrote:
On 07/15/2015 01:18 AM, Gunnar Beutner wrote:





On 15/07/15 08:04, "icinga-users on behalf of Michael Friedrich"
<[email protected] on behalf of
[email protected]> wrote:



Sent from my iphone w/ free typos.

Am 14.07.2015 um 23:42 schrieb Seth Galitzer <[email protected]>:

I want to be able to assign a service to a host that may be in one
of several groups among its list of groups. So if host "A" is in
groups "foo" and "bar" and service "check_foo" is assigned to hosts
that are members of the groups "foo" and "baz", then host "A" should
run service "check_foo". What would be the correct syntax for this
case?

I have the following and it obviously is incorrect:

object Host "A" {
  groups += [ "foo", "bar" ]
}

apply Service "check_foo" {
  assign where host.groups in [ "foo", "baz" ]
}

How about apply for? (Untested)

apply Service "bla" for (hg in host.groups) {

  assign where hg in [ "a", "b" ]
}

That’s going to break if your host is in more than one of the groups
you’re checking for (because in that case you’re trying to create two
„bla“ services).


In my specific use case, this would probably be fine.


A different approach would be intersection checking the array length.

http://docs.icinga.org/icinga2/latest/doc/module/icinga2/chapter/library-reference#global-functions


apply Service"bla" {

  var match = [ "a", "b" ]
  var arr = intersection(host.groups, match)

  assign where arr.len() > 0

}

That’s not going to work because ‚assign where‘ and ‚ignore where’
statements are evaluated _before_ all other statements. This should
work though:

apply Service "bla" {
   assign where {
     var match = [ "a", "b" ]
     var arr = intersection(host.groups, match)
     return arr.len() > 0
   }
}



This worked perfectly. I need to look more closely at these global
functions.

Thanks to all for the help.

Seth



Kind regards,
Michael


I need the correct way to say "assign where <any list member of
host.groups that matches any member of this list>".

I hope that makes sense. Anybody have any suggestions? Do I need to
do this in the apply statement somehow to loop through members of
host.groups? Or is there a better way?

Thanks.
Seth

--
Seth Galitzer
Systems Coordinator
Computing and Information Sciences
Kansas State University
http://www.cis.ksu.edu/~sgsax
[email protected]
785-532-7790
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users

-- 
Michael Friedrich, DI (FH)
Application Developer

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

** OSBConf 2015 - September - osbconf.org **
** OSMC 2015 - November - netways.de/osmc **
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users

-- 
Gunnar Beutner
Application Developer

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

** OSBConf 2015 - September - osbconf.org **
** OSMC 2015 - November - netways.de/osmc **
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users



--
Seth Galitzer
Systems Coordinator
Computing and Information Sciences
Kansas State University
http://www.cis.ksu.edu/~sgsax
[email protected]
785-532-7790
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users

Reply via email to