Executing event Handlers to correct action

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
ITOMB_IMT
Posts: 181
Joined: Wed Oct 17, 2018 12:55 pm

Re: Executing event Handlers to correct action

Post by ITOMB_IMT »

It executed successfully as nagios user on remote machine and does what it supposed to do, but when i run using nrpe it failed.
./check_nrpe -H localhost -c remove_core
NRPE: Unable to read output
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Executing event Handlers to correct action

Post by ssax »

This may be a sudo path issue.

Run this command on the remote system:

Code: Select all

which sudo
Then edit your command and change it to:
- Change /full/path/to/sudo to the the full path listed from the command above
- The 2>&1 redirects stderr to stdout so you can see the error
- The sudo path change may fix it, if it doesn't the 2>&1 should allow us to see what the issue is

Code: Select all

command[remove_core]=/full/path/to/sudo /usr/local/nagios/libexec/remove_core.sh 2>&1
The restart NRPE.

Now run this command from the other machine and post the full output:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H remote_host_IP -c remove_core 

Thank you
ITOMB_IMT
Posts: 181
Joined: Wed Oct 17, 2018 12:55 pm

Re: Executing event Handlers to correct action

Post by ITOMB_IMT »

Please see the output below.

#which sudo
/bin/sudo

changed command[remove_core]=/bin/sudo /usr/local/nagios/libexec/remove_core.sh 2>&1 , restarted nrpe and ran
from Nagios server:
]# ./check_nrpe -H remote_ip-c remove_core
NRPE: Unable to read output

on remote machine:
]# ./check_nrpe -H localhost -c remove_core
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

I can run as normal user, but when i run as nagios user same error as above.
in sudo i have as below.
nagios ALL = NOPASSWD:/usr/local/nagios/libexec/remove_core.sh
nagios ALL = NOPASSWD:/bin/rm -f /var/core/core*
nagios ALL = NOPASSWD:/bin/rm -f /data/was/current/resources/Snap*
nagios ALL = NOPASSWD:/bin/rm -f /data/was/current/resources/javacore*
nagios ALL = NOPASSWD:/bin/rm -f /data/was/current/resources/heap*

The script i have is as follows,
#!/bin/bash

/bin/sudo /bin/rm -f /data/was/current/resources/Snap*;
/bin/sudo /bin/rm -f /data/was/current/resources/javacore*;
/bin/sudo /bin/rm -f /data/was/current/resources/heap*;
/bin/sudo /bin/rm -f /var/core/core*;


Is it ok to run as script for event handlers or need any changes in the script?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Executing event Handlers to correct action

Post by scottwilkerson »

I believe you are going to need to add the following to your sudoers if not present

Code: Select all

Defaults:nagios !requiretty
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ITOMB_IMT
Posts: 181
Joined: Wed Oct 17, 2018 12:55 pm

Re: Executing event Handlers to correct action

Post by ITOMB_IMT »

made the changes as suggested, but the results are the same its not working.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Executing event Handlers to correct action

Post by scottwilkerson »

One thing I noticed, is that your script has no output

Code: Select all

#!/bin/bash

/bin/sudo /bin/rm -f /data/was/current/resources/Snap*;
/bin/sudo /bin/rm -f /data/was/current/resources/javacore*;
/bin/sudo /bin/rm -f /data/was/current/resources/heap*;
/bin/sudo /bin/rm -f /var/core/core*;
Which would lead to

Code: Select all

NRPE: Unable to read output
Can you change the script to

Code: Select all

#!/bin/bash

/bin/sudo /bin/rm -f /data/was/current/resources/Snap*;
/bin/sudo /bin/rm -f /data/was/current/resources/javacore*;
/bin/sudo /bin/rm -f /data/was/current/resources/heap*;
/bin/sudo /bin/rm -f /var/core/core*;
echo "Files deleted";
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ITOMB_IMT
Posts: 181
Joined: Wed Oct 17, 2018 12:55 pm

Re: Executing event Handlers to correct action

Post by ITOMB_IMT »

./check_nrpe -H localhost -c remove_core
Files deleted
ls -ltr /var/core/
-rw-r--r-- 1 nagios nagios 0 Jun 9 09:54 core3

But the files weren't deleted.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Executing event Handlers to correct action

Post by scottwilkerson »

I'm not sure what timezone you are in but the timestamp on that empty file is pretty recent, are you sure it isn't being automatically re-created?
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked