dsa-eventhandler-restart-service: update comments to match usage
[mirror/dsa-nagios.git] / dsa-nagios-checks / event_handlers / dsa-eventhandler-restart-service
1 #!/bin/sh
2 #
3 # Event handler script for restarting a service via NRPE
4 #
5 # Note: This script will only restart the service if the service is
6 #       retried 3 times (in a "soft" state) or if the service somehow
7 #       manages to fall into a "hard" error state.
8
9 # Args:
10 # $1 $SERVICESTATE$
11 # $2 $SERVICESTATETYPE$
12 # $3 $SERVICEATTEMPT$
13 # $4 $HOSTADDRESS$
14 # $5 state to match against ("WARNING" or "CRITICAL")
15 # $6 NRPE service name to use
16
17 state="$1"
18 type="$2"
19 attempt="$3"
20 host="$4"
21 starton="$5"
22 service="$6"
23
24 # What state is the service in?
25 case "${state}" in
26         "${starton}")
27         # Aha!  The service appears to have a problem - perhaps we should restart it
28         # Is this a "soft" or a "hard" state?
29                 case "${type}" in
30                 # We're in a "soft" state, meaning that Nagios is in the middle of retrying the
31                 # check before it turns into a "hard" state and contacts get notified...
32                         SOFT)
33                         # What check attempt are we on?  We don't want to restart the service on the first
34                         # check, because it may just be a fluke!
35                                 case "${attempt}" in
36                                         # Wait until the check has been tried 3 times before restarting the service
37                                         # If the check fails on the 4th time (after we restart the service), the state
38                                         # type will turn to "hard" and contacts will be notified of the problem.
39                                         # Hopefully this will restart the service successfully, so the 4th check will
40                                         # result in a "soft" recovery.  If that happens no one gets notified because we
41                                         # fixed the problem!
42                                         3)
43                                                 # Call the service restart script via NRPE
44                                                 /usr/lib/nagios/plugins/check_nrpe -n -H "${host}" -c "${service}"
45                                         ;;
46                                 esac
47                         ;;
48                         # The service somehow managed to turn into a hard error without getting fixed.
49                         # It should have been restarted by the code above, but for some reason it didn't.
50                         # Let's give it one last try, shall we?
51                         # Note: Contacts have already been notified of a problem with the service at this
52                         # point (unless you disabled notifications for this service)
53                         HARD)
54                                 /usr/lib/nagios/plugins/check_nrpe -n -H "${host}" -c "${service}"
55                         ;;
56         esac
57         ;;
58 esac
59
60 exit 0