Page 1 of 1

SOLVED Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 10:05 am
by jasgot
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:

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
        }
Here is my command from commands.cfg:

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 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:

Code: Select all

DU="/usr/bin/sudo /usr/bin/du"
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

Re: Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 10:39 am
by hsmith
Hi Jason,

I just set all of this up using your setup.. CentOS 7 / Core 4.1.0rc2

What are your permissions on the check_dirsize script?

Is your apache user part of the nagios group?

I was unable to replicate any issues whatsoever with this.

edit: Also, don't know if the comments here are going to be of any use to you. You may have already read them.

Re: Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 11:30 am
by jasgot
hsmith wrote:Hi Jason,

I just set all of this up using your setup.. CentOS 7 / Core 4.1.0rc2

What are your permissions on the check_dirsize script?

Is your apache user part of the nagios group?

I was unable to replicate any issues whatsoever with this.

edit: Also, don't know if the comments here are going to be of any use to you. You may have already read them.
permissions of check_dirsize11.sh are root:root 4755

I have played with the permissions, as far as I can tell, the permissions issue is not with check_dirsize11.sh, but rather with /usr/bin/du I am reluctant to toy with the permissions on /usr/bin/du, that's why I went with the sudo option.

Group? Yes.

Code: Select all

[root@sabrina libexec]# grep ^nagios /etc/group
nagios:?:?????:??????,apache,???,??????????
[root@sabrina libexec]#
That link to the install page? Yes, I had to follow those changes to Progname, Line 46 and sudoers to get this far.

Thanks for your help, This is driving me nuts....

Re: Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 11:54 am
by hsmith
jasgot wrote:
hsmith wrote:Hi Jason,

I just set all of this up using your setup.. CentOS 7 / Core 4.1.0rc2

What are your permissions on the check_dirsize script?

Is your apache user part of the nagios group?

I was unable to replicate any issues whatsoever with this.

edit: Also, don't know if the comments here are going to be of any use to you. You may have already read them.
permissions of check_dirsize11.sh are root:root 4755

I have played with the permissions, as far as I can tell, the permissions issue is not with check_dirsize11.sh, but rather with /usr/bin/du I am reluctant to toy with the permissions on /usr/bin/du, that's why I went with the sudo option.

Group? Yes.

Code: Select all

[root@sabrina libexec]# grep ^nagios /etc/group
nagios:?:?????:??????,apache,???,??????????
[root@sabrina libexec]#
That link to the install page? Yes, I had to follow those changes to Progname, Line 46 and sudoers to get this far.

Thanks for your help, This is driving me nuts....
Set it to nagios:nagios

Code: Select all

chown nagios:nagios check_dirsize11.sh

Code: Select all

 grep check_dirsize11.sh
-rwxr--r--. 1 nagios nagios   4328 Aug 20 05:28 check_dirsize11.sh

Re: Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 12:55 pm
by jasgot
No Joy. :(

Re: Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 12:58 pm
by jasgot
Just found this in a log file:

Aug 20 13:51:22 sabrina sudo: nagios : sorry, you must have a tty to run sudo ; TTY=unknown ; PWD=/??? ; USER=root ; COMMAND=/usr/bin/du -sk /mnt/backup
Aug 20 13:54:22 sabrina sudo: nagios : sorry, you must have a tty to run sudo ; TTY=unknown ; PWD=/??? ; USER=root ; COMMAND=/usr/bin/du -sk /mnt/backup

Re: Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 1:13 pm
by hsmith
jasgot wrote:Just found this in a log file:

Aug 20 13:51:22 sabrina sudo: nagios : sorry, you must have a tty to run sudo ; TTY=unknown ; PWD=/??? ; USER=root ; COMMAND=/usr/bin/du -sk /mnt/backup
Aug 20 13:54:22 sabrina sudo: nagios : sorry, you must have a tty to run sudo ; TTY=unknown ; PWD=/??? ; USER=root ; COMMAND=/usr/bin/du -sk /mnt/backup
I would attempt to take the sudo out after changing the ownership of the script.

Re: Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 1:14 pm
by jasgot
I followed instructions here and got it working! Yes!

http://serverfault.com/questions/313959 ... o-run-sudo

Re: Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 1:24 pm
by hsmith
jasgot wrote:I followed instructions here and got it working! Yes!

http://serverfault.com/questions/313959 ... o-run-sudo
Hmm, that is pretty interesting. Thank you for the share!

Can we do anything else to assist you, or is this one all right to close?

Re: SOLVED Script works from CLI but not from within nagios

Posted: Thu Aug 20, 2015 1:25 pm
by jasgot
OK to close.

Thanks for the help!