Page 1 of 2

my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 8:20 am
by baber
Dear all
Hi

i have downloaded attach plugin when i use this plugin on my linux server this output appear

Code: Select all

[root@npmbsrv libexec]# ./check_cciss-1.12 -v
RAID OK:  Smart Array P420i in Slot 0 (Embedded) array A logicaldrive 1 (279.4 GB, RAID 1, OK) array B logicaldrive 2 (279.4 GB, RAID 1, OK) array C logicaldrive 3 (279.4 GB, RAID 1, OK) [Controller Status: OK Cache Status: OK Battery/Capacitor Status: OK]

and

Code: Select all

[root@npmbsrv libexec]# ./check_cciss-1.12 -p
RAID OK

and add this in my cfg machine

Code: Select all


define service{
        use                            generic-service
        host_name                      npmbsrv
        service_description            Disk Raid
        check_command                  check_nrpe!check_cciss-1.12 
}
then add this line in nrpe.cfg file

Code: Select all

command[check_cciss-1.12]=/usr/local/nagios/libexec/check_cciss-1.12 -v -p
but output on nagios monitoring show this

Code: Select all

RAID UNKNOWN - /usr/sbin/hpacucli did not execute properly : sudo: sorry, you must have a tty to run sudo
even i used this

Code: Select all

command[check_cciss-1.12]=sudo /usr/local/nagios/libexec/check_cciss-1.12 -v -p
and this error appear on monitoring

Code: Select all

NRPE: Unable to read output

now what is my problem ? i am realy confused when i run directly on physical server get output but when want run from nagios not work

Best regards

Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 8:26 am
by eloyd
This is your problem:

Code: Select all

sudo: sorry, you must have a tty to run sudo
There are lots of threads on this, but I'll save you the problem and give you the answer. You need to add this to your sudoers file through the "visudo" command on the remote host that you're trying to execute the code on (via NRPE):

Code: Select all

# NEEDED TO ALLOW NAGIOS TO CHECK SERVICE STATUS
Defaults:nagios !requiretty
nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_init_service

Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 8:52 am
by baber
eloyd wrote:This is your problem:

Code: Select all

sudo: sorry, you must have a tty to run sudo
There are lots of threads on this, but I'll save you the problem and give you the answer. You need to add this to your sudoers file through the "visudo" command on the remote host that you're trying to execute the code on (via NRPE):

Code: Select all

# NEEDED TO ALLOW NAGIOS TO CHECK SERVICE STATUS
Defaults:nagios !requiretty
nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_init_service

thanks
but my problem not solved

i have add these line at the end of sudoers file on my remote physical server

Code: Select all

# NEEDED TO ALLOW NAGIOS TO CHECK SERVICE STATUS
Defaults:nagios !requiretty
nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_cciss-1.12

and in nrpe.cfg this line

Code: Select all

command[check_cciss-1.12]=/usr/local/nagios/libexec/check_cciss-1.12 -v -p
now in monitoring this error appear

Code: Select all

RAID UNKNOWN - /usr/sbin/hpacucli did not execute properly : sudo: no tty present and no askpass program specified
what do i have to do ?

Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 8:59 am
by eloyd
Make sure the lines you added are at the end of the sudoers file, not the beginning.

Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 9:00 am
by baber
eloyd wrote:Make sure the lines you added are at the end of the sudoers file, not the beginning.

exactly in end of file

Code: Select all

# NEEDED TO ALLOW NAGIOS TO CHECK SERVICE STATUS
Defaults:nagios !requiretty
nagios ALL=NOPASSWD: /usr/local/nagios/libexec/check_cciss-1.12
"/etc/sudoers" [readonly] 119L, 3940C                                                                                                                119,1         Bot


Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 9:06 am
by eloyd
Change

Code: Select all

command[check_cciss-1.12]=/usr/local/nagios/libexec/check_cciss-1.12 -v -p
to

Code: Select all

command[check_cciss-1.12]=sudo /usr/local/nagios/libexec/check_cciss-1.12 -v -p

Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 9:10 am
by baber
eloyd wrote:Change

Code: Select all

command[check_cciss-1.12]=/usr/local/nagios/libexec/check_cciss-1.12 -v -p
to

Code: Select all

command[check_cciss-1.12]=sudo /usr/local/nagios/libexec/check_cciss-1.12 -v -p
i have changed but another this error appear

Code: Select all

RAID UNKNOWN - /usr/sbin/hpacucli did not execute properly : sudo: sorry, you must have a tty to run sudo


Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 9:21 am
by eloyd
Is your remote code running as the nagios user or something else? If it's something else, you need to update the sudoers file with the appropriate username.

Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 9:25 am
by baber
eloyd wrote:Is your remote code running as the nagios user or something else? If it's something else, you need to update the sudoers file with the appropriate username.

i run script with root user

Code: Select all

[root@npmbsrv libexec]# ./check_cciss-1.12 -p
RAID OK

[root@npmbsrv libexec]# ./check_cciss-1.12 -v
RAID OK:  Smart Array P420i in Slot 0 (Embedded) array A logicaldrive 1 (279.4 GB, RAID 1, OK) array B logicaldrive 2 (279.4 GB, RAID 1, OK) array C logicaldrive 3 (279.4 GB, RAID 1, OK) [Controller Status: OK Cache Status: OK Battery/Capacitor Status: OK]


Code: Select all

[root@npmbsrv libexec]# ll check_cciss-1.12
-rwxr-xr-x 1 nagios nagios 14514 Aug 25 16:39 check_cciss-1.12


[root@npmbsrv libexec]# su - nagios
This account is currently not available.

Code: Select all

[root@npmbsrv libexec]# cat /etc/passwd

nagios:x:503:504::/home/nagios:/sbin/nologin


Re: my script not work correctly but directly work on server

Posted: Thu Aug 25, 2016 9:33 am
by eloyd
I mean, on the remote server, is your NRPE running as the nagios user or some other user? Can you look at the end of /var/log/secure and post the last 50 lines or so?