Page 3 of 3
Re: Executing event Handlers to correct action
Posted: Fri May 29, 2020 12:17 pm
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
Re: Executing event Handlers to correct action
Posted: Fri May 29, 2020 4:20 pm
by ssax
This may be a sudo path issue.
Run this command on the remote system:
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
Re: Executing event Handlers to correct action
Posted: Thu Jun 04, 2020 12:08 pm
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?
Re: Executing event Handlers to correct action
Posted: Thu Jun 04, 2020 12:27 pm
by scottwilkerson
I believe you are going to need to add the following to your sudoers if not present
Re: Executing event Handlers to correct action
Posted: Mon Jun 08, 2020 9:10 am
by ITOMB_IMT
made the changes as suggested, but the results are the same its not working.
Re: Executing event Handlers to correct action
Posted: Mon Jun 08, 2020 9:16 am
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
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";
Re: Executing event Handlers to correct action
Posted: Tue Jun 09, 2020 8:58 am
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.
Re: Executing event Handlers to correct action
Posted: Tue Jun 09, 2020 9:02 am
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?