You’re going to have to move the attribute declaration _into_ the apply rule:
apply Service "clusterx" {
vars.elb["x"] = [ "xx.ap-northeast-1.compute.amazonaws.com" ,
"xy.ap-northeast-1.compute.amazonaws.com" ]
....
if (!vars.elb["x"] { log("Array not defined") }
...
}
Otherwise your assignment would create a global variable „vars“ – which is not
associated with any service and therefore has no effect.
This seems like a good opportunity to mention
https://www.icinga.org/2015/11/12/icinga-2-script-debugger/ :)
-----Original Message-----
From: icinga-users <[email protected]> on behalf of Michael
Martinez <[email protected]>
Reply-To: "[email protected]" <[email protected]>
Date: Friday 12 August 2016 at 20:10
To: "[email protected]" <[email protected]>
Subject: Re: [icinga-users] Using check_multi with Icinga2
On Thu, Aug 11, 2016 at 11:53 PM, Michael Friedrich
<[email protected]> wrote:
> That as such won’t work since the custom attributes values are computed
at config compile time. You are looking for runtime calculated values - which
is why you need to turn the custom attribute values into a function.
>
> Something like that:
>
> vars.cluster_label = {{ get_host("vagrant-minion").state }}
> vars.cluster_data = {{ get_host("vagrant-minion").state }}
>
Ah, got it! This works. Thanks so much for the clarification.
Now I'm running into a new challenge. I would like to construct an
array of hostnames and then reference this array inside a service
object, as follows:
vars.elb["x"] = [ "xx.ap-northeast-1.compute.amazonaws.com" ,
"xy.ap-northeast-1.compute.amazonaws.com" ]
apply Service "clusterx" {
....
if (!vars.elb["x"] { log("Array not defined") }
...
}
The log statement shows me that this array is not defined in the
service definition. What am I doing wrong?
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users
--
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]
** OSBConf 2016 - September - osbconf.org **
** OSMC 2016 - November - netways.de/osmc **
_______________________________________________
icinga-users mailing list
[email protected]
https://lists.icinga.org/mailman/listinfo/icinga-users