-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathcheck_volume.sh
executable file
·86 lines (75 loc) · 1.66 KB
/
check_volume.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
#!/usr/bin/env bash
# Nagios Exit Codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
usage()
{
cat <<EOF
Check the capacity of a volume using df.
Options:
-v Specify volume as mountpoint
-c Critical threshold as an int (0-100)
-w Warning threshold as an int (0-100)
-s Skip threshold checks
Usage: $0 -v /mnt -c 95 -w 90
EOF
}
if [ $# -lt 6 ];
then
usage
exit 1
fi
# Define now to prevent expected number errors
VOL=/dev/da0
CRIT=0
WARN=0
SKIP=0
OS=$(uname)
while getopts "hc:sv:w:" OPTION
do
case $OPTION in
h)
usage
;;
c)
CRIT="$OPTARG"
;;
s)
SKIP=1
;;
v)
VOL="$OPTARG"
;;
w)
WARN="$OPTARG"
;;
\?)
exit 1
;;
esac
done
if [[ $OS == AIX ]]; then
STATUS=$(df "$VOL" | awk '!/Filesystem/ { print $4 }' | sed 's/%//')
SIZE=$(df -P -m "$VOL" | awk '!/Filesystem/ { print $4 }')
USED=$(df -P -m "$VOL" | awk '!/Filesystem/ { print $3 }')
else
STATUS=$(df -h "$VOL" | awk '!/Filesystem/ { print $5 }' | sed 's/%//')
SIZE=$(df -h "$VOL" | awk '!/Filesystem/ { print $2 }')
USED=$(df -h "$VOL" | awk '!/Filesystem/ { print $3 }')
fi
if [ $SKIP -eq 1 ]; then
echo "$VOL is at ${STATUS}% capacity, $USED of $SIZE (Threshold skipped)"
exit $OK
fi
if [ $STATUS -gt $CRIT ]; then
echo "$VOL is at ${STATUS}% capacity! $USED of $SIZE"
exit $CRITICAL
elif [ $STATUS -gt $WARN ]; then
echo "$VOL is at ${STATUS}% capacity! $USED of $SIZE"
exit $WARNING
else
echo "$VOL is at ${STATUS}% capacity, $USED of $SIZE"
exit $OK
fi