NSClient++: external script with optional arguments
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")
Related videos on Youtube
the-wabbit
Updated on September 18, 2022Comments
-
the-wabbit almost 2 years
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 definedmycheck=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 tomycheck=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?
-
the-wabbit over 10 yearsMichael, thank you for authoritatively confirming this. I hoped to avoid having to do this from within the script as it adds to complexity.
-
Michael Medin over 10 yearsWell, 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)
-
the-wabbit over 10 yearsMichael, 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.