[Nagiosplug-help] Help with Event handler again!!

Mitchell K. Smith mksmith at pa.eplus.com
Tue Jun 10 05:19:02 CEST 2003


Remember that nagios will try to execute the script as the nagios user not as root. Restarting the service requires root access.
The way that I do it is to run sudo.
 
Example for your event handler script:
 
ssh $4 sudo /etc/rc.d/init.d/httpd restart
 
Of course you need to configure sudo and also make sure that ssh is exchanging keys as the nagios user.
 
Mitch Smith
 

-----Original Message-----
From: Soeun Vanny [mailto:vanny at artemis-it.com]
Sent: Tuesday, June 10, 2003 1:15 AM
To: nagiosplug-help at lists.sourceforge.net
Subject: [Nagiosplug-help] Help with Event handler again!!


Hello everybody!
 
I've tried to apply the event handler to restart a service,which is probed to be down by nagios,on a remote host.I don't know what's wrong with my work. Please take a look at my work as mentioned below.
 
1. the script that is called by nagios to restart a service.
 
    #!/bin/sh
    
    case "$1" in
    OK)
            ;;
    WARNING)
            ;;
    UNKNOWN)
            ;;
    CRITICAL)
            
 
            case "$2" in
            SOFT)
                    case "$3" in
                    3)
                            ssh $4 /etc/rc.d/init.d/httpd restart
                            ;;
                    esac
                    ;;
            HARD)
                    ssh $4 /etc/rc.d/init.d/httpd restart
                    ;;
            esac
            ;;
    esac
    exit 0
 
2. Here is the syntax of serviccs.cfg
 
# Service definition
define service{
 use    generic-service  ; Name of service template to use
 
 
 host_name               hestia
 service_description  HTTP
 is_volatile               0
 check_period           24x7
 max_check_attempts      4
 normal_check_interval      5
 retry_check_interval      1
 contact_groups           admins
 notification_interval      120
 notification_period          24x7
 notification_options      w,u,c,r
 event_handler_enabled    1
 check_event_handler    service-restart
 check_command           check_http
 }
 
3. Here is the syntax of checkcommands.cfg
 
# 'event_handler' command definition
define command{
 command_name     service-restart
 command_line /usr/local/nagios/libexec/service-restart $SERVICESTATE$ $STATETYPE$ $SERVICEATTEMP$ $HOSTADDRESS$
 }
 
For test i stopped the http service on a remote machine and  tried to execute by hand the following command: 
     ssh 192.168.1.200 /etc/rc.d/init.d/httpd restart . Well, it worked well (of course i set ssh to passwordless).
 
Is there anything wrong with my script?
 
 
Thanks in advance for your help
 
 
 
 
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/
_/  日本アルテミス株式会社
_/  スーン・ヴァニー (Soeun Vanny)
_/  mailto : vanny at artemis-it.com
_/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-plugins.org/archive/help/attachments/20030610/d08c5cf2/attachment.html>


More information about the Help mailing list