Hi,
I installed the Cube module for IcingaWeb2 and I’m trying now to create a view displaying all my zones (currently “Master” and “Satellite”) with all hosts in these zones.
No problem displaying the zones, as far as I define a custom variable vars.zone with the name of the zone, but I’d like to display the host names in the view, too…
Unfortunately I can’t access a variable with the host name inside Cube (and I don’t want to patch the code, for now…).
So I’m trying to define a custom variable with what I need.
Obviously I don’t want to define this variable on every host I have, so I tried to define it in a template:
template Host "generic-host" {
max_check_attempts = 5
check_interval = 1m
retry_interval = 1m
check_command = "hostalive"
enable_perfdata = true
vars.downtime = ""
vars.kind = ""
vars.name = host.vars.name
}
but it does not work and fails by check config with Tried to access undefined script variable ‘host’
So my question(s):
- is it possible to automatically define a variable with the host name? How?
- is it possible to define a variable with the zone name? How?
Thanks a lot
Luca
Hi There,
how about:
vars.agent_endpoint = name
You possibly have this already in your host configs. So perhaps you can use this in cube?
Hi William,
thanks a lot! I wrote:
vars.name = display_name
and it works.
The variable name is not in Cube, so I must add it in a way…
Any suggestion for automagically set a variable with the zone (defined as a directory into zones.d)?
Thanks
Luca
For that we use:
vars.zone = "{{ ic_sat_zone }}"
in ansible 
put the zone in the host / group vars like:
ic_sat_zone: EU-servers
That will put it in our /zones.d/EU-servers/EUhost.conf once it need to place the template EUhost.conf.j2
So for automation, you should look into ansible / puppet / chef /terraform or other flavour that you like.
You could bash script it away, but I would not recommend it.
Hi William,
we don’t use ansible.
Do you know if there is a solution using plain Icinga2?
Thanks
Luca
Hi,
You could see what
host.zone
holds in terms of information it should be the folder the host is in.

Thank you very much William!
You saved my day!!!
I wrote in my template:
template Host "generic-host" {
max_check_attempts = 5
check_interval = 1m
retry_interval = 1m
check_command = "hostalive"
enable_perfdata = true
vars.downtime = ""
vars.kind = ""
vars.name = display_name
vars.zone = zone
}
and it works!!
Thank you very very much!
Luca
1 Like