forked from alibby/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_drupal
executable file
·173 lines (149 loc) · 3.12 KB
/
check_drupal
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
#
# Drupal monitoring plugin for Nagios
#
# Requires a Drupal module from http://drupal.org/project/nagios
#
# Copyright 2009 Khalid Baheyeldin http://2bits.com
#
ECHO="/bin/echo"
GREP="/bin/egrep"
RM="/bin/rm"
WGET="/usr/bin/wget"
SSL=/bin/false
PROGNAME=`/usr/bin/basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.1.2.12 $' | sed -e 's/[^0-9.]//g'`
temp=/tmp/$PROGNAME.$$
if [[ -e $PROGPATH/utils.sh ]]; then
. $PROGPATH/utils.sh
elif [[ -e /usr/lib/nagios/plugins/utils.sh ]]; then
. /usr/lib/nagios/plugins/utils.sh
else
echo 'Could not find nagios utils include file!'
exit 1
fi
print_usage() {
$ECHO "Usage: $PROGNAME -U unique_id [ -H host_name ] [ -P path_to_nagios_status_page ] [ -t time_out_seconds ]"
$ECHO "Usage: $PROGNAME --help"
$ECHO "Usage: $PROGNAME --version"
}
print_help() {
print_revision $PROGNAME $REVISION
$ECHO ""
print_usage
$ECHO ""
$ECHO "Drupal monitoring plugin for Nagios"
$ECHO ""
support
}
# Make sure the correct number of command line
# arguments have been supplied
if [ $# -lt 1 ]; then
print_usage
exit $STATE_UNKNOWN
fi
# Grab the command line arguments
exitstatus=$STATE_WARNING
while test -n "$1"; do
case "$1" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
--version)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-V)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-H)
hostname=$2
shift
;;
-U)
unique_id=$2
shift
;;
-P)
path=$2
shift
;;
-S)
SSL=/bin/true
shift
;;
-t)
timeout=$2
shift
;;
*)
$ECHO "Unknown argument: $1"
print_usage
exit $STATE_UNKNOWN
esac
shift
done
# Set a default for hostname
if [ "$hostname" = "" ]; then
hostname=$NAGIOS_HOSTADDRESS
fi
# Set a default for path
if [ "$path" = "" ]; then
path="nagios"
fi
# Set the default for timeout
if [ "$timeout" = "" ]; then
timeout=2
fi
# Set the default for timeout
if [ "$unique_id" = "" ]; then
unique_id="Nagios"
fi
if $SSL; then
CMD=("$WGET" --no-check-certificate -S -T $timeout -O "$temp" -U "$unique_id" "https://$hostname/$path")
else
CMD=("$WGET" -S -T $timeout -O "$temp" -U "$unique_id" http://$hostname/$path)
fi
HTTP="$( "${CMD[@]}" 2>&1 | "$GREP" "HTTP/1" )"
RC=$?
if [ "$RC" != 0 ]; then
$ECHO "wget error: $RC: when accessing $hostname/$path. HTTP: $HTTP"
$RM -f $temp
exit $STATE_CRITICAL
fi
HTTP_CODE=`$ECHO "$HTTP" | awk '{print $2}'`
if [ "$HTTP_CODE" != "200" ]; then
$ECHO "HTTP returned an error code. HTTP: $HTTP"
$RM -f $temp
exit $STATE_CRITICAL
fi
DATA="`$GREP "nagios=" $temp | sed -e 's/^.*nagios=//g'`"
STATUS=`$ECHO "$DATA" | awk -F, '{print $1}'`
case $STATUS in
"OK")
exitstatus=$STATE_OK
;;
"WARNING")
exitstatus=$STATE_WARNING
;;
"UNAUTHORIZED")
exitstatus=$STATE_CRITICAL
;;
"CRITICAL")
exitstatus=$STATE_CRITICAL
;;
*)
exitstatus=$STATE_UNKNOWN
;;
esac
# Send the data
$ECHO "DRUPAL $DATA"
$RM -f $temp
exit $exitstatus