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

Reply via email to