Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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)
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.
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)
That wouldn't be necessary because the OP has the path of perl as the interpreter line in his perl script.
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
}
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:
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.
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
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:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.