-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_dfs.py
More file actions
97 lines (67 loc) · 1.9 KB
/
check_dfs.py
File metadata and controls
97 lines (67 loc) · 1.9 KB
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
#!/usr/bin/python
"""
This nagios plug is checks Hadoop Datanodes
__author__ = "Fatih N. YARCI"
__license__ = "GPL"
__version__ = "0.1"
__email__ = "fatih.yarci@comodo.com"
__status__ = "alpha"
"""
from sys import argv, exit
from getopt import GetoptError, getopt
from subprocess import Popen, PIPE
from re import search
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3
HUSER = "hadoop"
DFSREPORTCMD = "sudo su - %s -c 'hadoop dfsadmin -report'"
def help():
print("help")
def get_dfs_report(huser=HUSER):
cmd = DFSREPORTCMD % (huser)
out = Popen('%s' % (cmd), shell=True, stdout=PIPE, stderr=None)
return (out.stdout.read().decode("utf-8"))
def description(text):
out = search("Datanodes[ \S+]+", text)
parsed_data = out.group()
return (parsed_data)
def live_nodes(text):
out = search("Datanodes[ \S+]+", text)
parsed_data = out.group()
l_nodes = search("[\d]", parsed_data)
return (l_nodes.group())
def main(argv):
try:
opts, args = getopt(argv, 'hw:c:', ['help', 'warning=', 'critical='])
except GetoptError:
help()
exit(UNKNOWN)
current = int(live_nodes(get_dfs_report()))
desc = description(get_dfs_report())
status = 'O'
for opt, arg in opts:
if opt in ('-h', '--help'):
help()
exit()
elif opt in ('-w', '--warning'):
w_limit = int(arg)
if current <= w_limit:
status = 'W'
print "WARNING - %s" % (desc)
exit(WARNING)
elif opt in ('-c', '--critical'):
c_limit = int(arg)
if current <= c_limit:
status = 'C'
print "CRITICAL - %s" % (desc)
exit(CRITICAL)
else:
help()
exit(UNKNOWN)
if status == 'O':
print "OK - %s" % (desc)
exit(OK)
if __name__ == '__main__':
main(argv[1:])