NSClient++: external script with optional arguments

Posted by syneticon-dj on Server Fault See other posts from Server Fault or by syneticon-dj
Published on 2013-11-11T21:05:16Z Indexed on 2013/11/11 21:56 UTC
Read the original article Hit count: 1306

Filed under:
|

I am trying to define an external script which would take optional arguments in NSClient++ 0.4.1 on Windows. Following the nsclient-full.ini example code I have defined

mycheck=cmd /C echo C:\mydir\myscript.ps1 %ARGS% | powershell.exe -command -

which simply yields the string %ARGS% passed as the only argument to myscript.ps1, no matter what I specify in my call through NRPE (using Nagios' check_nrpe if that matters). I then tried to rewrite the definition to

mycheck=cmd /C echo C:\mydir\myscript.ps1 $ARG1$ $ARG2$ | powershell.exe -command -

(myscript.ps1 would take up to two arguments), which does help a bit. At least, if two arguments are provided, I can fetch them via the args[] array. The trouble starts when the call has less than two arguments - in this case the literal strings $ARG2 and $ARG1$ are passed through as arguments. Handling this case in the code of myscript.ps1 makes the whole argument processing routine ugly at best.

Is there a sane way of defining optional parameters to an external script which would not pass NSClient's variable names if no parameter has been specified?

© Server Fault or respective owner

Related posts about nrpe

Related posts about nsclient++