I’m trying to dynamically generate the display_name value for Hosts in my environment. Ideally I’d like to do this using the vars that I have set on that host. I’ve attempted to accomplish this in a handful of ways, but nothing seems to work (though I wouldn’t be surprised if I’m doing it wrong). I’ve included a few of the attempts (but there were many more) in my example host below. My latest attempt was the uncommented bit, which resulted in a pass through the config checker, but the display_name value shows up as " Object of type ‘Function’" in the Icinga GUI
I’ve seen examples for Services where you can do this very simply (E.G., display_name = $host.vars.customer$ + $host.vars.host_type$) so I’m lost as to why that doesn’t work for Hosts. Is this just not possible or is there a different way to accomplish this?
Example host:
object Host “dcn_dcnproddeploy01” {
import “dcn-hdos-splunk-host”
vars.splunk_roles = [“Deployment Server”, “License Master”]
vars.aliases = [“ccnproddeploy01.bla”]
vars.hl_splunk_gui_url = “https://ccnproddeploy01.bla:$vars.splunk_port$”
vars.client_splunk_gui_url = “https://ccnproddeploy01.bla:$vars.splunk_port$”
vars.site_location_identifier = “NA”
vars.cluster_number_identifier = “1”
display_name = {{
var test;
var r = macro("$host.vars.customer$");
test = r.to_string();
return test
}}
address = “1.2.3.4”
#display_name = $host.vars.customer$ + $host.vars.host_type$
#display_name = “$host.vars.customer$” + “$host.vars.host_type$”
#display_name = $host.vars.customer$ $host.vars.site_location_identifier$ $host.vars.host_type$ $host.vars.splunk_roles$ $host.vars.cluster_number_identifier$
#display_name = {{ $host.vars.aliases$ }}
}
The import:
template Host “dcn-hdos-splunk-host” {
import “generic-host”
vars.os_type = “hdos”
vars.host_type = “Splunk”
vars.customer = “DCN”
vars.org_name = “dcn”
vars.has_nrpe = true
vars.team = “splunk”
}
- root@:~# icinga2 --version
icinga2 - The Icinga 2 network monitoring daemon (version: r2.12.3-1)
Platform: Ubuntu
Platform version: 18.04.5 LTS (Bionic Beaver) - Enabled features: api-users api command compatlog ido-mysql mainlog notification statusdata