I configured a bunch of hosts statically via config scripts. Then I used an external script to query ESX hosts to pull the virtual machine information from each ESX host and fed it into Icinga using REST API: For all virtual machines I added a host variable
vars.esxhost = host name
The Icinga web GUI easily shows these variables have been set correctly for each host.
Output of first command. Variable esxhost ist not shown.
root@icinga:/etc/icinga2/conf.d# icinga2 object list --type Host --name listig
Object ‘listig’ of type ‘Host’:
% declared in ‘/etc/icinga2/conf.d/hosts/unix/listig.conf’, lines 1:0-1:19
__name = “listig”
action_url = “”
address = “10.192.2.91”
% = modified in ‘/etc/icinga2/conf.d/hosts/unix/listig.conf’, lines 3:2-3:24
address6 = “”
check_command = “hostalive”
% = modified in ‘/etc/icinga2/conf.d/templates.conf’, lines 19:3-19:29
check_interval = 60
% = modified in ‘/etc/icinga2/conf.d/templates.conf’, lines 16:3-16:21
check_period = “”
check_timeout = null
command_endpoint = “”
display_name = “listig”
enable_active_checks = true
enable_event_handler = true
enable_flapping = false
enable_notifications = true
enable_passive_checks = true
enable_perfdata = true
event_command = “”
flapping_threshold = 0
flapping_threshold_high = 30
flapping_threshold_low = 25
groups = [ ]
icon_image = “”
icon_image_alt = “”
max_check_attempts = 3
% = modified in ‘/etc/icinga2/conf.d/templates.conf’, lines 15:3-15:24
name = “listig”
notes = “”
notes_url = “”
package = “_etc”
retry_interval = 30
% = modified in ‘/etc/icinga2/conf.d/templates.conf’, lines 17:3-17:22
root@icinga:/etc/icinga2/conf.d# icinga2 object list --type HostGroup --name “vm”
Object ‘vm’ of type ‘HostGroup’:
% declared in ‘/etc/icinga2/conf.d/groups/hgroups.conf’, lines 24:1-24:21
Thanks for your input, as i suspected, your hostgroups is not applying to your host because it is missing the var esxhost in vars in some way in the configuration.
You can directly define it in your static configuration host file (/etc/icinga2/conf.d/hosts/unix/listig.conf)
Did you affected the current esxhost to your hosts throught api ? if so, did you restarted icinga after this ?
Templates objects dont reapply at runtime for modifications done on the API, it may be the case too for HostGroups.
Hello @Hutzli
The where statement is you HostGroup object is bad. Could you try this where statement?
object HostGroup “vm” {
display_name = “Virtual Machines”
assign where match ( "*", host.vars.esxhost )
}
EDITED: Sorry I did not read your next post. The variable is missing when running the the object list command. The where statement will not work without the variable showing under the host object command first.
@someone:
Yes I did a: icinga2 daemon --validate && systemctl reload icinga2
I just tried systemctl restart icinga2 but with no change.
In /var/lib/icinga/modified-attributes I find lines of the kind:
var obj = get_object(“Host”, “listig”)
if (obj) {
obj.modify_attribute(“vars.esxhost”, “qux”)
obj.version = 1596634559.644526
}
I have the assumption that during startup these modifications are applied too late, i.e. AFTER apply rules for hostgroups were already executed. Is that possible?
My problem seems somewhat related to this one.
However then reloading/restarting icinga should fix it - that’s not the case, however.
I should add version information:
root@icinga:/etc/icinga2/conf.d# icinga2 --version
icinga2 - The Icinga 2 network monitoring daemon (version: r2.11.3-1)