my script not work correctly but directly work on server

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
baber
Posts: 308
Joined: Wed Oct 21, 2015 4:39 am

my script not work correctly but directly work on server

Post 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
Attachments
check_cciss-1.zip
(3.29 KiB) Downloaded 243 times
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post 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
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
baber
Posts: 308
Joined: Wed Oct 21, 2015 4:39 am

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

Post 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 ?
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post by eloyd »

Make sure the lines you added are at the end of the sudoers file, not the beginning.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
baber
Posts: 308
Joined: Wed Oct 21, 2015 4:39 am

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

Post 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

User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post 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
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
baber
Posts: 308
Joined: Wed Oct 21, 2015 4:39 am

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

Post 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

User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post 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.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
baber
Posts: 308
Joined: Wed Oct 21, 2015 4:39 am

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

Post 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

User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

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

Post 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?
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
Locked