eventhandlers

carole gimenez gimenez at cict.fr
Fri Feb 4 10:59:01 CET 2005


Hi,

I have a little problem with one of my eventhandlers scripts.

It works well. The miltrassassin service restart as it is necessary but 
the commands run by the nagios user are always active.

On nagios server,
$ ps -ef | grep nagios
  nagios  3952     1  0 10:23:49 ?        0:00 sh -c 
/usr/local/nagios/libexec/eventhandlers/restart-miltrassassin CRITICAL SO
  nagios 25595     1  1   Jan 10 ?       187:15 
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
  nagios 24065 24053  0   Jan 26 pts/1    0:00 -ksh
  nagios  3958  3953  0 10:23:50 ?        0:01 ssh spam at x.x.x.x 
/usr/local/bin/miltrassassin -p /miltrassassin/miltrassa
  nagios  3953  3952  0 10:23:49 ?        0:00 /bin/sh 
/usr/local/nagios/libexec/eventhandlers/restart-miltrassassin CRITICAL
  nagios 24053 24035  0   Jan 26 ?        0:03 /usr/local/sbin/sshd


My script is the following:

#!/bin/sh
#
# Script de gestionnaire d'evenement pour redemarrer miltrassassin sur 
les passerelles de messagerie distantes
#
# Note: Ce script redemarrera le service miltrassassin si on essaie de 
le joindre
#       2 fois (dans un etat "soft") ou si le service miltrassassin finit
#       par tomber dans un etat d'erreur "hard"
#


# What state is the miltrassassin service in?
case "$1" in
OK)
        # The service just came back up, so don't do anything...
        ;;
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 miltrassassin service appears to have a problem - 
perhaps we should restart the server...

        # 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 miltrassassin service on the first
                # check, because it may just be a fluke!
                case "$3" in

                # Wait until the check has been tried 2 times before 
restarting the miltrassassin service.
                # If the check fails on the 3th time (after we restart 
the miltrassassin service), the state
                # type will turn to "hard" and contacts will be notified 
of the problem.
                # Hopefully this will restart the miltrassassin service 
successfully, so the 3th check will
                # result in a "soft" recovery.  If that happens no one 
gets notified because we
                # fixed the problem!
                2)
                        echo -n "Restarting miltrassassin service (2nd 
soft critical state)..."
                        # Call the script to restart the miltrassassin 
service
                        result=`ssh spam@$4 ps -ef | grep miltrassassin 
| wc -l`
                        if [ $result -eq 0 ] ; then
                            ssh spam@$4 rm -f 
/miltrassassin/miltrassassin.sock
                            ssh spam@$4 /usr/local/bin/miltrassassin -p 
/miltrassassin/miltrassassin.sock -H50 -M40 -L 30
                        fi
                        ;;
                        esac
                ;;

        # The miltrassassin 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 -n "Restarting miltrassassin service..."
                # Call the script to restart the miltrassassin service
                result=`ssh spam@$4 ps -ef | grep miltrassassin | wc -l`
                if [ $result -eq 0 ] ; then
                    ssh spam@$4 rm -f /miltrassassin/miltrassassin.sock
                    ssh spam@$4 /usr/local/bin/miltrassassin -p 
/miltrassassin/miltrassassin.sock -H50 -M40 -L 30
                fi
                ;;
        esac
        ;;
esac
exit 0


I am not a good programmer. Can someone help me, please?

Carole.



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
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