Logoj0ke.net Open Build Service > Projects > server:monitoring > nagios-plugins-cciss > check_cciss
Sign Up | Log In

File check_cciss of Package nagios-plugins-cciss

x
 
1
#!/bin/sh
2
#
3
# HP Smart Array Hardware status plugin for Nagios
4
# ( With HP Array Configuration Utility CLI hpacucli-x.y.*.rpm )
5
#
6
# Written by Simone Rosa (info@simonerosa.it)
7
# Extended by Carsten Schoene (cs@linux-administrator.com)
8
#
9
# Description:
10
#
11
# This plugin checks hardware status for Smart Array Controllers,
12
# using the HP Array Configuration Utility CLI.
13
# (Array, controller, cache, battery, etc...)
14
#
15
#
16
# Usage: ./check_cciss [-v] [-d] [-e <number>] [-E <name>]
17
#
18
#  -v                   = output status and informations about RAID
19
#  -e <number>          = exclude slot number
20
#  -E <name>            = exclude chassis name
21
#  -d                   = use for debug ( command line mode )
22
#
23
#
24
# !!!!!! NOTE: !!!!!!
25
#
26
# HP Array Configuration Utility CLI (hpacucli-x.y.*.rpm) need administrator rights.
27
# Please add this line to /etc/sudoers :
28
# --------------------------------------------------
29
# nagios      ALL=NOPASSWD: /usr/sbin/hpacucli
30
#
31
# !!!!!!!!!!!!!!!!!!!
32
#
33
# NB: Please update the hpacucli to the current version (8.10)
34
#
35
# !!!!!!!!!!!!!!!!!!!
36
#
37
# Examples:
38
#
39
#   ./check_cciss -v
40
# RAID OK:  Smart Array 6i in Slot 0 array A logicaldrive 1 (67.8 GB, RAID 1+0, OK)
41
#           [Controller Status: OK  Cache Status: OK  Battery Status: OK]
42
#
43
#   ./check_cciss
44
# RAID OK
45
#
46
#
47
# Another Examples:
48
#
49
# RAID CRITICAL - HP Smart Array Failed:  Smart Array 6i in Slot 0 array \
50
#          A (failed) logicaldrive 1 (67.8 GB, 1+0, Interim Recovery Mode)
51
#
52
# RAID WARNING - HP Smart Array Rebuilding:  Smart Array 6i in Slot 0 array \
53
#           A logicaldrive 1 (67.8 GB, 1+0, Rebuilding)
54
#
55
#
56
# ChangeLog:
57
#
58
# 04/06/12 (1.13)
59
#      - Added support for kernels greater 3.x (prepend uname26)
60
#
61
# 07/10/11 (1.12)
62
#      - Added support for newer kernels with hpsa driver
63
#
64
# 19/08/11 (1.11)
65
#      - Added support to disable chache check (-c)
66
#
67
# 10/06/08 (1.8)
68
#          - Added support for chassis name (example MSA500)
69
#          - Added arguments to exclude slot number (-e <n>) and chassis name (-E <name>)
70
#          - Added "Recovering" status reporting
71
#          - Updated for hpacucli 8.10 version
72
#
73
# 07/12/08 (1.7)
74
#          - Changed command argument support to use getopts and dropped the now unnecessary -N and -c options
75
#            ( thanks to Reed Loden )
76
#
77
# 07/06/08 (1.6)
78
#          - Added support for multiple arrays
79
#            ( thanks to Reed Loden )
80
#
81
# 05/30/08 (1.5)
82
#          - Added support for checking cache and battery status; added autodetection of slot number; corrected typo
83
#            ( thanks to Reed Loden )
84
#
85
# 01/25/06 (1.4)
86
#          - Changed "Rebuilding" grep with "Rebuild" for capture "Ready for Rebuild" status
87
#            ( thanks to Loris A. )
88
#
89
# 12/24/05 (1.3)
90
#          - Added STATE_UNKNOWN when hpacucli command failed ( if sudo exit with error )
91
#            ( thanks to Tim Hughes )
92
#
93
# 10/10/05 (1.2)
94
#          - Now it's compatible with "Compaq Smart Array"
95
#            ( suggested by Hans Engelen )
96
#
97
# 10/07/05 (1.1)
98
#          - Debug messages
99
#
100
# 10/06/05 (1.0)
101
#          - First production version
102
# 
103
104
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
105
106
PROGNAME=`basename $0`
107
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
108
REVISION=`echo '$Revision: 1.8 $' | sed -e 's/[^0-9.]//g'`
109
DEBUG="0"
110
VERBOSE="0"
111
NO_CACHE="0"
112
HPPROC="/proc/driver/cciss/cciss"
113
COMPAQPROC="/proc/driver/cpqarray/ida"
114
HPSASYS="/sys/bus/pci/drivers/hpsa"
115
if [ ! -x /usr/bin/uname26 ] ; then
116
    hpacucli="/usr/sbin/hpacucli"
