-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_geom
131 lines (112 loc) · 3.46 KB
/
check_geom
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
#!/bin/sh
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version. For further details see:
## <http://www.gnu.org/licenses/>.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
# =============
# check_geom
# =============
# * written by Silver Salonen, Estonia
# version 1.2 (11.Dec.2009)
# * append " (SYNCHRONIZING - <percentage>)" to status if some of the disks is/are syncing
# * in case of a synchronizing array, status 1 (WARNING) is returned
# * in case of -v, don't echo about the state additionally
# (09.Apr.2009)
# include licence
# version 1.1.1 (27.Sep.2007)
# * fix typo 'grmirror' in printUsage().
# * mention graid in printUsage().
# version 1.1 (05.Jul.2007)
# * add type graid
# * delete unused functions that were copied from the check_pf.sh plugin ;)
# version 1.0.1 (27.Apr.2007)
# * allow GEOM state to be "COMPLETE" also.
# version 1.0 (17.Apr.2007)
# plugin return codes:
# 0 OK
# 1 Warning
# 2 Critical
# 3 Unknown
while getopts "ht:n:v" opt
do
case $opt in
h)
showhelp=1
break
;;
t)
type="$OPTARG"
;;
n)
name="$OPTARG"
;;
esac
done
printUsage() {
echo "Usage: $0 [-h] -t (gstripe|gmirror|graid) -n <name> [-v]"
echo ""
echo "Example: $0 -t gstripe -n gs0"
}
printHelp() {
printUsage
echo ""
echo "This plugin checks state and status of a GEOM device (currently gstripe, gmirror or graid)"
echo ""
echo "For more details, see inside the script ;)"
echo ""
exit 3
}
if [ "$showhelp" = "1" ]; then
printHelp
exit 3
fi
if [ ! "$type" ] || [ ! "$name" ]; then
printUsage
exit 3
fi
case "$type" in
gmirror)
geom_exec=/sbin/gmirror
;;
gstripe)
geom_exec=/sbin/gstripe
;;
graid)
geom_exec=/sbin/graid
;;
*)
echo "$type: unknown type"
exit 3
;;
esac
if [ ! -x $geom_exec ]; then
echo "$geom_exec: command not found"
exit 3
fi
geom_list=`$geom_exec list $name`
geom_name=`echo "$geom_list" | grep "^Geom name"`
geom_state=`echo "$geom_list" | grep "^State"`
geom_status=`echo "$geom_list" | grep "\<Status"`
if ( echo "$geom_list" | grep "^No such geom" > /dev/null ); then
echo "$geom_list"
exit 3
fi
ret_code=0
geom_state_only=`echo "$geom_state" | cut -d ':' -f 2 | sed 's/^ //'`
if [ "$geom_state_only" != "OPTIMAL" ] && [ "$geom_state_only" != "UP" ] && [ "$geom_state_only" != "COMPLETE" ]; then
if ( echo "$geom_list" | grep "\<State: SYNCHRONIZING" > /dev/null ); then
synced="`echo "$geom_list" | grep "\<Synchronized" | cut -d ':' -f 2`"
geom_state="$geom_state (SYNCHRONIZING:$synced)"
ret_code=1
else
ret_code=2
fi
fi
echo "$geom_name; $geom_state"
exit $ret_code