Powershell – Why is the Powershell script returing extra output when run by Nagios NRPE

nagiosnrpepowershell

I have a Powershell script that I'm running via nrpe as an external script. The windows server (2008) is running nsclient++ (nscp.exe) v 0.4.1.102.

The return section of my powershell script looks like this

 } else {
                    write-host "ok $queue|queue = $queue"
                    exit 0
 }

And the wrapper script to call the ps1 file looks like this:

ps1 = cmd /c echo C:\\NetAdmin\\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -

If I run this from a windows command prompt the output looks something like:

ok 93|queue = 93

But when I run is using check_nrpe from my nagios server the output changes to:

ok 93|'queue''=0 '93'=0

Nagios is having an issue processing the performance data.

UPDATE:
After filing a bug report, the software author replied that this is desired behavior, but that there are two options for disabling it in the nsclient.ini:

Globally (All scripts)

[/settings/external scripts/scripts/default]
ignore perfdata = true

Single script

[/settings/external scripts/scripts/check_foo]
ignore perfdata = true

Best Answer

You should try to remove extra spaces around = sign :

write-host "ok $queue|queue=$queue"

By now i cannot explain this behaviour on this version of nsclient++. This is not happening on some previous versions like v0.3.8.76 which works like a charm (at least, as expected without surprises).

Seems that nsclient++ extends spaces as a data with a value of 0. It could be a bug or a wanted behaviour.

I am actually searching for some clues on the Internet, and will try to analyse source code.