Permalink
Browse files

hostwatch: handle fully qualified domain names

(slightly modified by apenwarr)
1 parent 432e98c commit 6450c37043c37b1d5df355efeb360c02f95d49eb @georgeguimaraes georgeguimaraes committed with May 20, 2011
Showing with 11 additions and 6 deletions.
  1. +1 −1 client.py
  2. +10 −5 hostwatch.py
View
@@ -163,7 +163,7 @@ def start(self):
raise Fatal('%r expected STARTED, got %r' % (self.argv, line))
def sethostip(self, hostname, ip):
- assert(not re.search(r'[^-\w]', hostname))
+ assert(not re.search(r'[^-\w\.]', hostname))
assert(not re.search(r'[^0-9.]', ip))
self.pfile.write('HOST %s,%s\n' % (hostname, ip))
self.pfile.flush()
View
@@ -51,15 +51,20 @@ def read_host_cache():
words = line.strip().split(',')
if len(words) == 2:
(name,ip) = words
- name = re.sub(r'[^-\w]', '-', name).strip()
+ name = re.sub(r'[^-\w\.]', '-', name).strip()
ip = re.sub(r'[^0-9.]', '', ip).strip()
if name and ip:
found_host(name, ip)
-
-def found_host(hostname, ip):
- hostname = re.sub(r'\..*', '', hostname)
- hostname = re.sub(r'[^-\w]', '_', hostname)
+
+def found_host(full_hostname, ip):
+ full_hostname = re.sub(r'[^-\w\.]', '_', full_hostname)
+ hostname = re.sub(r'\..*', '', full_hostname)
+ _insert_host(full_hostname, ip)
+ _insert_host(hostname, ip)
+
+
+def _insert_host(hostname, ip):
if (ip.startswith('127.') or ip.startswith('255.')
or hostname == 'localhost'):
return

0 comments on commit 6450c37

Please sign in to comment.