117
else
118
    hpacucli="/usr/bin/uname26 /usr/sbin/hpacucli"
119
fi
120
121
. $PROGPATH/utils.sh
122
123
print_usage() {
124
        echo ""
125
        echo "Usage: $PROGNAME [-v] [-e <number>] [-E <name>] [-c] [-d]"
126
        echo "Usage: $PROGNAME [-h]"
127
        echo "Usage: $PROGNAME [-V]"
128
        echo ""
129
        echo "  -v                   = output status and informations about RAID"
130
        echo "  -e <number>          = exclude slot number"
131
        echo "  -E <name>            = exclude chassis name"
132
    echo "  -c                   = exclude controller cache check"
133
        echo "  -d                   = use for debug ( command line mode )"
134
        echo "  -h                   = help information"
135
        echo "  -V                   = version information"
136
        echo ""
137
        echo " NOTE:"
138
        echo ""
139
        echo " HP Array Configuration Utility CLI (hpacucli-x.y.*.rpm) need administrator rights."
140
        echo " Please add this line to /etc/sudoers"
141
        echo " --------------------------------------------------"
142
        echo " nagios      ALL=NOPASSWD: /usr/sbin/hpacucli"
143
        echo ""
144
        echo " NB: Please update the hpacucli to the current version (8.10)"
145
}
146
147
print_help() {
148
        print_revision $PROGNAME $REVISION
149
        echo ""
150
        print_usage
151
        echo ""
152
        echo "This plugin checks hardware status for Smart Array Controllers, using the HP Array Configuration Utility CLI."
153
        echo ""
154
        support
155
        exit 0
156
}
157
158
while getopts "N:cvde:E:Vh" options
159
do
160
    case $options in
161
      N)  ;;
162
      c)  NO_CACHE=1;;
163
      v)  VERBOSE=1;;
164
      d)  DEBUG=1;;
165
      e)  EXCLUDE_SLOT=1
166
          excludeslot="$OPTARG";;
167
      E)  EXCLUDE_CH=1
168
          excludech="$OPTARG";;
169
      V)  print_revision $PROGNAME $REVISION
170
          exit 0;;
171
      h)  print_help
172
          exit 0;;
173
      \?) print_usage
174
          exit 0;;
175
      *)  print_usage
176
          exit 0;;
177
  esac
178
done
179
180
raid=`cat $HPPROC* 2>&1`
181
status=$?
182
if [ "$DEBUG" = "1" ]; then
183
        echo ${raid}
184
fi
185
if test ${status} -eq 1; then
186
    if [ -n "` ls -1A $COMPAQPROC* 2>/dev/null`" ] ; then
187
            raid=`cat $COMPAQPROC* 2>&1`
188
            status=$?
189
    elif [ -d "$HPSASYS" ] ; then
190
        status=0
191
    fi
192
        if [ "$DEBUG" = "1" ]; then
193
                echo ${raid}
194
        fi
