NSClient++ Help (#1) - calling powershell with arguments [SOLVED] (#637) - Message List
Hello everybody,
I been trying to call powershell with CheckExternalScripts module, if I call it like this (saw it in another thread) it works ok,
test_script=cmd /c echo scripts\powershell.ps1 | powershell.exe -command -
but if I want to pass an argument to the powershell script, like this (doesn't work, as expected, since is redirecting output and input) test_script=cmd /c echo scripts\powershell.ps1 $ARG1$ | powershell.exe -command - or test_script=cmd /c echo scripts\powershell.ps1 | powershell.exe -command -arg $ARG1$ -
it won't run. Is there any way to call powershell effectively with arguments?
thanks!
-
Message #1906
Look at the "Wrapped Scripts" section in the latest version. It will "help you" with all that.
+ Added new "script templating" thing to simplify adding scripts: Two new sections: [Script Wrappings] for adding templates and [Wrapped Scripts] for adding the scripts. %SCRIPT% is replaced with the script name %ARGS% is replaced with arguments. vbs=cscript.exe //T:30 //NoLogo scripts\wrapper.vbs %SCRIPT% %ARGS% and w_vbs=check_test.vbs /arg1:1 /arg2:1 /variable:1 is the same as: w_vbs=cscript.exe //T:30 //NoLogo scripts\wrapper.vbs check_test.vbs /arg1:1 /arg2:1 /variable:1 * Added correct syntax for VB scripts * Added correct syntax for powershell scriptsThere you just put:
[Wrapped Scripts] check_test_ps1=check_test.ps1 arg1 arg2 $ARG1$
The proper syntax (if you don't wanna use this) can be found in the other section mentioned:
cmd /c echo <SCRIPT> <ARGS>; exit($lastexitcode) | powershell.exe -command -
Michael Medin
mickem07/28/10 17:41:09 (19 months ago)-
Message #1911
Worked great. Thank you for your fast response!
[Script Wrappings] ps1=cmd /c echo scripts\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -
[Wrapped Scripts] TareaBackup=BackupExec.ps1 exchange
jorgemestre07/29/10 12:20:08 (19 months ago)-
Message #2336
Maybe i can piggy-back on this thread..
What happens if powershell is getting only empty arguments, despite the script wrapper being active?
logparser=logparser_args.ps1 $arg1 $arg2
This is my call for the powershell script and nsclient seems to loose the arguments that nagios is sending (I can see them when i run nsclient /test and allow_arguments=1 is set). Does the wrapper need a modification to work with multiple arguments or is just my call for the script wrong?
Sebastian10/13/11 11:11:57 (4 months ago)-
Message #2337
Humm, $arg1 seems wrong think it whould be $ARG1$ or maybe $arg1$ note sure of the top of my head...
But this is a simple string replacement so... Given:
- script=foo
- arguments=1 2 3 4
Then this:
ps1=cmd /c echo scripts\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -
Will turn into this:
ps1=cmd /c echo scripts\foo 1 2 3 4; exit($lastexitcode) | powershell.exe -command -
In your case though getting script and arguments set could be what breaks... but for instance:
bar=foo $ARG1$ $ARG2$ $ARG3$ $ARG4$
called like so:
bar 1 2 3 4
should translate to:
- script=foo
- arguments=1 2 3 4
(ish)
Michael Medin
mickem10/13/11 15:06:33 (4 months ago)-
Message #2338
You are right, my own error put me into this place. After replacing $arg1 (which i just copied from the [Wrapped Scripts] of the nsc.ini without checking) with $ARG1$, it just works.
Thank you for clearing that up, lets hope no one else falls into the trap of copy&paste.
Sebastian10/13/11 16:33:17 (4 months ago)
-
-
-







