Nagios - interprets perl plugin output as (null)
Hi,
I developed my first Nagios plugin from scratch and I'm getting some issues regarding the way nagios interprets its output. Execution from CLI returns good output (even $? is as 0), but nagios interface recognizes it as CRITICAL witn an output of '(null)'. From command line: Quote:
Quote:
Code:
#!/usr/bin/perl -w Well, I'm hoping this is a very simple issue. All similar issues I've seen either end up related to perl 'use' clause (libraries or paths) or with permissions. Best regards, sburnay |
What is your services.cfg entry for this? Are <my_UPS_IP> <my_Community> hard coded values in the command.cfg or are you passing them as variables from services.cfg? If so how have you defined the variables in the command.cfg? How have you separated them in the services.cfg?
|
Well, I give the args directly in the command definition (commands.cfg),
which means I pass directly the host IP address (lets say 192.168.1.20) and SNMP community surrounded by ''s (as in 'myCommunity'), I don't use the $HOSTADDRESS$ nor a predefined $USERx$ for SNMP community. In my service definition (services.cfg) I only call the command which is defined in commands.cfg (no arguments given on ervice definition) Code:
# 4 C-Consumo_Energia |
I may be wrong about this, but from the scripts I've written in Bash for Nagios, the exit status number (0,1,2) is what tells Nagios whether it is OK, Warning or Critical (optionally 3 for Unknown). The output text is arbitrary as far as Nagios is concerned and is just for the user's information.
|
Yes serosensteinq,
And I've checked the '$?' system variable's value after execution of the script (either wuth the nagios user and root), it always came with the suposely correct value of 0 (zero = OK). I even followed a sugestion I found on another forum of disabling the Nagios' perl interpreter, setting the 'enable_embedded_perl=0', but without results. |
Just to make sure, nagios is running under the "nagios" user, right?
I know you said you didn't need to include the $USER$ variable in the commands.cfg, but have you tried adding it? Also, Have you tried the full path of perl? (Although it shouldn't be needed either) command_line /usr/bin/perl /usr/local/nagios/libexec/my_get_consumo_ups.pl <my_UPS_IP> <my_Community> |
Quote:
The prompt of his original command line above shows he is running as the nagios user when testing from command line. Hopefully the nagios process is also running as that user when he starts it. |
Yes, I saw that the command from the command line was being run as Nagios, and I assumed that the process was as well, but it never hurts to check.
Also, I know that the script defines the interpreter and that it shouldn't be necessary, just as adding the $USER$, but those are just some of the steps I would personally go through. |
I'm having the same issue. Please see the relevant config info from Nagios:
define service{ use unix-linux-service ; Name of service template to use host_name RandomBox service_description Database Partition check_command check_nix_disk!/dev/mapper/z-db!10!85 } # 'check_nix_disk' define command{ command_name check_nix_disk command_line /usr/bin/perl $USER1$/NagiosPlugin/check_disk.pl -H $HOSTADDRESS$ -F $ARG1$ -w $ARG2$ -c $ARG3$ } I've disabled nagios embedded perl, and as you see above, I'm using the full path to my perl to run this script. From the NAGIOS Gui, this will get expanded to: To expand: check_nix_disk!/dev/mapper/z-db!10!85 check_nix_disk /usr/bin/perl $USER1$/NagiosPlugin/check_disk.pl -H $HOSTADDRESS$ -F $ARG1$ -w $ARG2$ -c $ARG3$ -> /usr/bin/perl $USER1$/NagiosPlugin/check_disk.pl -H $HOSTADDRESS$ -F /dev/mapper/z-db -w 10 -c 85 Running the check_disk.pl from the command line (as root) gives this: # /usr/bin/perl /usr/lib/nagios/plugins/NagiosPlugin/check_disk.pl -H 172.22.24.196 -F /dev/mapper/z-db -w 10 -c 85 DISK WARNING: Used=38% (Size: 20G, Available: 12G) Running as nagios gave me problems due to permissions. After fixing these, I now get this (as nagios): nagios@myhost:/usr/lib/nagios/plugins/NagiosPlugin> /usr/lib/nagios/plugins/NagiosPlugin/check_disk.pl -H 172.22.24.196 -F /dev/mapper/z-db -w 10 -c 85 DISK WARNING: Used=38% (Size: 20G, Available: 12G) For testing I have printed the input from command line to check_disk.pl; When this script runs from Nagios, it does not create the file. I use m// for checking in my perl script. It seems that the special variables come back empty when the script is called from Nagios. When it is called from the command line, they work fine. Any further ideas? |
According to this page:
http://nagios.sourceforge.net/docs/3...eddedperl.html You can tell the perl script itself not to use the Nagios embedded perl (starting with Nagios v3.x) even if it is used for other scripts by adding: nagios: -epn within the first 10 lines of the perl script for Nagios to detect it. The page suggests that is a good debugging step to rule out embedded perl. It also notes that embedded perl directives in nagios.cfg only have effect if you originally compiled with embedded perl options explicitly set. Reviewing your config log in the directory where you original ran the configure command and subsequent makes should show if you have it enabled. You should see a line like: configure:8260: result: Embedded Perl: no |
Quote:
Quote:
I'm in a hurry right now, but tomorow I will try to give the '/usr/bin/perl' as prefix of command_line in the command definition. I will also explore the link sugested (http://nagios.sourceforge.net/docs/3...eddedperl.html) |
Hi again; I'm using NagiosŪ Core™ 3.3.1
I tried placing the below line early in my scripts. # nagios: -epn Also I set the below in nagios.cfg enable_embedded_perl=0 use_embedded_perl_implicitly=0 Where before I had only set enable_embedded_perl=0. This didn't help either after restarting Nagios. I'm wondering is there a way to tell if Nagios embedded perl is running these scripts? Or better, can I somehow run my check_disk.pl script from Linux command line using Nagios embedded Perl? I tried changing the first line of my script to: #!/usr/lib/nagios/p1.pl But got no output. |
I didn't find a way to tell which options the compiled Nagios was compiled with. However as noted above if you did the compile yourself and have the original directory in which you ran the configure and make steps then you should have a config.log that shows what options were used. If it wasn't configured with embedded perl (which is default) you should see a line like:
configure:8260: result: Embedded Perl: no The subsequent make would use that to NOT include embedded perl support in the compile. Presumably that "no" would be "yes" if it WAS configured with embedded perl. On my 3.x installation we have this set to no and haven't had any issues running perl scripts in Nagios. |
My issue is resolved. My plugin does file IO and wasn't opening a file for reading. Works from the command line possibly because I ran the script from the same directory as the script. Nagios runs the script from absolute path in another working directory.
sburnay: I would recommend you try running your script as nagios, from a different working directory, using an absolute path to run the script. See if it still works for you. Otherwise, ensure that you are using absolute paths where possible. |
Solved
Well, sorry for the long time to reply,
In the meanwhile I had devoleped a shell script to do the same thing as my original perl script. In thr Nagios Support Forum someone sugested changing Quote:
Quote:
Thank you for the brainstorming. |
Thanks for posting your solution. Please go to thread tools and mark this thread as closed. It helps others in future web searches find solutions more quickly.
|
All times are GMT -5. The time now is 10:40 PM. |