forked from jonschipp/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_fs_write.sh
executable file
·83 lines (69 loc) · 1.25 KB
/
check_fs_write.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
#!/usr/bin/env bash
# Author: Jon Schipp
# Date: 09-10-2014
########
# Examples:
# 1.) Check if sshd has restarted since last check
# $ ./check_fs_write.sh -o /var,/tmp
# Nagios Exit Codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
usage()
{
cat <<EOF
Notify if a filesystem is read-only by writing a file to it.
Options:
-f Specify custom filename (optional)
-o Specify destinations to write, comma separated
Usage: $0 -o /var,/home,/tmp,/nfs
EOF
}
if [ $# -lt 1 ];
then
usage
exit 1
fi
# Define now to prevent expected number errors
CHECK=0
CRIT=0
FILE=68b329da9893e34099c7d8ad5cb9c940
while getopts "hf:o:" OPTION
do
case $OPTION in
h)
usage
;;
f)
FILE="$OPTARG"
;;
o)
DIR=$(echo "$OPTARG" | sed 's/,/ /g');
CHECK=1
;;
\?)
exit 1
;;
esac
done
if [ $CHECK -eq 1 ]; then
for directory in $DIR
do
timeout 3s touch $directory/$FILE 2>/dev/null
if [ $? -ne 0 ]; then
echo "Failure to write file to ${directory}!"
CRIT=1
else
rm -f $directory/$FILE
echo "Success writing file to $directory"
fi
done
if [ $CRIT -eq 1 ]; then
echo "State: CRITICAL"
exit $CRITICAL
else
echo "State: OK"
exit $OK
fi
fi