# CheckCommand conditional command

**URL:** <https://community.icinga.com/t/checkcommand-conditional-command/11880>\
**Category:** Events and Community\
**Tags:** icinga2\
**Created:** [April 26, 2023, 9:48pm UTC](https://community.icinga.com/t/checkcommand-conditional-command/11880 "2023-04-26T21:48:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![d83](https://community.icinga.com/letter_avatar_proxy/v4/letter/d/a4c791/32.png) [@d83](https://community.icinga.com/u/d83)\
**Post date:** [April 26, 2023, 9:48pm UTC](https://community.icinga.com/t/checkcommand-conditional-command/11880/1 "2023-04-26T21:48:43Z")

</div>

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:

```auto
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](https://community.icinga.com/uploads/default/original/2X/0/022fc7664df332c8718c275a509c977642ebe281.png)

But it is not working:

 ![Screenshot 2023-04-27 at 11.53.32](https://community.icinga.com/uploads/default/original/2X/e/e6f716fefbc95febc93c618ceadb82aa15161af7.png)

If I try changing the command definition condition to:

```auto
    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:

 ![Screenshot 2023-04-27 at 11.59.48](https://community.icinga.com/uploads/default/original/2X/5/575348d9feef067c04370c5d215a503c3a06faa6.png)

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

```auto
if (vars.pve_always_ok == true) {

```

Thank you very much!

Bye

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [May 16, 2023, 11:46am UTC](https://community.icinga.com/t/checkcommand-conditional-command/11880/2 "2023-05-16T11:46:06Z")

</div>

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

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

...

}

```
