Re: [icinga-users] Question about assign rules

2016-09-20 Thread Dirk Roeder

Hello Michi,


That sort of requires a more complex expression. While you could use the “in” 
operator this would just work for exact string matches. The better approach is 
to write your own global function which provides such a functionality.
A similar example with templates can be found here: 
http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc#!/icinga2/latest/doc/module/icinga2/chapter/advanced-topics#use-functions-assign-where

globals.check_matching_hostgroup = function(host, search) {
   for (hg in host.groups) {
 if (match(search, hg)) {
   return true
 }
   }

   return false
}

apply Service “blub” {
   //...
   assign where check_matching_hostgroup(host, “*_customer")
}

Thank you very much, that will work perfectly for me!

Kind regards
Dirk
___
icinga-users mailing list
icinga-users@lists.icinga.org
https://lists.icinga.org/mailman/listinfo/icinga-users


Re: [icinga-users] Question about assign rules

2016-09-19 Thread Michael Friedrich

> On 18 Sep 2016, at 18:50, Dirk Roeder  wrote:
>
> Hello together,
>
> I'm right now migration our Icinga1 configuration for the new format and I'm 
> wondering if there is the possibilty of combining match rules with Arrays:
>
> object Host "hostnameX" {
> [...]
> groups = ["application_server", "centos_customer"]
> }
>
> object Host "hostnameY" {
> [...]
> groups = ["application_server", "debian_customer"]
> }
>
>
> These Groups appended with _TYPE are created by our CMDB. I would like to 
> match, if there is any Element within the host.groups Array matching the 
> match string:
> apply Service "serviceW" {
>
> [...]
>
> assign where match("*_customer", host.groups)
> }
>
> With this syntax it's not working for me.

That sort of requires a more complex expression. While you could use the “in” 
operator this would just work for exact string matches. The better approach is 
to write your own global function which provides such a functionality.
A similar example with templates can be found here: 
http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc#!/icinga2/latest/doc/module/icinga2/chapter/advanced-topics#use-functions-assign-where

globals.check_matching_hostgroup = function(host, search) {
  for (hg in host.groups) {
if (match(search, hg)) {
  return true
}
  }

  return false
}

apply Service “blub” {
  //...
  assign where check_matching_hostgroup(host, “*_customer")
}

Kind regards,
Michael


>
>
> Thanks in advance
>
>
> Best regards
>
> Dirk
> ___
> icinga-users mailing list
> icinga-users@lists.icinga.org
> https://lists.icinga.org/mailman/listinfo/icinga-users


-- 
Michael Friedrich, DI (FH)
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 | michael.friedr...@netways.de

** OSBConf 2016 - September - osbconf.org **
** OSMC 2016 - November - netways.de/osmc **
___
icinga-users mailing list
icinga-users@lists.icinga.org
https://lists.icinga.org/mailman/listinfo/icinga-users


[icinga-users] Question about assign rules

2016-09-18 Thread Dirk Roeder

Hello together,

I'm right now migration our Icinga1 configuration for the new format and 
I'm wondering if there is the possibilty of combining match rules with 
Arrays:


   object Host "hostnameX" {
   [...]
groups = ["application_server", "centos_customer"]
   }

   object Host "hostnameY" {
   [...]
groups = ["application_server", "debian_customer"]
   }


These Groups appended with _TYPE are created by our CMDB. I would like 
to match, if there is any Element within the host.groups Array matching 
the match string:


   apply Service "serviceW" {

   [...]

assign where match("*_customer", host.groups)

   }

With this syntax it's not working for me.


Thanks in advance


Best regards

Dirk

___
icinga-users mailing list
icinga-users@lists.icinga.org
https://lists.icinga.org/mailman/listinfo/icinga-users