Syntax question: variable as a command argument

Hi all,
some environment information first:
Icinga version: 2.11.3-1
OS: RHEL 7.6

Issue: I’m trying to configure a command to set a parameter using a variable content (string) as name, if the variable is filled.

Requirements:
The generated command should be either:
${PluginDir}/check_os_bond_mon #if variable is empty
or
${PluginDir}/check_os_bond_mon <variable_content> #if variable is filled

Just adding the variable to the command is not the solution, because this will cause an empty string being added, if the variable is empty. This empty string will be counted as an argument, which will cause the script to change its behaviour and to evaluate this “empty” parameter.

Example:

command = [ PluginDir + "/check_os_bond_mon", "$bond_iface_name$" ]

leads to:
${PluginDir}/check_os_bond_mon ‘’

instead of just:
${PluginDir}/check_os_bond_mon
if the variable is empty.

My command config:

object CheckCommand "os_bond" {
  import "plugin-check-command"
  command = [ PluginDir + "/check_os_bond_mon" ]
  arguments += {
    "$bond_iface_name$" = {
      set_if = "$os_bond_iface_name$"
    }
  }
  vars.bond_iface_name = "$os_bond_iface_name$"
}

I tried following strings as argument name so far:

"$bond_iface_name$" = {
"$os_bond_iface_name$" = {
"macro($bond_iface_name$)" = {
"macro($os_bond_iface_name$)" = {

All those lines are accepted by “icinga2 daemon -C”, but none of it is adding the string, if the variable is filled. What’s the correct syntax to beam the variable content into the argument name?

Thanks a lot.
Best regards,
Dirk

The following hasn’t been tested, but please try:

object CheckCommand "os_bond" {
  import "plugin-check-command"
  command = [ PluginDir + "/check_os_bond_mon" ]
  if (vars.bond_iface_name) {
    command += [vars.bond_iface_name]
  }
}

The same should actually work with arguments too.

Also if the $$ expansion won’t work with setif (sometimes it doesn’t and I’ve never figured out why), you may try set_if = {{ if ( "$some_variable$" ) { return 1 } else { return 0 } }}.