195
        if test ${status} -eq 1; then
196
                echo "RAID UNKNOWN - HP Smart Array not found"
197
                exit $STATE_UNKNOWN
198
        fi
199
fi
200
201
status=$?
202
if [ "$DEBUG" = "1" ]; then
203
        echo ${hpacucli}
204
fi
205
if test ${status} -eq 1; then
206
        echo "RAID UNKNOWN - HP Array Utility CLI not found"
207
        exit $STATE_UNKNOWN
208
fi
209
210
if [ "$NO_CACHE" = "1" ] ; then
211
    check=`$hpacucli controller all show status | grep -v "Cache Status" 2>&1`
212
else
213
    check=`$hpacucli controller all show status 2>&1`
214
fi
215
216
status=$?
217
if test ${status} -ne 0; then
218
        echo "RAID UNKNOWN - $hpacucli did not execute properly : "${check}
219
        exit $STATE_UNKNOWN
220
fi
221
222
223
if [ "$EXCLUDE_SLOT" = "1" ]; then
224
        slots=`echo ${check} | egrep -o "Slot \w" | awk '{print $NF}' | grep -v "$excludeslot"`
225
else
226
        slots=`echo ${check} | egrep -o "Slot \w" | awk '{print $NF}'`
227
fi
228
for slot in $slots
229
do
230
        check2b=`$hpacucli controller slot=$slot logicaldrive all show 2>&1`
231
        status=$?
232
        if test ${status} -ne 0; then
233
                echo "RAID UNKNOWN - $hpacucli did not execute properly : "${check2b}
234
                exit $STATE_UNKNOWN
235
        fi
236
        check2="$check2$check2b"
237
done
238
239
if [ "$EXCLUDE_CH" = "1" ]; then
240
        chassisnames=`echo ${check} | egrep -o "in \w+" | egrep -v "Slot" | awk '{print $NF}' | grep -v "$excludech"`
241
else
242
        chassisnames=`echo ${check} | egrep -o "in \w+" | egrep -v "Slot" | awk '{print $NF}'`
243
fi
244
for chassisname in $chassisnames
245
do
246
        check2b=`$hpacucli controller chassisname="$chassisname" logicaldrive all show 2>&1`
247
        status=$?
248
        if test ${status} -ne 0; then
249
                echo "RAID UNKNOWN - $hpacucli did not execute properly : "${check2b}
250
                exit $STATE_UNKNOWN
251
        fi
252
        check2="$check2$check2b"
253
done
254
255
if echo ${check} | egrep Failed >/dev/null; then
256
        echo "RAID CRITICAL - HP Smart Array Failed: "${check} | egrep Failed
257
        exit $STATE_CRITICAL
258
elif echo ${check} | egrep Disabled >/dev/null; then
259
        echo "RAID CRITICAL - HP Smart Array Problem: "${check} | egrep Disabled
260
        exit $STATE_CRITICAL
261
elif echo ${check2} | egrep Rebuild >/dev/null; then
262
        echo "RAID WARNING - HP Smart Array Rebuilding: "${check2} | egrep Rebuild
263
        exit $STATE_WARNING
264
elif echo ${check2} | egrep Recover >/dev/null; then
265
        echo "RAID WARNING - HP Smart Array Recovering: "${check2} | egrep Recover
266
        exit $STATE_WARNING
267
elif echo ${check2} | egrep Failed >/dev/null; then
268
        echo "RAID CRITICAL - HP Smart Array Failed: "${check2} | egrep Failed
269
        exit $STATE_CRITICAL
270
else
271
        if [ "$DEBUG" = "1" -o "$VERBOSE" = "1" ]; then
272
                check3=`echo "${check}" | egrep Status`
273
                check3=`echo ${check3}`
274
                echo "RAID OK: "${check2}" ["${check3}"]"
275
        else
276
                echo "RAID OK"
277
        fi
278
        exit $STATE_OK
279
fi
280
281
exit $STATE_UNKNOWN
282