CheckCommand - set_if


I’ve setup a CheckCommand with 2 parameters. Both parameters are taken from the host config and the values are derives. I would like to skip the second parameters whenever a host var is not existent.
So I used - set_if = “$host.test1$” but it doesn’t seem work. Maybe I’m not setting it up properly. I referred the documentation but couldn’t figure out the cause.

Please advise

do you use icinga director.
as i remember that is a bug.
i had a similar problem with:
hosttemplate var → service templatevar → command
and icinga always thought that the var is not empty.
I did the following workaround:
adapt the script to ignoring the parameter if empty or “”
add quotation to the command var
so icinga always executes like that => command -parameter1 “test” - parameter2 “”

I don’t use director. Not sure how to do that in the config file. All I need is not to set the parameter if a specific host var doesn’t exist.


I think this should be $host.vars.test1$. And if this variable isn’t a boolean type it won’t work for a set_if, as this expects true/false.

Have you had a look at if/else conditional statements?
I think that could work: Language Reference - Icinga 2

if ($yourvar$){
  $your2ndvar$ = true
else {
  $your2ndvar$ = false

And then have the set_if of your command argument look at $host.vars.your2ndvar$

1 Like

Thanks. I will try that in the “apply” or CheckCommand object.

Another question I’ve is -

How do I get the complete “CheckCommand” which gets constructed to run?


You can get that via the API:

curl -k -s -S -i -u user:password 'https://localhost:5665/v1/objects/services/hostname!servicename'

In the JSON output you then have

"last_check_result": {
					"active": true,
					"check_source": "some-server",
					"command": [
						"'/usr/lib64/nagios/plugins/check_procs' '-C' 'chronyd' '-c' '1:' '-w' '1:'",
1 Like