SOLVED Script works from CLI but not from within nagios
Posted: Thu Aug 20, 2015 10:05 am
check_dirsize11.sh Script works from CLI as nagios user but not from within nagios
I have the check_dirsize11.sh script. It works from the command line as root and also as nagios. However, from within nagios the script is executed, but nagios shows an error in the gui.
Here is my service definition in localhost.cfg:
Here is my command from commands.cfg:
Here is the cli as root:
here is the cli as nagios:
here is the gui from nagios:
The error and log entries change based on the DU command inside check_dirsize11.sh
Line 46 of check_dirsize11.sh has this:
If I leave this line as is, the error in the gui reports permission denied. AND I get permission denied at the cli as nagios.
If I change line 46 to this:
then it runs properly from the cli as nagios and the error in the gui simply shows "Error:" as you see above
In the log file, if I use the sudo in the command, I see this: "[08-20-2015 10:51:31] Successfully launched command file worker with pid 21846"
If I do not use the sudo in the command, I only see this: "[08-20-2015 08:36:11] SERVICE NOTIFICATION: nagiosadmin;localhost;Backup Mount;UNKNOWN;notify-service-by-email;Error:"
I could sure use some help in sorting this out.
Thanks,
Jason
I have the check_dirsize11.sh script. It works from the command line as root and also as nagios. However, from within nagios the script is executed, but nagios shows an error in the gui.
Here is my service definition in localhost.cfg:
Code: Select all
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Backup Mount
check_command check_backup
}Code: Select all
# 'check_backup' command definition
define command{
command_name check_backup
command_line $USER1$/check_dirsize11.sh -d /mnt/backup -w 65000000000 -c 7500000000 -f
}Here is the cli as root:
Code: Select all
[root@sabrina libexec]# ./check_dirsize11.sh -d /mnt/backup -w 65000000000 -c 7500000000 -f
74709032 KB - ok|'size'=74709032KB;65000000000;7500000000
[root@sabrina libexec]#
here is the cli as nagios:
Code: Select all
[root@sabrina libexec]# su nagios
[nagios@sabrina libexec]$ ./check_dirsize11.sh -d /mnt/backup -w 65000000000 -c 7500000000 -f
74709032 KB - ok|'size'=74709032KB;65000000000;7500000000
[nagios@sabrina libexec]$
here is the gui from nagios:
Code: Select all
Current Status: UNKNOWN (for 1d 0h 16m 15s)
Status Information: Error:
Performance Data:
Current Attempt: 4/4 (HARD state)
Last Check Time: 08-20-2015 10:39:07
Check Type: ACTIVE
Check Latency / Duration: 0.000 / 0.019 seconds
Next Scheduled Check: 08-20-2015 10:42:07
Last State Change: 08-19-2015 10:24:08
Last Notification: 08-20-2015 09:39:09 (notification 25)
Is This Service Flapping? NO (0.00% state change)
In Scheduled Downtime? NO
Last Update: 08-20-2015 10:40:20 ( 0d 0h 0m 3s ago)
Active Checks:
ENABLED
Passive Checks:
ENABLED
Obsessing:
ENABLED
Notifications:
ENABLED
Event Handler:
ENABLED
Flap Detection:
ENABLED
The error and log entries change based on the DU command inside check_dirsize11.sh
Line 46 of check_dirsize11.sh has this:
Code: Select all
DU="/usr/bin/du"If I change line 46 to this:
Code: Select all
DU="/usr/bin/sudo /usr/bin/du"In the log file, if I use the sudo in the command, I see this: "[08-20-2015 10:51:31] Successfully launched command file worker with pid 21846"
If I do not use the sudo in the command, I only see this: "[08-20-2015 08:36:11] SERVICE NOTIFICATION: nagiosadmin;localhost;Backup Mount;UNKNOWN;notify-service-by-email;Error:"
I could sure use some help in sorting this out.
Thanks,
Jason