-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_hadoop-deadnodes.sh
executable file
·116 lines (102 loc) · 2.67 KB
/
check_hadoop-deadnodes.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
#!/bin/sh
PROGNAME=`basename $0`
VERSION="Version 2.0,"
AUTHOR="2009, Mike Adolphs (http://www.matejunkie.com/)"
AUTHOR="2013, Florian Baumann (http://noqqe.de)"
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
print_version() {
echo "$VERSION $AUTHOR"
}
print_help() {
print_version $PROGNAME $VERSION
echo ""
echo "$PROGNAME is a Icinga plugin to check the status of HDFS, Hadoop's"
echo "underlying, redundant, distributed file system."
echo ""
echo "$PROGNAME -w 10 -c 5"
echo ""
echo "Options:"
echo " -w|--warning)"
echo " Defines the warning level for dead nodes"
echo " -c|--critical)"
echo " Defines the critical level for dead nodes"
exit $ST_UK
}
while test -n "$1"; do
case "$1" in
--help|-h)
print_help
exit $ST_UK
;;
--version|-v)
print_version $PROGNAME $VERSION
exit $ST_UK
;;
--warning|-w)
warning=$2
shift
;;
--critical|-c)
critical=$2
shift
;;
*)
echo "Unknown argument: $1"
print_help
exit $ST_UK
;;
esac
shift
done
check_sanity() {
if [ -n "$warning" -a -n "$critical" ]; then
if [ ${warning} -gt ${critical} ]; then
echo "ERR: Confusing warning and critical values"
exit $ST_UK
fi
else
echo "ERR: Missing value, see --help"
exit $ST_UK
fi
if [ ! -x "$(which hdfs)" ]; then
echo "ERR: hdfs not installed"
exit $ST_UK
fi
}
get_vals() {
tmp_vals=`sudo /usr/local/bin/genhdfsreport.sh 2>/dev/null`
dn_avail=`echo -e "$tmp_vals" | grep -m1 "Datanodes available:" | awk '{print $3}'`
dn_total=`echo -e "$tmp_vals" | grep -m1 "Datanodes available:" | awk '{print $4}'`
dn_total=`echo $dn_total | awk -F\( '{print $2}'`
dn_dead=`echo -e "$tmp_vals" | grep -m1 "Datanodes available:" | awk '{print $6}'`
}
do_output() {
output="Nodes available: ${dn_avail}, Nodes total: ${dn_total}, Nodes dead: ${dn_dead}"
}
do_perfdata() {
perfdata="'dn_avail'=${dn_avail} 'dn_total'=${dn_total} 'dn_dead'=${dn_dead}"
}
# Runtime
check_sanity
get_vals
do_output
do_perfdata
# Nagios plugin data
if [ -n "$warning" -a -n "$critical" ] ; then
if [ "$dn_dead" -ge "$warning" -a "$dn_dead" -lt "$critical" ] ; then
echo "WARNING - ${output} | ${perfdata}"
exit $ST_WR
elif [ "$dn_dead" -ge "$critical" ]; then
echo "CRITICAL - ${output} | ${perfdata}"
exit $ST_CR
else
echo "OK - ${output} | ${perfdata} "
exit $ST_OK
fi
else
echo "OK - ${output} | ${perfdata}"
exit $ST_OK
fi