Skip to content

Commit

Permalink
hostwatch: handle fully qualified domain names
Browse files Browse the repository at this point in the history
(slightly modified by apenwarr)
  • Loading branch information
georgeguimaraes authored and apenwarr committed Jul 6, 2012
1 parent 432e98c commit 6450c37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 10 additions & 5 deletions hostwatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6450c37

Please sign in to comment.