Creating check command with unnamed parameters

Hi!

I need to call a PowerShell-Script on a Windows-Server to perform same checks.
The script need as parameter a string, but no “key” (e.g., it must be script blah and not script --blah).

I tried so:

object CheckCommand “check_eventlog” {
import “plugin-check-command”

command = [
“C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe”,
“-command”,
“& ‘C:\Program Files\NSClient++\scripts\evtsumup3\query.ps1’”,
vars.evlog_server,
]

timeout = 180s
}

Unfortunately, it does not work and I get an error from script, that no parameter was given.

If I add

arguments = {
“evlog_server” = {
value = “$evlog_server$”
}
}

I get a more confusing error:

Host and/or global config and/or exclude file is missing.

That I cannot explain… Maybe it is so because of friday, but can someone explain me where is the error?

Thanks
Luca

OK folks!

I got it! For someone other with the same problem, here my running configuration:

object CheckCommand “check_eventlog” {
import “plugin-check-command”

command = [
“C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe”,
“-command”,
“& ‘C:\Program Files\NSClient++\scripts\evtsumup3\query.ps1’”,
vars.evlog_server
]

arguments = {
“” = “$evlog_server$”
}

timeout = 180s
}

Have a nice weekend
Luca

Thank you for posting a working example.

This is very useful for people who search the archive in future.

And, congratualtions :slight_smile:

Antony.

Any particular reason why you are not using the NSClient, which seems to be installed, to run the script?

For the “powershell way” keep in mind that the check will exit with an OK state if the script is not present.
At least that is what I experienced with a similar check:

See my other topic Timeout exceeded with nscp-local the reason I tried to rewrite the check directly in Icinga…
BTW: I think, if I already have Icinga working on the server, another check program is waste, so I’m trying to rewrite all remaining checks that currently use NSClient++.

Regards
Luca

I did try the suggested solution and it doesn’t work at all.

The solution isn’t obvious from Icinga documentations but is relatively simple.

If you have a command which uses arguments directly from the command line you first need parameters to transform in local config group variables, and then you are able to use it in command attribute without using arguments attribute.

Exammple :
check_something argum1 argum2 argum3

CheckCommand block should like :

object CheckCommand "check_some" {

  vars.argum1 = "$host.vars.some1$"
  vars.argum2 = "$host.vars.some2$"
  vars.argum3 = "$service.vars.some1$"

  command = [ PluginDir + "/check_something",
              vars.argum1,
              vars.argum2,
              vars.argum3 ]
}

Just a “FYI”:
You can also use the skip_key and order values for each argument.
With these Icinga will ignore what you put in as a parameter and set your values in your specified order.
See command-arguments-skip-key

arguments = {
    "--process" = {
      value = "$icingacli_businessprocess_process$"
      description = "Business process to monitor"
      skip_key = true
      required = true
      order = -1
    }
  }
1 Like