summaryrefslogtreecommitdiffstats
path: root/roles/nagios_server/files/nagios/plugins/restart_rsyslog
blob: 2ece8a3e42fb4cf1eff810cd0b311c4d63f37028 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
#
# Event handler script for restarting the rsyslog server on the local machine
#
# Note: This script will only restart the web server if the service is
#       retried 3 times (in a "soft" state) or if the web service somehow
#       manages to fall into a "hard" error state.
#

servicestate=$1
servicestatetype=$2
serviceattempt=$3
remotehost=$4
hostalias=$5
servicedesc=$6
servicestate=$7

# What state is the HTTP service in?
case "$servicestate" 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 rsyslog service appears to have a problem - perhaps we should restart the server...

    # Is this a "soft" or a "hard" state?
    case "$servicestatetype" 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 web server on the first
        # check, because it may just be a fluke!
        case "$serviceattempt" in

        # Wait until the check has been tried 2 times before reloading the web server.
        # If the check fails on the 4th time (after we restart the web server), the state
        # type will turn to "hard" and contacts will be notified of the problem.
        # Hopefully this will restart the web server successfully, so the 4th check will
        # result in a "soft" recovery.  If that happens no one gets notified because we
        # fixed the problem!
        2)
            echo -n "Restarting rsyslog service (3rd soft critical state)..."
            # Call the init script to restart the rsyslog server
            echo "#fedora-noc $hostalias - Attempting to reload rsyslog. $servicedesc is $servicestate (2nd check)" | /usr/bin/nc -w 1 value01 5050
            /usr/lib64/nagios/plugins/check_nrpe -H $remotehost -c service_rsyslog_reload
            ;;
            esac
        ;;
                
    # The HTTP 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 rsyslog service..."
        echo "#fedora-noc $hostalias - Attempting to restart rsyslog. $servicedesc is $servicestate" | /usr/bin/nc -w 1 value01 5050
        # Call the init script to restart the HTTPD server
        /usr/lib64/nagios/plugins/check_nrpe -H $remotehost -c service_rsyslog_restart
        ;;
    esac
    ;;
esac
exit 0