forked from jonschipp/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_filesystem_stat.sh
executable file
·81 lines (64 loc) · 1.31 KB
/
check_filesystem_stat.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
#!/usr/bin/env bash
# Author: Jon Schipp
########
# Examples:
# 1.) Return critical if stat does not exit successfully
# $ ./check_filesystem_errors.sh -p /mnt -d 2
#
# Nagios Exit Codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
usage()
{
cat <<EOF
Nagios plug-in that recursively checks for filesystem input/output
errors by directory using stat.
Options:
-p <dir> Directory or mountpoint to begin
-d <int> Depth i.e. level of subdirectories to check (def: 1)
EOF
}
argcheck() {
if [ $ARGC -lt $1 ]; then
echo "Please specify an argument!, try $0 -h for more information"
exit 1
fi
}
DEPTH=1
CHECK=0
COUNT=0
ARGC=$#
# Print warning and exit if less than n arguments specified
argcheck 1
# option and argument handling
while getopts "hp:d:" OPTION
do
case $OPTION in
h)
usage
exit $UNKNOWN
;;
p)
CHECK=1
DIR=$OPTARG
;;
d)
DEPTH=$OPTARG
;;
*)
exit $UNKNOWN
;;
esac
done
if [ $CHECK -eq 1 ]; then
find $DIR -maxdepth $DEPTH -type d -print0 | xargs -0 -I file sh -c 'stat "file" 1>/dev/null 2>/dev/null || (echo "Error file" && exit 2)'
if [ $? -gt 0 ]; then
echo "CRITICAL: Found filesystem errors"
exit $CRITICAL
else
echo "OK: No filesystem errors found"
exit $OK
fi
fi