Re: [icinga-users] Using check_multi with Icinga2

2016-08-16 Thread Michael Martinez
On Fri, Aug 12, 2016 at 11:16 PM, Gunnar Beutner
 wrote:
> How about something like this?:
>

Thanks so much for your code! It helped a lot.

In putting it together, I've come into a couple of questions:

1) why do we need to say "macro" in   for (instance in
macro("$ec2_instances$")) ...? Why can't we just say: for (instance in
ec2_instances)  ..?

2) why is a variable that is created with "var" only visible inside
the conf file that it appears in? I created a "var elb {}" inside one
conf file (not inside any functions or objects), then I tried to
reference it inside another conf file but was rejected. It works if I
append that second conf file at the end of the first.
___
icinga-users mailing list
icinga-users@lists.icinga.org
https://lists.icinga.org/mailman/listinfo/icinga-users


Re: [icinga-users] Using check_multi with Icinga2

2016-08-16 Thread Michael Martinez
Ok, the code given below works (for now I'm going with the
check_cluster plugin, although eventually I will play around with
Gunnar's script).

I've got a question. I don't know why "h.groups" is null. I've
verified that the hosts are getting assigned into HostGroups using the
web api to query objects. But my log statement keeps showing that
h.groups is empty. Any thoughts?

--
for (elbname => members in elb) {
/* the "use" is necessary to pass the variable into the scope of the object */
  object Service "check_cluster elbname" use(elbname) {
import "generic-service"
check_command = "check_cluster"
host_name = elbname

  /* using braces makes it a function which means
 it is calculated dynamically. otherwise without braces
 it is calculated once at compile time

 hostgroup membership is designated in the hosts.groups array,
 not in the HostGroup object. So it is necessary to iterate
 over all hosts to find which ones belong to a particular HostGroup.
  */

vars.ec2_instances = []
for (h in get_objects(Host)) {

 if (!h.groups) { log("h.groups empty") }

 if (elbname in h.vars._elbs) {
// if (elbname in h.groups) {
vars.ec2_instances.add(h.name)
  }
}

log("MM2: elbname: " + elbname + ", ec2_instances: " +
vars.ec2_instances.join(",") )

vars.cluster_data = {{
  var states = []
  for (instance in macro("$ec2_instances$") ) {
states.add(get_host(instance).state)
  }
  return states.join(",")
}}

vars.cluster_label = elbname

  }

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