NSClient++ Help (#1) - calling powershell with arguments [SOLVED] (#637) - Message List
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?
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 scripts
There 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 Medinmickem07/28/10 17:41:09 (3 years ago)
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 exchangejorgemestre07/29/10 12:20:08 (3 years ago)
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 (20 months ago)
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:
- arguments=1 2 3 4
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:
- arguments=1 2 3 4
Michael Medinmickem10/13/11 15:06:33 (20 months ago)
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 (20 months ago)