Use vars in host display_name

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 = “”
#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 = “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

Hi @gdhgdr32 , welcome :hugs: to the community.

Have you also tried the following approach? I have tried it on my system and it works quite well :relieved: I think.

  display_name = this.vars.customer + " " + this.vars.host_type


You’re a life saver Yonas, thank you so much, that’s exactly what I needed. I couldn’t even find the existence of “this.” in the docs.

Indeed - that’s a nice way of getting at the object’s variables.

I, too, had never noticed the use of “this” in the documentation, but after
having a pretty thorough search around, I’ve found a reference to “the ‘this’
scope” for variable names:

Language Reference - Icinga 2

I can’t help feeling that this should be repeated and emphasised, for example
in the Advanced Topics section, possibly alongside Apply Rules.


Hii @Pooh,

If you don’t want to explicitly call the this keyword, you can also do it that way vars.customer + vars.host_type, because it’s exactly the same. Therefore, it would be superfluous to document the this keyword, whereas it can be done without it.