2

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?

1 Answer 1

3

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:

[/settings/external scripts/scripts]
x=scripts\\check_test.bat $ARGS$
y=scripts\\check_test.bat $ARGS"$

Executing the unquoted version:

x 1 "2 3" 4 5
D ext-script Command line: scripts\\check_test.bat 1 2 3 4 5
L     client OK: Test arguments are: (1 2 3)

Executing the quoted version:

y 1 "2 3" 4 5
D ext-script Command line: scripts\\check_test.bat "1" "2 3" "4" "5"
L     client OK: Test arguments are: ("1" "2 3" "4")
3
  • Michael, thank you for authoritatively confirming this. I hoped to avoid having to do this from within the script as it adds to complexity.
    – the-wabbit
    Nov 26, 2013 at 14:54
  • Well, as I said, add a ticket and you will be notified when it is added, the reason I don't just add this is I am unsure how to add it ie. should it be an option "ignore empty args=true" or should it be a special keyword like $ARG*$ etc etc, so let me know what you think would be best and I will add it) Nov 27, 2013 at 9:15
  • Michael, I very much likee the $ARG*$ idea due to the backward compatibility and simplicity of use. I've filed nsclient.org/nscp/ticket/670#ticket as an enhancement request, thank you for pushing me towards it.
    – the-wabbit
    Nov 27, 2013 at 10:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .