-
Notifications
You must be signed in to change notification settings - Fork 4
/
cinder_list.sh
executable file
·166 lines (144 loc) · 4.55 KB
/
cinder_list.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
#!/bin/bash
################################################################################
# Simple Nagios plugin to monitor cinder list #
# Author: Daniel Shirley #
################################################################################
VERSION="Version 1.0"
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 list 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 list takes longer than (sec)
-c INTEGER
Exit with CRITICAL status if cinder list 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 #########################################################################
time="$(/bin/date +%s)"
cinder_output="$($CINDER list 2>&1)"
if [[ $? -gt 0 ]]; then
echo "CINDER LIST CRITICAL - Command failed please check the logs at /var/log/icinga/cinder_list_check.log"
echo "$(/bin/date)" >> /var/log/icinga/cinder_list_check.log
echo "$cinder_output" >> /var/log/icinga/cinder_list_check.log
exit $STATE_CRITICAL
fi
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 Output: $cinder_output
__EOT
fi
# Evaluate #####################################################################
if [[ "$time" -gt "$thresh_crit" ]]; then
# Cinder list took longer than the critical threshold
echo "CINDER LIST CRITICAL - Took $time sec to complete"
exit $STATE_CRITICAL
elif [[ "$time" -gt "$thresh_warn" ]]; then
# Cinder list took longer than the warning threshold
echo "CINDER LIST WARNING - Took $time sec to complete"
exit $STATE_WARNING
else
# Cinder list working!
echo "CINDER LIST OK - Took $time sec to complete"
exit $STATE_OK
fi