Icinga 2: Using functions in custom attributes

Starting with version 2.2 Icinga supports arrays and dictionaries in custom attributes. In combination with apply this is incredibly powerful, e.g. to define HTTP vhosts for a host and to set up individual services for each of these vhosts.
Version 2.3 – which we’re planning to release on the 10th of March – will introduce support for using functions in custom attributes:

object CheckCommand "random-text" {
  import "plugin-check-command"
  command = [ PluginDir + "/check_dummy", "0", "$text$" ]
  vars.text = {{ Math.random() * 100 }}

The two curly braces are used to define a function. Icinga runs this function every time it needs the value for the custom attribute “text”. In this example this results in a new random value each time this check command is executed.
However, using functions we’re not limited to calculating simple values. Users can use if/else to accomplish more complex things:

vars.text = {{
  if (host.address == "") {
    log("This is a check for localhost.")
  return "Test"

We can also access arbitrary attribute for other hosts and services:

vars.text = {{
  "The state for 'other-host' is: " + get_host("other-host").state