forked from PabloCastellano/pablog-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmunin-check-reachable.py
More file actions
47 lines (37 loc) · 924 Bytes
/
munin-check-reachable.py
File metadata and controls
47 lines (37 loc) · 924 Bytes
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
#!/usr/bin/env python
import os
import socket
import sys
import re
# Disable output buffering
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
# TODO: Use threads
# TODO: port not default
config = '/etc/munin/munin.conf'
hosts = []
def readconfig(filename):
global hosts
with open(filename) as fp:
for line in fp.readlines():
match = re.match('^\s+address\s+(.*)\s*$', line)
if match:
hosts.append(match.group(1))
def checkhost(host, port=4949):
s = socket.socket()
res = 'FAILED'
try:
s.connect((host, port))
buf = s.recv(100)
if 'munin' in buf:
res = 'OK'
else:
res = 'UNKNOWN'
except:
pass
return res
if __name__ == '__main__':
readconfig(config)
for host in hosts:
print "Checking host %s...\t" % host,
res = checkhost(host)
print res