From 5bcd522d7752c96ceb4bf7aafa3a7c03c85905f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Angelo=20Gr=C3=BCndler?= Date: Fri, 8 Mar 2013 16:39:27 +0100 Subject: [PATCH] fixed module network.traceroute --- salt/modules/network.py | 49 +++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/salt/modules/network.py b/salt/modules/network.py index bbd684b9cc..55a555888a 100644 --- a/salt/modules/network.py +++ b/salt/modules/network.py @@ -436,8 +436,6 @@ def netstat(): return ret -# FIXME: This is broken on: Modern traceroute for Linux, version 2.0.14, May 10 2010 (Ubuntu 10.10) -# FIXME: traceroute is deprecated, make this fall back to tracepath def traceroute(host): ''' Performs a traceroute to a 3rd party host @@ -449,24 +447,47 @@ def traceroute(host): ret = [] cmd = 'traceroute {0}'.format(salt.utils.socket_util.sanitize_host(host)) out = __salt__['cmd.run'](cmd) + + # Parse version of traceroute + cmd2 = 'traceroute --version' + out2 = __salt__['cmd.run'](cmd2) + traceroute_version = re.findall(r'(?d+)', out2)[0:3] # FIXME: iprove regexp - for line in out: + for line in out.splitlines(): if not ' ' in line: continue if line.startswith('traceroute'): continue - comps = line.split() - result = { - 'count': comps[0], - 'hostname': comps[1], - 'ip': comps[2], - 'ms1': comps[4], - 'ms2': comps[6], - 'ms3': comps[8], - 'ping1': comps[3], - 'ping2': comps[5], - 'ping3': comps[7]} + comps = line.split(' ') + + if (traceroute_version[0] >= 2 and traceroute_version[2] >= 14 + or traceroute_version[0] >= 2 and traceroute_version[1] > 0): + if comps[1] == '* * *': + result = { + 'count': int(comps[0]), + 'hostname': '*'} + else: + result = { + 'count': int(comps[0]), + 'hostname': comps[1].split()[0], + 'ip': comps[1].split()[1].strip('()'), + 'ms1': float(comps[2].split()[0]), + 'ms2': float(comps[3].split()[0]), + 'ms3': float(comps[4].split()[0])} + else: + result = { + 'count': comps[0], + 'hostname': comps[1], + 'ip': comps[2], + 'ms1': comps[4], + 'ms2': comps[6], + 'ms3': comps[8], + 'ping1': comps[3], + 'ping2': comps[5], + 'ping3': comps[7]} + ret.append(result) + return ret