0

Recently we've been experiencing a lot of spam hitting our servers causing apache to topple over. To tackle this we've installed nagios to notify us/run some restart commands if the issue arises. Notifications function fine, but the restart scripts just wont kick in. We've taken the following steps:

  • Created our restart script located: /usr/share/nagios3/plugins/eventhandlers/restart_apache
  • Tested and ran via ./restart_apache CRITICAL SOFT 3 - can confirm the script works
  • Defined the command: /etc/nagios3/commands.cfg
define command{
        command_name restart-apache
        command_line /usr/local/nagios/libexec/eventhandlers/restart_apache $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}
  • Applied the command to fire when current load notifications run: /etc/nagios3/conf.d/localhost_nagios2.cfg
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       localhost
        service_description             Current Load
        check_command                   check_load!5.0!4.0!3.0!10.0!6.0!4.0
        event_handler                   restart-apache
        }
  • We've set the script to write to a text file when performing a restart, but nothing is happening (and apache stays down) - so something is not right. Any direction is much appreciated!Thanks
2

you should make sure that handlers are enabled and logging in your nagios.cfg

enable_event_handlers=1
log_event_handlers=1

then try to tail your nagios logs (in my case /var/spool/nagios/nagios.log ) and wait for your event, you should see the handler being executed or failing

tail -f /var/spool/nagios/nagios.log | egrep HANDLER
...
[1271946604] SERVICE EVENT HANDLER: $HOST:$SERVICE:CRITICAL:HARD:3:$YOUR_RESTART_HANDLER
  • Thanks for your response - I can confirm the script is now firing - however, we need to run sudo service apache2 stop - but this just wont fire from the script. Any idea? – williamsowen Jun 18 '13 at 10:53
  • 1
    Make sure nagios is allowed to run that command via sudo, without a password and without requiring a TTY. – Keith Jun 18 '13 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.