[Nagiosplug-help] help with event handler

Mitchell K. Smith mksmith at pa.eplus.com
Tue May 27 08:21:08 CEST 2003


Greetings all.
I need some help with the event handlers.
I am trying to have Nagios restart services on remote servers when it sees the service is down. I can do all the commands manually to restart the services. The problem seems to be in the event handler script.

Here is my service config:
# Service definition - test server
define service{
        use                             eplus-service
        event_handler_enabled           1       ; Service event handler is enabled
        host_name                       test
        service_description             HTTP
        event_handler                   remote-restart-httpd
        contact_groups                  linux-admins
        check_command                   check_http
        notification_options            c,r
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3 
        normal_check_interval           3   
        retry_check_interval            1  
        notification_interval           120
        notification_period             workhours
        }

Here is my remote-restart-httpd script:
#!/bin/sh
case "$1" in
OK)
        ;;
WARNING)  
        ;;
UNKNOWN)  
        ;;
CRITICAL) 
        # Is this a "soft" or a "hard" state?
        case "$2" in
        SOFT)
                case "$3" in
                
                3)
                        echo -n "Restarting HTTP service (3rd soft critical state)..."
                        # Call the init script to restart the HTTPD server
                        ssh $HOSTADDRESS$ sudo /etc/rc.d/init.d/httpd restart
                        ;;
                        esac
                ;;
                  
        HARD)
                echo -n "Restarting HTTP service..."
                # Call the init script to restart the HTTPD server
                ssh $HOSTADDRESS$ sudo /etc/rc.d/init.d/httpd restart
                ;;
        esac
        ;;  
esac
exit 0

I can run commands from the Nagios server as the Nagios user and they work.
ssh 172.31.1.34 sudo /etc/rc.d/init.d/httpd status
This will return my httpd server status.

Thanks for any help you can offer.

Mitchell K. Smith




More information about the Help mailing list