You would need to grant sudo priviledges to nagios for it to run those commands with sudo.
See here for an example:
http://users.telenet.be/mydotcom/howto/ ... nsudo.html
Event Handler script not running
Re: Event Handler script not running
The script is:
As I said, I just copied the template from the nagios event-handler page and added my command.
I tried adding nagios to the sudo group but it had no effect, the sudo commands are still ignored.
Any ideas?
Thanks!
Code: Select all
#!/bin/sh
case "$1" in
OK)
# The service just came back up, so don't do anything...
echo "Policy server OK">> /usr/local/nagios/policy_log.log
;;
WARNING)
# We don't really care about warning states, since the service is probably still running...
;;
UNKNOWN)
# We don't know what might be causing an unknown error, so don't do anything...
;;
CRITICAL)
# Aha! The HTTP service appears to have a problem - perhaps we should restart the server...
echo "policy server critical">>/usr/local/nagios/policy_log.log
# Is this a "soft" or a "hard" state?
case "$2" in
# We're in a "soft" state, meaning that Nagios is in the middle of retrying the
# check before it turns into a "hard" state and contacts get notified...
SOFT)
# What check attempt are we on? We don't want to restart the web server on the first
# check, because it may just be a fluke!
case "$3" in
# Wait until the check has been tried 3 times before restarting the web server.
# If the check fails on the 4th time (after we restart the web server), the state
# type will turn to "hard" and contacts will be notified of the problem.
# Hopefully this will restart the web server successfully, so the 4th check will
# result in a "soft" recovery. If that happens no one gets notified because we
# fixed the problem!
3)
echo "Restarting Policy server (3rd soft critical state)...">>/usr/local/nagios/policy_log.log
# Call the init script to restart the HTTPD server
sudo nohup mono >/dev/null /opt/ulink/Tools/PolicyServer/uLinkPolicyServer.exe &
;;
esac
;;
# The HTTP service somehow managed to turn into a hard error without getting fixed.
# It should have been restarted by the code above, but for some reason it didn't.
# Let's give it one last try, shall we?
# Note: Contacts have already been notified of a problem with the service at this
# point (unless you disabled notifications for this service)
HARD)
echo "Restarting Policy server...">>/usr/local/nagios/policy_log.log
sudo nohup mono >/dev/null /opt/ulink/Tools/PolicyServer/uLinkPolicyServer.exe &
# Call the init script to restart the HTTPD server
#sudo nuhup mono > /dev/null /opt/ulink/Tools/PolicyServer/uLinkPolicyServer.exe &
;;
esac
;;
esac
exit 0I tried adding nagios to the sudo group but it had no effect, the sudo commands are still ignored.
Any ideas?
Thanks!
Re: Event Handler script not running
OK, I tried adding nagios to the group using a different command.
I'll try the way you suggested and see what happens.
I'll try the way you suggested and see what happens.
Re: Event Handler script not running
Yeah, you need to use visudo and add nagios with the NOPASSWORD option so it won't prompt and can run the commands that you are trying to run.
Let us know how it goes.
Let us know how it goes.
Re: Event Handler script not running
Finally working! 
Thanks!!
Thanks!!
Re: Event Handler script not running
I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee