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?
Best Answer
First off the %ARGS% tingy is for a wrappers (which is something else), perhaps I should rename that $ARGS$ to make it less confusing?
Anyways NSClient++ as of before 0.4.2.61 does not support variable arguments. This was added in 0.4.2.61 however as per request in this ticket.
As of NSClient++ 0.4.2.61 there are two new options $ARGS$ and $ARGS"$ the latter will quote all strings.
Configuration in nsclient.ini:
Executing the unquoted version:
Executing the quoted version: