Constants in CheckCommand arguments

I’ve been battling this for a bit, but I’m trying to figure out how to use a “const” in a command argument. For some reason, whenever I use the $const_name$ as the value of the argument, it silently gets removed.

for example:

I have a const.conf file that defines the following:

const const_name = {
  "blah" = {
    blahblah = "11045"
  }
}

and elsewhere, I have a check command template that looks like this:

template CheckCommand "testing" {
    import "plugin-check-command"
    command = [ PluginDir + "/custom/check_test" ]
    arguments += {
        "--const" = "$const_name$"
        "-h" = "$host.address$"
        "-p" = "$password$"
        "-u" = "$username$"
    }
}

but when the check command runs, all arguments are present, except the “–const”. It simply disappears.

If I run icinga2 variable get const_name I do indeed get the appropriate value, so I do know that the config loaded the const correctly.

(running icinga r2.13.2-1 on ubuntu 22.04)

PluginDir is a constant so just try to use --const = blah.

Unfortunately, (guess I should have mentioned it) Director forces the quotes around the “value” field. I did try manually creating the template, but now the icinga daemon won’t start with the error

critical/config: Error: Validation failed for object 'check_test' of type 'CheckCommand'; Attribute 'arguments' -> '--const': Invalid type.

(check_test is a command that imports testing)

I think I’m making some progress… the “const_name” is an array, which I was hoping would be passed as a string. I tried to use json.encode() on it, but it is complaining with “Error: Argument is not a callable object.” whenever the check command is executed.

specifically, I tried using {{ return json.encode(const_name) }}

Does anyone know of a good way to json encode a variable into a single line that is useable?

I managed to sort-of make this work by setting the const to a single-line json encoded string. Is there no way to json encode a variable to use it as an argument?

The command definition is one of the few places where Icinga DSL can be used in the Director.

Maybe it’s the same for constants like it is for variables and the macro() needs to be used to get the value.

https://icinga.com/docs/icinga-2/latest/doc/18-library-reference/#macro

So maybe it needs to be of valuetype Icinga-DSL and look like, in the end:

{{ return json.encode(macro(const_name)) }}

Also it looks like the director adds the {{ }} by itself

image