Set_if to remove argument

Hello everyone!
I hope everybody is safe and healthy right now. Here in Canada we are holding on.

At the moment we have some hosts with older versions of Ubuntu (will be migrated eventually…) and those servers don’t allow us to use SSL. We have created a variable $NOSSL$ (-n) that we pass to those servers specifically.

Our cpu load check, however, doesn’t like having the $NOSSL$ parameter empty with those servers that allow SSL. I was thinking about using “set_if” in the command definition so when $NOSSL$ equals “-n” then you use it, and if it’s empty, you don’t use the parameter at all.

object CheckCommand “cmd-check-cpu-load” {
command = [PluginDir + “/check_nrpe”]

    arguments +=  {
       "-n" = {
                    value = "$NOSSL$"
                    set_if = "$NOSSL$"
                    skip_key = true
             }
       "-H" = "$HOSTNAME$"
       "-t" = "60"
       "-c" = "$ARG1$"
       "-a" = "$ARG2$"
    }

}

Clearly that line is wrong : set_if = “$NOSSL$”

I would like to be able to do something like this : set_if = “if $NOSSL$ == ‘-n’”

Is it something that can be done?

Thank you so much!
Gen

Hello,

why does everyone and his mother define new commands for nrpe when there is a nrpe command already in the ITL? Use this command and set your variables right in your service and you dont have to think about how you can write a new command. Icinga2 is not like icinga1/nagios/check_mk where you have to create tons of command definition for the same plugin. Please read the docs!

For your command you dont need to set a value and skip_key, just the set_if is needed.

Regards,
Carsten

@Carsten

ok I will do that.
It’s just the way my team used to do it with Nagios and I never realised their script was standard.

So is this running through NRPE? I don’t see any argument to specify the Host… usually “-H”.

(yes I will put the load data in my template…it’s just for testing purposes)

apply Service “load” {
import “generic-service”

check_command = “load”

vars.load_wload1 = “25”
vars.load_wload5 = “100”
vars.load_wload15 = “100”

vars.load_cload1 = “30”
vars.load_cload5 = “100”
vars.load_cload15 = “100”

assign where “common-checks-ubuntu-server-24x7” in host.groups || “common-checks-centos-server-24x7” in host.groups || “common-checks-xenserver-host-24x7” in host.groups

}

@anon66228339 Writing you again, just in case you missed my reply…

Hi,

depends on how your nrpe is configured a icinga2 service could look like

apply Service "load" {
    import “generic-service”

    check_command = "nrpe"

    vars.nrpe_command = "load"
    vars.nrpe_no_ssl = true
    vars.nrpe_arguments = [ "25", "100", "100", "30", "100", "100" ]

    assign where “common-checks-ubuntu-server-24x7” in host.groups || “common-checks-centos-server-24x7” in host.groups || “common-checks-xenserver-host-24x7” in host.groups
}

Better would be to drop nrpe as agent and use icinga2, but i know its not always possible.

@anon66228339

Exactly, it’s unfortunately not possible at the moment but it’s always in the back of my mind to make the switch one day.

I’ll try your suggestion and let you know.

thank you again!