-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_disk_all.sh
160 lines (146 loc) · 4.4 KB
/
check_disk_all.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
#!/bin/bash
#
# check_disk_all.sh is a bash function to check Linux filesystem
# Copyright (C) 2017 Ramon Roman Castro <[email protected]>
#
# 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.
#
# 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.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see http://www.gnu.org/licenses/.
#
# @package nagios-plugins
# @author Ramon Roman Castro <[email protected]>
# @link http://www.rrc2software.com
# @link https://github.com/ramonromancastro/nagios-plugins
# Changes
# 1.1 Minor changes
# Replace [df -k] by [df -kP | tail -n$((\`df -kP | wc -l\`-1))]
# Add perfomance data
# 1.2 Parameters by identifiers not by position
# Add [-h] and [-V] options
# 1.2.1 Minor changes
# 1.3 Now checks used% and not free%
# 1.4 Checks free% and not used% again (like check_disk plugin)
# Add warn and crit values on perfomance data
# Now, -w and -c are not mandatory arguments
# 1.5 Now checks used% and not free%
# 1.6 Now include exclude/only filesystem type
# 1.7 Perfomance data fixed
# ----------------------------------
# VARIABLES
# ----------------------------------
VERSION="1.7"
WARNING=80
CRITICAL=90
EXCLUDE=
ONLY=
# ----------------------------------
# FUNCTIONS
# ----------------------------------
function print_version(){
echo "$0 - version $VERSION"
exit 0
}
function print_usage(){
echo "Usage: $0 (-w <warn>) (-c <crit>) (-x <fs>) (-h) (-V)"
exit 3
}
function print_help(){
echo 'Nagios Filesystem Plugin'
echo ''
echo 'This plugin is not developed by the Nagios Plugin group.'
echo 'Please do not e-mail them for support on this plugin.'
echo ''
echo 'For contact info, please read the plugin script file.'
echo ''
echo "Usage: $0 (-w <warn>) (-c <crit>) (-x <fs>|-o <fs>) (-h) (-V)"
echo '---------------------------------------------------------------------'
echo 'Usable Options:'
echo ''
echo ' -w <warn>'
echo " warning threshold (% of consumable used) [default: $WARNING]"
echo ' -c <crit>'
echo " critical threshold (% of consumable used) [default: $CRITICAL]"
echo ' -x <fs>'
echo ' excluded file system'
echo ' -o <fs>'
echo ' only filesystem type'
echo ' -h'
echo ' show this help screen'
echo ' -V'
echo ' show the current version of the plugin'
echo ''
echo 'Examples:'
echo " $0 -w 80 -c 90"
echo " $0 -w 80 -c 90 -x nfs"
echo " $0 -V"
echo ''
echo '---------------------------------------------------------------------'
exit 3
}
# ----------------------------------
# MAIN CODE
# ----------------------------------
#if [ $# -eq 0 ]; then
# print_usage
#fi
while getopts "w:c:x:o:hV" OPTION;
do
case $OPTION in
"w")
WARNING=$OPTARG
;;
"c")
CRITICAL=$OPTARG
;;
"x")
EXCLUDE=$OPTARG
;;
"o")
ONLY=$OPTARG
;;
"h")
print_help
;;
"V")
print_version
;;
*)
print_help
;;
esac
done
if [ "$WARNING" -ge "$CRITICAL" ]
then
echo "Warning value must be less than critical value"
exit 3
fi
# Output for the dashboard
DF_CMD="df -kP"
if [ "$ONLY" != "" ]; then
DF_CMD="${DF_CMD} -t ${ONLY}";
elif [ "$EXCLUDE" != "" ]; then
DF_CMD="${DF_CMD} -x ${EXCLUDE}";
fi
`$DF_CMD > /dev/null 2>&1`
if [ $? -ne 0 ]; then
echo "DISK USAGE UNKNOWN: No file systems processed" ; exit 3
fi
DF=`$DF_CMD | sed 1d`
RESULT=$(${DF_CMD} | sed 1d | grep -v devices|grep -v cdrom|grep -v proc|awk '{ print $6"("$5 ") "}'|sort -nr|tr -d '\n')
PERFOMANCE=$(${DF_CMD} | sed 1d | grep -v devices|grep -v cdrom|grep -v proc|awk -v WARNING="$WARNING" -v CRITICAL="$CRITICAL" '{ print "'\''" $6 " %" "'\''" "="int($5)"%;"WARNING";"CRITICAL" "}'|tr -d '\n')
i=$(${DF_CMD} | sed 1d | grep -v devices|grep -v cdrom|grep -v proc|awk '{print int($5)}'|sort -nr| head -n1)
if [ "$i" -gt "$CRITICAL" ] ; then
echo "DISK USAGE CRITICAL: $RESULT\n|$PERFOMANCE" ; exit 2
elif [ "$i" -gt "$WARNING" ] ; then
echo -e "DISK USAGE WARNING: $RESULT\n|$PERFOMANCE" ; exit 1
else
echo -e "DISK USAGE OK: $RESULT\n|$PERFOMANCE" ; exit 0
fi