NSClient++ Help (#1) - Can't get PowerShell? scripts to accept arguments (#915) - Message List
I've been trying to understand how I can parse arguments to PowerShell? scripts using NSClient++. I've read some threads and I think I am doing everthing I think I should but it doesn't work.
http://www.nsclient.org/nscp/discussion/topic/637
The problem is that the arguments PowerShell? sees are just $ signs.
So in my NSC.ini file I have:
[Script Wrappings] ps1=cmd /c echo scripts\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -
[Wrapped Scripts] test_powershell=test_powershell.ps1 $ARG1$ $ARG2$
My PowerShell? script is as follows:
$Argument1 = $args[0] $Argument2 = $args[1] $ExitCode = 0 Write-Host "Argument1 Begin: " -noNewLine Write-Host $Argument1 -noNewLine Write-Host " :End " -noNewLine Write-Host " Argument2 Begin: " -noNewLine Write-Host $Argument2 -noNewLine Write-Host " :End " -noNewLine exit $ExitCode
When I run the script directly on the server using the following command:
test_powershell.ps1 test1 test2
I get the output:
Argument1 Begin: test1 :End Argument2 Begin: test2 :End
And this is how the script should work.
When I call the script from my Nagios server using the following command:
./check_nrpe -H 192.168.100.43 -t 30 -c test_powershell test1 test2
I get the output:
Argument1 Begin: $ :End Argument2 Begin: $ :End
You can see that the arguments test1 and test2 are not making it to PowerShell?, only $ signs are.
What am I doing wrong here?
-
Message #3021
Hey Box293,
did you find a solution for that problem? i have the same issue :)
greetz
bongface01/23/13 09:54:04 (4 months ago)-
Message #3121
YES I just worked it out, I typed the command incorrectly!
The problem is I am missing the -a option after the command BEFORE the arguments.
When I call the script from my Nagios server using the following command: ./check_nrpe -H 192.168.100.43 -t 30 -c test_powershell test1 test2
The command should be:
./check_nrpe -H 192.168.100.43 -t 30 -c test_powershell -a test1 test2
Which gives the output:
Argument1 Begin: test1 :End Argument2 Begin: test2 :End
Thanks for giving this thread a bump bongface, I wanted to get this one sorted out.
Box29304/25/13 12:28:23 (4 weeks ago)
-
-
Message #3024
Script:
write-host "UNKNOWN: Everything is not going to be fine $($args.count) $args!" exit 1
Config:
[/modules] CheckExternalScripts = enabled [/settings/external scripts/wrapped scripts] foo=check_test.ps1 a b c
Running it:
foo debug core Injecting: foo... debug ext-script Arguments: /c echo scripts\check_test.ps1 a b c; exit($lastexitcode) | powershell.exe -command - debug core Result foo: WARNING message client WARNING:UNKNOWN: Everything is not going to be fine 3 a b c!
So yes, seems to work for me...
Michael Medin
mickem01/23/13 23:00:08 (4 months ago)








