-
Notifications
You must be signed in to change notification settings - Fork 4
/
cinder_create.sh
executable file
·265 lines (222 loc) · 7.15 KB
/
cinder_create.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
################################################################################
# Simple Nagios plugin to monitor cinder create #
# Author: Daniel Shirley #
################################################################################
VERSION="Version 0.01a"
AUTHOR="2014 Daniel Shirley (daniel.l.shirley@hp.com)"
PROGNAME=`/bin/basename $0`
PATH=`/usr/bin/dirname $0`
# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# File Includes ################################################################
. $PATH/enviroment.conf
# Helper functions #############################################################
function print_revision {
# Print the revision number
echo "$PROGNAME - $VERSION"
}
function print_usage {
# Print a short usage statement
echo "Usage: $PROGNAME [-v] -w <limit> -c <limit>"
}
function print_help {
# Print detailed help information
print_revision
echo "$AUTHOR"
echo "Check how long cinder create takes"
echo "Requires enviroment verables set in enviroment.conf and python-cinderclient installed"
echo "you can install this by typeing -- pip install python-cinderclient"
print_usage
/bin/cat <<__EOT
Options:
-h
Print detailed help screen
-V
Print version information
-w INTEGER
Exit with WARNING status if cinder create takes longer than (sec)
-c INTEGER
Exit with CRITICAL status if cinder create takes longer than (sec)
-v
Verbose output
__EOT
}
# Verbosity level
verbosity=0
# Warning threshold
thresh_warn=
# Critical threshold
thresh_crit=
# Parse command line options
while [ "$1" ]; do
case "$1" in
-h | --help)
print_help
exit $STATE_OK
;;
-V | --version)
print_revision
exit $STATE_OK
;;
-v | --verbose)
: $(( verbosity++ ))
shift
;;
-w | --warning | -c | --critical)
if [[ -z "$2" || "$2" = -* ]]; then
# Threshold not provided
echo "$PROGNAME: Option '$1' requires an argument"
print_usage
exit $STATE_UNKNOWN
elif [[ "$2" = +([0-9]) ]]; then
# Threshold is a number (MB)
thresh=$2
else
# Threshold is not a number
echo "$PROGNAME: Threshold must be an integer"
print_usage
exit $STATE_UNKNOWN
fi
[[ "$1" = *-w* ]] && thresh_warn=$thresh || thresh_crit=$thresh
shift 2
;;
-?)
print_usage
exit $STATE_OK
;;
*)
echo "$PROGNAME: Invalid option '$1'"
print_usage
exit $STATE_UNKNOWN
;;
esac
done
if [[ -z "$thresh_warn" || -z "$thresh_crit" ]]; then
# One or both thresholds were not specified
echo "$PROGNAME: Threshold not set"
print_usage
exit $STATE_UNKNOWN
elif [[ "$thresh_crit" -lt "$thresh_warn" ]]; then
# The warning threshold must be less than the critical threshold
echo "$PROGNAME: Warning time should be less than critical time"
print_usage
exit $STATE_UNKNOWN
fi
# Main #########################################################################
volid=noid
#remove old logger file if present
if [ -e /tmp/cindercreate.tmp ]
then
/bin/rm /tmp/cindercreate.tmp
fi
#create temp logging file
/bin/touch /tmp/cindercreate.tmp
#check if temp log file created successfully ... if not abandon all hope
if [ ! -e /tmp/cindercreate.tmp ]
then
echo "could not create temp logging file. please check the logs at /var/log/icinga/cinder_create.log"
echo "could not create temp logging file. /tmp/cindercreate.tmp" >> /var/log/icinga/cinder_create.log
exit $STATE_UNKNOWN
else
/bin/date > /tmp/cindercreate.tmp
fi
#start timeing now
time="$(/bin/date +%s)"
echo "create cinder volume" >> /tmp/cindercreate.tmp
$CINDER create 1 &>> /tmp/cindercreate.tmp
volid=$($GREP " id " /tmp/cindercreate.tmp | $CUT -d"|" -f3)
if [ $volid == "noid" ]
then
echo "could not find volume id" >> /tmp/cindercreate.tmp
/bin/cat /tmp/cindercreate.tmp >> /var/log/icinga/cinder_create.log
echo "could not find volume id please check logs /var/log/icinga/cinder_create.log"
exit $STATE_CRITICAL
else
echo "useing $volid as volume id" >> /tmp/cindercreate.tmp
fi
TIME=0
AVAILABLE="fasle"
echo "check if volume is available" >> /tmp/cindercreate.tmp
while [ "$AVAILABLE" = "fasle" ]
do
status=$($CINDER list | $GREP $volid)
if echo "$status" | $GREP -q "available"
then
AVAILABLE="true"
echo "volume is available" >> /tmp/cindercreate.tmp
$CINDER list &>> /tmp/cindercreate.tmp
elif echo "$status" | $GREP -q "error"
then
echo "volume created in error" >> /tmp/cindercreate.tmp
$CINDER list &>> /tmp/cindercreate.tmp
/bin/cat /tmp/cindercreate.tmp >> /var/log/icinga/cinder_create.log
echo "volume created in error please check logs /var/log/icinga/cinder_create.log"
exit $STATE_CRITICAL
fi
TIME="$(($(/bin/date +%s)-$time))"
if [ $TIME -gt $thresh_crit ]
then
echo "volume did not create in time" >> /tmp/cindercreate.tmp
$CINDER list &>> /tmp/cindercreate.tmp
/bin/cat /tmp/cindercreate.tmp >> /var/log/icinga/cinder_create.log
echo "volume did not create in time please check logs /var/log/icinga/cinder_create.log"
exit $STATE_CRITICAL
fi
done
echo "deleteing the volume" >> /tmp/cindercreate.tmp
$CINDER delete $volid &>> /tmp/cindercreate.tmp
DELETED="fasle"
while [ "$DELETED" = "fasle" ]
do
if !($CINDER list | $GREP -q $volid)
then
DELETED="true"
echo "volume was deleted" >> /tmp/cindercreate.tmp
$CINDER list &>> /tmp/cindercreate.tmp
fi
TIME="$(($(/bin/date +%s)-$time))"
if [ $TIME -gt $thresh_crit ]
then
echo "volume did not delete in time" >> /tmp/cindercreate.tmp
$CINDER list &> /tmp/cindercreate.tmp
/bin/cat /tmp/cindercreate.tmp >> /var/log/icinga/cinder_create.log
echo "volume did not delete in time please check logs /var/log/icinga/cinder_create.log"
exit $STATE_CRITICAL
fi
done
#end timeing
time="$(($(/bin/date +%s)-$time))"
# Verbosity settings ###########################################################
if [[ "$verbosity" -ge 2 ]]; then
# Print debugging information
/bin/cat <<__EOT
Debugging information:
Warning threshold: $thresh_warn SEC
Critical threshold: $thresh_crit SEC
Verbosity level: $verbosity
Completed Time: $time
CINDER Volume: $volid
Volume was available: $AVAILABLE
Volume was deleted: $DELETED
Log:
$(/bin/cat /tmp/cindercreate.tmp)
__EOT
fi
# Evaluate #####################################################################
if [[ "$time" -gt "$thresh_crit" ]]; then
# Cinder create took longer than the critical threshold
echo "CINDER CREATE CRITICAL - Took $time sec to complete"
exit $STATE_CRITICAL
elif [[ "$time" -gt "$thresh_warn" ]]; then
# Cinder create took longer than the warning threshold
echo "CINDER CREATE WARNING - Took $time sec to complete"
exit $STATE_WARNING
else
# Cinder create working!
echo "CINDER CREATE OK - Took $time sec to complete"
exit $STATE_OK
fi