NSClient++ Help (#1) - arguments problem using perl (#953) - Message List
hi
I'm using 0.3.9 and need to use perl.
I did a file.pl for test without arguments and worked OK, from local (the windows where nsclient is installed) and from my nagios server.
but when I want to use a perl script with arguments there is a problem.
I have a perl script that localy (using strawberry console) works fine with arguments, but when a call it from my nagios server the logs says that perl.exe returned a 255 error
for external commands I have:
check_perl=C:\strawberry\perl\bin\perl.exe scripts\prueba.pl $ARG1$ $ARG2$ $ARG3$
and the logs says:
2012-04-12 16:47:06: error:modules\CheckExternalScripts\CheckExternalScripts.cpp:214: The command (C:\strawberry\perl\bin\perl.exe) returned an invalid return code: 255
I repeat, the script works fine localy, so there is no sintaxis problem, the problem comes when I call it remotely.
thanks!
-
Message #2521
First step:
cd <nsclient> C:\strawberry\perl\bin\perl.exe scripts\prueba.pl <arg1> <arg2> <arg3> echo %ERRORLEVEL%
Second step:
cd <nsclient> nscp test ... check_perl <arg1> <arg2> <arg3>
Then you check from nagios command line...
But check that you allow arguments TWICE (once for NRPE and once for external scripts)!
Michael Medin
mickem04/12/12 23:17:53 (14 months ago)-
Message #2524
thanks fir answer
first, yes, I have allow arguments in both NRPE and external scripts (also nasty chars)
second, I tried
C:\strawberry\perl\bin\perl.exe scripts\prueba.pl <arg1> <arg2> <arg3>
and works fine
then I tried
nscp test ... check_perl <arg1> <arg2> <arg3>
and there is a problem, the logs shows:
2012-04-12 17:23:32: debug:NSClient++.cpp:1144: Injecting: check_perl: 192.168.7.36, 80, 5 2012-04-12 17:23:39: error:modules\CheckSystem\PDHCollector.cpp:215: Failed to query performance counters: \Processor(_total)\% Processor Time: PdhGetFormattedCounterValue failed: A counter with a negative denominator value was detected. (800007D6)
the commas in "192.168.7.36, 80, 5" are correct?
any suggestion?
tc04/12/12 23:27:43 (14 months ago)-
Message #2525
Yeah thats how the log messages splits arguments...
The interesting bit with running from command line was the echo %ERRORLEVEL% part after as it will show you the exit status of the script.
But from your log it seems the command "hangs" what does it do BTW?.
Could you let the command run (when you run it from nscp test) run for a minute or so and see what happens?
Michael Medin
mickem04/12/12 23:40:40 (14 months ago)-
Message #2529
hi, i am having strange behaviour lately
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl $ARG1$ cannot be resolved into an IP address at scripts\prueba.pl line 57. [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 CHECK_NRPE: Socket timeout after 10 seconds. [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 CHECK_NRPE: Socket timeout after 10 seconds. [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 80 5 CHECK_NRPE: Socket timeout after 10 seconds. [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl_prueba probando... [root@nagios libexec]#
in this
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl $ARG1$ cannot be resolved into an IP address at scripts\prueba.pl line 57.
the command is intensionally wrong (without arguments) for testing, but the strange is that the alias seems to send anyway the ARG1 not as argument but as text plain.
then in
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 CHECK_NRPE: Socket timeout after 10 seconds.
there is one argument (the script works with three), but a get a timeout error
then in
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 80 5 CHECK_NRPE: Socket timeout after 10 seconds.
there are the three arguments, but again there is timeout
finally I tested other perl script here
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl_prueba probando... [root@nagios libexec]#
that just print text when I call it.
so, my idea is that there is a problem using arguments.
the script that I trying to use is a TCP ping for windows, which receive three arguments: a target, a port and a delay time
thanks !
tc04/13/12 21:12:09 (14 months ago)-
Message #2530
Arguments are only replaced when they are found so getting$ARG1$ is "correct" (albeit perhaps not the behavior you want). In other words you might say it is the arguments which defines what gets replaced (not the command definition).
Why not create a simple perl script which just prints the arguments it gets (both to stdout and to a file?) ?
Michael Medin
mickem04/13/12 22:05:05 (14 months ago)-
Message #2532
something like this?
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl 192.168.7.36 80 5 $ARG1$ cannot be resolved into an IP address at scripts\prueba.pl line 57. $ARG1$ is the arguemnt 1 $ARG2$ is the arguemnt 2 $ARG3$ is the arguemnt 3 [root@nagios libexec]#
3 arguments are given, but the script seems to receive $ARGn$ as text and no as argument.
localy the script works ok, the issue is remotely.
thanks !
tc04/13/12 23:30:24 (14 months ago)-
Message #2533
Wait...
./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 80 5
Notice the -a before the argument list...
Have run into this one several times myself :)
Michael Medin
mickem04/14/12 06:38:04 (14 months ago)-
Message #2535
oh, my mistake, but there is something strange, look:
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 80 5 CHECK_NRPE: Socket timeout after 10 seconds. [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl 192.168.7.36 80 5 $ARG1$ cannot be resolved into an IP address at scripts\prueba.pl line 57. $ARG1$ is the arguemnt 1 $ARG2$ is the arguemnt 2 $ARG3$ is the arguemnt 3 [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 80 5 CHECK_NRPE: Socket timeout after 10 seconds. [root@nagios libexec]#
with the "-a" I get a timeout error, without the "-a" I get the ARGn error
thanks for your time
tc04/15/12 15:19:16 (14 months ago)-
Message #2536
Well... my guess is there is some issue with the script you are running or something is miss configured here is what I did to simulate the problem:
perl script (scripts\test.pl):
print("Arg1=$ARGV[0], arg2=$ARGV[1], arg3=$ARGV[2]"); exit(2);Configuration (nsclient.ini):
[/modules] ; Check External Scripts - A simple wrapper to run external scripts and batch files. CheckExternalScripts = 1 ; NRPE server - A simple server that listens for incoming NRPE connection and handles them. NRPE is preferred over NSClient as it is more flexible. You can of cource use both NSClient and NRPE. NRPEServer = 1 ; Section for external scripts configuration options (CheckExternalScripts). [/settings/external scripts] ; COMMAND ARGUMENT PROCESSING - This option determines whether or not the we will allow clients to specify arguments to commands that are executed. allow arguments = true ; COMMAND ALLOW NASTY META CHARS - This option determines whether or not the we will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments. allow nasty characters = true ; A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments> [/settings/external scripts/scripts] test_pl=C:\\strawberry\\perl\\bin\\perl.exe scripts\\test.pl \"$ARG1$\" \"$ARG2$\" \"$ARG3$\" ; Section for NRPE (NRPEListener.dll) (check_nrpe) protocol options. [/settings/NRPE/server] ; COMMAND ARGUMENT PROCESSING - This option determines whether or not the we will allow clients to specify arguments to commands that are executed. allow arguments = true ; COMMAND ALLOW NASTY META CHARS - This option determines whether or not the we will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments. allow nasty characters = true [/settings/default] ; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges. allowed hosts = 192.168.0.1Running from my linux box:
/usr/lib/nagios/plugins/check_nrpe -H 192.168.0.231 -c test_pl -a "Hello World" "Arg 2" "arg 3" Arg1=Hello World, arg2=Arg 2, arg3=arg 3
Which gives me the impression it is working as expected right?
Michael Medin
mickem04/15/12 19:21:12 (14 months ago)-
Message #2537
ok, I still with the issue, this is my conf:
in the perl script
print("arg0=$ARGV[0], arg1=$ARGV[1], arg2=$ARGV[2]");in the nsclient.ini
[modules] NRPEListener.dll CheckWMI.dll FileLogger.dll CheckSystem.dll CheckDisk.dll CheckEventLog.dll CheckHelpers.dll ;# NSCLIENT++ MODULES ;# A list with DLLs to load at startup. ; You will need to enable some of these for NSClient++ to work. ; ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ; * * ; * N O T I C E ! ! ! - Y O U H A V E T O E D I T T H I S * ; * * ; ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! FileLogger.dll CheckSystem.dll CheckDisk.dll NSClientListener.dll NRPEListener.dll ;SysTray.dll CheckEventLog.dll CheckHelpers.dll CheckWMI.dll CheckNSCP.dll ; ; Script to check external scripts and/or internal aliases. CheckExternalScripts.dll ;# USE THIS FILE ; Use the INI file as opposed to the registry if this is 0 and the use_reg in the registry is set to 1 ; the registry will be used instead. use_file=1 allowed_hosts=192.168.7.11 ; [NRPE] ;# NRPE PORT NUMBER ; This is the port the NRPEListener.dll will listen to. ;port=5666 ; ;# COMMAND TIMEOUT ; This specifies the maximum number of seconds that the NRPE daemon will allow plug-ins to finish executing before killing them off. command_timeout=60 ; ;# COMMAND ARGUMENT PROCESSING ; This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed. allow_arguments=1 ; ;# COMMAND ALLOW NASTY META CHARS ; This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments. allow_nasty_meta_chars=1 ; [External Script] ;# COMMAND TIMEOUT ; This specifies the maximum number of seconds that the NRPE daemon will allow plug-ins to finish executing before killing them off. command_timeout=60 ; ;# COMMAND ARGUMENT PROCESSING ; This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed. allow_arguments=1 ; ;# COMMAND ALLOW NASTY META CHARS ; This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments. allow_nasty_meta_chars=1 ; ;check_perl=C:\\strawberry\\perl\\bin\\perl.exe scripts\\prueba.pl "$ARG1$" "$ARG2$" "$ARG3$" check_perl=C:\\strawberry\\perl\\bin\\perl.exe scripts\\prueba.pl \"$ARG1$\" \"$ARG2$\" \"$ARG3$\" check_perl_prueba=C:\strawberry\perl\bin\perl.exe scripts\perl.pland what I get from Nagios:
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 I (0.3.9.327 2011-08-16) seem to be doing fine... [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 80 5 "192.168.7.36" cannot be resolved into an IP address at scripts\\prueba.pl line 58. arg0="192.168.7.36", arg1="80", arg2="5" [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a "192.168.7.36" "80" "5" "192.168.7.36" cannot be resolved into an IP address at scripts\\prueba.pl line 58. arg0="192.168.7.36", arg1="80", arg2="5" [root@nagios libexec]#
seems like nsclient when pass the arguments attach the " to it.
and again, locally and using the script for itself it works fine.
thanks !
tc04/16/12 21:19:18 (13 months ago)-
Message #2538
something interesting is that having:
check_perl=C:\\strawberry\\perl\\bin\\perl.exe scripts\\prueba.pl \" $ARG1$ \" \" $ARG2$ \" \" $ARG3$ \"
note the spaces around the \"
I get:
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a "192.168.7.36" "80" "5" \ cannot be resolved into an IP address at scripts\\prueba.pl line 58. arg0=\, arg1=192.168.7.36, arg2=\
the first arg is passed as I hope but in the second place
thanks!
tc04/16/12 21:42:28 (13 months ago)-
Message #2539
something even more interesting is this:
check_perl=C:\\strawberry\\perl\\bin\\perl.exe scripts\\prueba.pl \ $ARG1$ $ARG2$ $ARG3$
I get:
[root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a 192.168.7.36 80 5 \ cannot be resolved into an IP address at scripts\\prueba.pl line 58. arg0=\ arg1=192.168.7.36 arg2=80 [root@nagios libexec]# ./check_nrpe -H 192.168.7.46 -c check_perl -a "192.168.7.36" "80" "5" \ cannot be resolved into an IP address at scripts\\prueba.pl line 58. arg0=\ arg1=192.168.7.36 arg2=80 [root@nagios libexec]#
thanks !
tc04/16/12 21:49:21 (13 months ago)-
Message #2540
ok, the perl script is missing something, because now I can pass and show the arguments as I want, but the script can't hand it or the response is with something wrong. As I say, localy it works, and when I use the script it echoes what I want, but seems that those echoes can't pass through NRPE so show time out error.
tc04/16/12 21:57:34 (13 months ago)
-
-
-
-
-
-
-
-
-
-
-
-








