CheckCommand conditional command

Hi,
I wrote a small wrapper to have an “always OK” configuration for check commands if needed.

The use case is let a service exit with OK even if the executed plugin exits with WARNING or CRITICAL.

I need this feature only for a few services, so I’m trying to hack the command definitions to execute this wrapper if needed:

object CheckCommand "_check_pve" {
    import "ipv4-or-ipv6"

    if (vars.pve_always_ok == true) {
        vars.check_command = [ "/opt/icinga2-plugins/always-ok", "/opt/icinga2-plugins/check_pve.rb" ]
    } else {
        vars.check_command = [ "/opt/icinga2-plugins/check_pve.rb" ]
    }

    command = vars.check_command

    arguments = {
        [...]
    }
}

I added the variable pve_always_ok to the Service definition:

Screenshot 2023-04-27 at 11.52.48

But it is not working:

If I try changing the command definition condition to:

    if (true) {
        vars.check_command = [ "/opt/icinga2-plugins/always-ok", "/opt/icinga2-plugins/check_pve.rb" ]
    } else {
        vars.check_command = [ "/opt/icinga2-plugins/check_pve.rb" ]
    }

it works:

Could you please help me to understand where I’m wrong in the following statement:

if (vars.pve_always_ok == true) {

Thank you very much!

Bye

I would use a service object instead e.g.:

apply Service "check-pve" {
    if (vars.pve_always_ok == true) {
        check_command = "dummy"
        vars.dummy_state = 0
    } else {
        check_command = "check_pve"
    }

...

}