From 6450c37043c37b1d5df355efeb360c02f95d49eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?George=20Guimara=CC=83es?= Date: Fri, 20 May 2011 14:47:11 -0300 Subject: [PATCH] hostwatch: handle fully qualified domain names (slightly modified by apenwarr) --- client.py | 2 +- hostwatch.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client.py b/client.py index 06fc573..a03ac3a 100644 --- a/client.py +++ b/client.py @@ -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() diff --git a/hostwatch.py b/hostwatch.py index 66e7461..e2bdb2b 100644 --- a/hostwatch.py +++ b/hostwatch.py @@ -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