How about something like this?: object Host "ec2-instance1" { import "generic-host"
address = "192.168.2.36" vars.elbs = [ "elb1", "elb2" ] } object Host "ec2-instance2" { import "generic-host" address = "192.168.2.36" vars.elbs = [ "elb1", "elb2" ] } var ELBs = [ "elb1", "elb2" ] for (elb in ELBs) { object Host elb { import "generic-host" } object Service "cluster" use(elb) { import "generic-service" host_name = elb check_command = "dummy" vars.ec2_instances = [] for (host in get_objects(Host)) { if (elb in host.vars.elbs) { vars.ec2_instances.add(host.name) } } vars.cluster_data = {{ var states = [] for (instance in macro("$ec2_instances$")) { states.add(get_host(instance).state) } return states.join(",") }} vars.cluster_state = {{ var worst_state = 0 for (instance in macro("$ec2_instances$")) { var state = get_host(instance).state if (state > worst_state) { worst_state = state } } return worst_state }} vars.cluster_info = {{ var worst_state = macro("$cluster_state$") var instances = [] for (instance in macro("$ec2_instances$")) { if (get_host(instance).state == worst_state) { instances.add(instance) } } var states = [ "OK", "Warning", "Critical", "Unknown" ] return "Instances " + instances.join(", ") + " are in state " + states[worst_state] }} vars.dummy_state = "$cluster_state$" vars.dummy_text = "$cluster_info$" } } This automatically figures out which instances belongs to each ELB by iterating over all hosts and checking their ‚elbs’ custom variable. I’ve also added a few additional custom variables (cluster_state, cluster_info) which demonstrate how you can use use check_dummy to generate your own check results – without using another external plugin. -----Original Message----- From: icinga-users <icinga-users-boun...@lists.icinga.org> on behalf of Michael Martinez <mwt...@gmail.com> Reply-To: "icinga-users@lists.icinga.org" <icinga-users@lists.icinga.org> Date: Friday 12 August 2016 at 23:15 To: "icinga-users@lists.icinga.org" <icinga-users@lists.icinga.org> Subject: Re: [icinga-users] Using check_multi with Icinga2 On Fri, Aug 12, 2016 at 12:32 PM, Gunnar Beutner <gunnar.beut...@netways.de> wrote: > You’re going to have to move the attribute declaration _into_ the apply rule: Hmmm.. Let me explain what I need to do, and maybe the folks here can help suggest how to achieve it; Outside of Icinga, I gather a list of amazon instances and the ELBs that they are attached to. I am using Jinja templates to produce the Icinga host objects from this list. In order to associate each ELB to which hosts belong to it, I have done two things: a) in each host object, have a vars._elb variable that contains the names of the ELBs the host belongs to b) outside of the host objects, created a "global" elb["elbname"] array that contains the hostnames of the hosts that belong to it Now, I need to create a Service object (for each ELB) that contains a vars.cluster_data variable which contains the hosts in the ELB, as follows: vars.cluster_data = {{ get_host("hostname1").state + "," + get_host("hostname2").state + "," + .... }} I was trying to do this by referencing the "global" elb array as I mentioned, but apparently this global data is not available within the Service definition. What woudl be the right approach? Perhaps instead of creating an ELB array, I should create a hostgroup for each ELB, and put the ELB's members as members of the hostgroup. Then I can reference them in my Service definition? -- --- Michael Martinez http://www.michael--martinez.com _______________________________________________ icinga-users mailing list icinga-users@lists.icinga.org 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 | gunnar.beut...@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