blob: d27221a6eec8a2871d91e9627982f6f24db644eb (
plain)
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
|
#!/bin/sh
### Monitor free disk space
# Display alert if the free percentage of space is >= $ALERT
#
# Static Config Variables
#
ALERT=90 # free space percentage to trigger an alert
#
# Static Binary Paths
#
DF='/bin/df'
GREP='/usr/bin/grep'
AWK='/usr/bin/awk'
CUT='/usr/bin/cut'
HOSTNAME='/usr/bin/hostname'
DATE='/bin/date'
MSG_CLIENT='/usr/LH/bin/msg_client.py --msg'
export DISPLAY=:0.0
#
# Static System Variables
#
THIS_HOST=`${HOSTNAME}`
#
# Check CLI Options
#
VERBOSE=false
OSD=false
for ARG in "$@" ; do
case $ARG in
"-v")
VERBOSE=true
;;
"-osd")
OSD=true
;;
esac
done
[ $VERBOSE = true ] && echo "Checking free disk space on ${THIS_HOST}"
[ $VERBOSE = true ] && echo "Threshold for warning is ${ALERT}%"
[ $VERBOSE = true ] && echo "------------------------------------------------------------------"
# Dynamic Variables
#DATE_STR=`${DATE} "+%d-%B-%y @ %H%Mhrs"`
# Call df to find the used percentages. Grep for only local disks (not remote mounts like nfs or smb)
# Pipe the output to awk to get the needed columns, then start a while loop to process each line.
$DF -HPl | $GREP -E "^/dev/" | $AWK '{ print $5 " " $6 " " $1 }' | while read OUTPUT ; do
USED_PCENT=$(echo ${OUTPUT} | $AWK '{ print $1}' | $CUT -d'%' -f1 ) # Used space as a percentage
PARTITION=$(echo ${OUTPUT} | $AWK '{ print $2 }' ) # Mount Point (eg, /home)
DEVICE=$(echo ${OUTPUT} | $AWK '{ print $3 }' ) # Device (eg, /dev/sda1 or LABEL or UUID)
if [ $VERBOSE = true ] ; then
echo -e "Checking device ${DEVICE} which is mounted to ${PARTITION} \t${USED_PCENT}% used"
fi
if [ ${USED_PCENT} -ge $ALERT ]; then
if [ $VERBOSE = true ] ; then
echo "WARNING: ${PARTITION} (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}."
else
echo "WARNING: ${PARTITION} (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}." #|
if [ $OSD = true ] && [ ${PARTITION} = / ]; then
$MSG_CLIENT "WARNING: The root (${PARTITION}) partition is ${USED_PCENT}% full on ${THIS_HOST}."
fi
fi
fi
done
exit 0
|