event_handler problem

Lunt, Nick Nick.Lunt at wesleyan.co.uk
Fri Jun 10 16:52:08 CEST 2005


Hi list,

nagios-1.2
nagios-plugins-1.4
redhat 7.2

I've got an event_handler setup for apache running on the local nagios machine (named netview).
When I stop apache I get an email - no problems there.
However, the event_handler I've setup is not working.

In services.cfg I have an event_handler called restart-httpd, and in checkcommands.cfg I have a command called restart-httpd which calls a script. Same as shown in the Nagios documentation.

Because this was not working I put some logging at the top of the script to log the args to the script, and this shows that the script is getting the correct args.

The trouble is the script is not restarting apache when $SERVICESTATE$==CRITICAL, $STATETYPE$==SOFT and $SERVICEATTEMPT$==3.
It only restarts apache when the SERVICEATTEMPT has reached 5 turning it into a HARD STATETYPE.

I must of done something silly to have caused this, but I cannot see what it is.
I would really appreciate any help anyone could offer.

Below is a paste of the relevant bits of the file involved.

Many thanks
Nick .

# services.cfg
define service{
        host_name               netview
        service_description     check_http
        check_command           check_http
        max_check_attempts      5
        normal_check_interval   5
        retry_check_interval    3
        check_period            24x7
        event_handler           restart-httpd
        notification_interval   30
        notification_period     24x7
        notification_options    w,c,r
        contact_groups          linux-admins

# checkcommands.cfg
define command{
        command_name    restart-httpd
        command_line    /usr/local/nagios/libexec/eventhandlers/restart-httpd $SERVICESTATE$ $STATETYPE$ $SERVICEATTEMPT$
        }


# restart-httpd script
LOG=/tmp/NAGLOG
echo "`date` STATE $1 TYPE $2 ATTEMPTS $3" >> $LOG

SERVICESTATE=$1
SERVICETYPE=$2
SERVICEATTEMPT=$3

case "$SERVICESTATE" in
OK)             # The service just came back up so dont do anything
                ;;
WARNING)        # We dont care about warning states cos httpd is prob still running
                ;;
UNKNOWN)        # We dont know what could be causing this, so leave alone
                ;;
CRITICAL)       # Httpd has a problem, lets restart it
                case "$SERVICETYPE" in
                SOFT)   # What check attempt are we on
                        case "$SERVICEATTEMPT" in
                        3)      echo -n "Restarting Apache - 3rd soft critical state"
                                echo $SERVICEATTEMPT | /usr/lib/sendmail nick.lunt at wesleyan.co.uk 
                                sudo /etc/init.d/httpd restart
                                ;;
                        esac
                        ;;
                HARD)   # Restart Apache regardless
                        echo -n "Restarting Apache after Hard failure"
                        echo $SERVICEATTEMPT | /usr/lib/sendmail nick.lunt at wesleyan.co.uk 
                        sudo /etc/init.d/httpd restart
                        ;;
                esac
                ;;

esac

echo $SERVICEATTEMPT | /usr/lib/sendmail nick.lunt at wesleyan.co.uk 
exit 0

# /tmp/NAGLOG
Fri Jun 10 15:30:20 BST 2005 STATE CRITICAL TYPE SOFT ATTEMPTS 1
Fri Jun 10 15:33:20 BST 2005 STATE CRITICAL TYPE SOFT ATTEMPTS 2
Fri Jun 10 15:36:20 BST 2005 STATE CRITICAL TYPE SOFT ATTEMPTS 3
Fri Jun 10 15:39:20 BST 2005 STATE CRITICAL TYPE SOFT ATTEMPTS 4
Fri Jun 10 15:42:21 BST 2005 STATE CRITICAL TYPE HARD ATTEMPTS 5
Fri Jun 10 15:47:21 BST 2005 STATE OK TYPE HARD ATTEMPTS 5




Wesleyan Administration Services Ltd registered number 5188850 and Wesleyan Unit Trust Managers Ltd registered number 2114859 ("WUTM Ltd")
are wholly owned subsidiary companies of Wesleyan Assurance Society, whose registered number is ZC145.
WUTM Ltd is a member of IMA. For ISA/PEP/Unit Trusts Administration Centre: PO Box Basildon SS15 5WQ Telephone: 0870 601 6129
Wesleyan Assurance Society and WUTM Ltd are authorised and regulated by the Financial Services Authority.
Head Office, Colmore Circus, Birmingham B4 6AR. Telephone: 0121 200 3003 Fax 0121 200 2971.
Website: www.wesleyan.co.uk Telephone calls may be recorded for monitoring and training purposes.

CONFIDENTIALITY NOTICE

This communication and the information it contains is intended for the person or organisation to whom it is addressed. Its contents are confidential and may be protected in law. Unauthorised use, copying or disclosure of any of it may be unlawful. If you are not the intended recipient, please contact us immediately.

The contents of any attachments in this e-mail may contain software viruses, which could damage your own computer system. While every reasonable precaution to minimise this risk has been taken, we cannot accept liability for any damage that you sustain as a result of software viruses. You should carry out your own virus checking procedure before opening any attachment.



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r 
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list