-
Notifications
You must be signed in to change notification settings - Fork 5
/
utests.sh
executable file
·209 lines (181 loc) · 5.58 KB
/
utests.sh
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
CAPWARN=80 # warning at 80% of used disc capacity
CAPCRIT=90 # warnint at 90% of user disc capacity
VERBOSE=0 # verbose
PRGNAME=$(basename "$0")
DBG="n"
function dbg() { [ "$DBG" = "y" ] && echo "DBG: $*" >&2 ; }
OPTS=':hH:i:u:p:w:c:vd-:' # first : and lsast - is mandatory
function usage() {
[ -n "$*" ] && {
exec 1>&2 # redirect STDOUT to STDERR for rest of script
echo "${PRGNAME} ERROR: $*"
echo ""
}
echo "Tests for check_3par.
Copyright (c) 2010-2017 various developers - look in source code
Usage: ${PRGNAME} -h | -H <3PAR> [-d] [-v] [-u <username>] [-i <inform_cli> [-p <password_file>]] [-w <warning>] [-c <critical>] <volumename> <quorum_witeness>
Options:
-h, --help
Print detailed help screen
-H, --hostname=ADDRESS
3PAR controler
-i, --inform-bin=PATH
Path to 3PAR Inform CLI. Default connection method is SSH.
-u, --username=USER
3PAR username
-p, --password-file=PATH
Password file for 3PAR Inform CLI
-w, --warning=TRESHOLD (default: 80)
Warning treshold
-c, --critical=TRESHOLD (default: 90)
Critical treshold
-d, --debug
Turn on debugging
-v, --verbose
Verbose output
"
exit 128
}
[ "$#" = 0 ] && usage "Too few arguments."
while getopts "$OPTS" OPTION ; do
dbg "option $OPTION optind $OPTIND optarg $OPTARG"
case "$OPTION" in
d ) DBG="y";;
v ) VERBOSE=$((++VERBOSE)) ;;
h ) usage ;;
H ) INSERV="$OPTARG" ;;
i ) INFORMBIN="$OPTARG" ;;
u ) USERNAME="$OPTARG" ;;
p ) PASSFILE="$OPTARG" ;;
w ) CAPWARN="$OPTARG" ;;
c ) CAPCRIT="$OPTARG" ;;
- ) [ $OPTIND -ge 1 ] && optind=$(expr $OPTIND - 1 ) || optind=$OPTIND
eval OPTION="\$$optind"
OPTARG=$(echo $OPTION | cut -d'=' -f2)
OPTION=$(echo $OPTION | cut -d'=' -f1)
dbg "- option $OPTION optind $OPTIND optarg $OPTARG"
case $OPTION in
--debug ) DBG="y" ;;
--verbose ) VERBOSE=$((++VERBOSE)) ;;
--help ) usage ;;
--hostname ) INSERV="$OPTARG" ;;
--inform-bin ) INFORMBIN="$OPTARG" ;;
--username ) USERNAME="$OPTARG" ;;
--password-file ) USERNAME="$OPTARG" ;;
--warning ) CAPWARN="$OPTARG" ;;
--critical ) CAPCRIT="$OPTARG" ;;
? ) usage "Invalid option '$OPTARG'" ;;
* ) usage "parsing options failed";;
esac
#OPTIND=1
#shift
;;
? ) usage "Invalid option '$OPTARG'" ;;
* ) usage "parsing options failed";;
esac
done
shift $((OPTIND-1))
VOL="$1"
QW="$2"
TMPOUT=""
if [ "$DBG" = "y" ]
then
DBG="-d"
else
DBG=""
fi
if [ ! -x "./check_3par" ]
then
usage "Can not run ./check_3par ."
fi
# CLI or SSH
if [ -n "$INFORMBIN" ]
then
# To connect using the 3PAR CLI, use option -i and -p to setup the command
CMD="./check_3par -H $INSERV -i $INFORMBIN -p $PASSFILE -w $CAPWARN -c $CAPCRIT $DBG"
# Note : connecting using the CLI requires creating password files (.pwf)
else
# To connect using SSH use -u option to set username
# Note : connecting using SSH requires setting public key authentication
CMD="./check_3par -H $INSERV -u $USERNAME -w $CAPWARN -c $CAPCRIT $DBG"
fi
function utest() {
EXPRET=$1
shift
case "$EXPRET" in
OK ) RET=0 ;;
WARN ) RET=1 ;;
CRIT ) RET=2 ;;
UNKN ) RET=3 ;;
* ) echo "Wrong parameter for utest()" >&2; exit 128 ;;
esac
CMDOUT=$( $CMD $@ )
CMDRET=$?
if [ $CMDRET -eq $RET ]
then
echo "### OK # $CMD $@"
if [ "${VERBOSE}" -gt 0 ]
then
echo "${CMDOUT}"
fi
else
echo
echo "############################################"
echo "# Failed $CMD $@"
echo "# Expected return '$RET' but get '$CMDRET'."
echo "##########"
echo "$CMDOUT"
echo "############################################"
echo
fi
}
echo "####################################"
echo "### Runing check_node tests"
echo "### CMD: $CMD"
echo
echo " !!! Warning !!!"
echo " If tested 3PAR array is in an edgy condition,"
echo " you can get false negatives/positives"
echo
utest OK check_node
utest OK check_pd
utest OK check_ld
utest OK check_vv
utest OK check_ps_node
utest OK check_ps_cage
utest OK check_cap_ssd
# check Warning level
utest WARN -w 1 -c 99 check_cap_ssd
utest OK -w 98 -c 99 check_cap_ssd
# check Critical level
utest CRIT -w 1 -c 2 check_cap_ssd
utest OK -w 98 -c 99 check_cap_ssd
utest OK check_cap_fc
# check Warning level
utest WARN -w 1 -c 99 check_cap_fc
utest OK -w 98 -c 99 check_cap_fc
# check Critical level
utest CRIT -w 1 -c 2 check_cap_fc
utest OK -w 98 -c 99 check_cap_fc
utest OK check_cap_nl
# check Warning level
utest WARN -w 1 -c 99 check_cap_nl
utest OK -w 98 -c 99 check_cap_nl
# check Critical level
utest CRIT -w 1 -c 2 check_cap_nl
utest OK -w 98 -c 99 check_cap_nl
utest OK check_volume $VOL
# check Warning level
utest WARN -w 1 -c 99 check_volume $VOL
utest OK -w 98 -c 99 check_volume $VOL
# check Critical level
utest CRIT -w 1 -c 2 check_volume $VOL
utest OK -w 98 -c 99 check_volume $VOL
# check real QW
utest OK check_qw $QW
# check nonexitsting QW
utest UNKN check_qw 8.8.8.8
utest OK check_alerts
utest OK check_health
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab: