From e502129656349a46881e2cd610f2890b90537d34 Mon Sep 17 00:00:00 2001 From: Baptiste Jonglez Date: Wed, 12 Feb 2014 15:47:27 +0100 Subject: [PATCH] Fix parsing of 'show protocols' with bird 1.4 The current parsing was broken because of a change in the date format. Actually, the new method is much simpler, and should resist small syntax changes in Bird's output. We don't use an ugly regexp anymore. Important limitation: parsing will be messed up if the date contains a space character. This does not happen with the default date format of both bird 1.3 and bird 1.4, but since the date format is configurable in bird, it may happen anyway. --- lg.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lg.py b/lg.py index 2c38dbb..5271b33 100644 --- a/lg.py +++ b/lg.py @@ -217,8 +217,6 @@ def whois(): SUMMARY_UNWANTED_PROTOS = ["Kernel", "Static", "Device"] -SUMMARY_RE_MATCH = r"(?P[\w_]+)\s+(?P\w+)\s+(?P\w+)\s+(?P\w+)\s+(?P((|\d\d\d\d-\d\d-\d\d\s)(|\d\d:)\d\d:\d\d|\w\w\w\d\d))($|\s+(?P.*))" - @app.route("/summary/") @app.route("/summary//") @@ -245,9 +243,16 @@ def summary(hosts, proto="ipv4"): for line in res[1:]: line = line.strip() if line and (line.split() + [""])[1] not in SUMMARY_UNWANTED_PROTOS: - m = re.match(SUMMARY_RE_MATCH, line) - if m: - data.append(m.groupdict()) + split = line.split() + if len(split) >= 5: + props = dict() + props["name"] = split[0] + props["proto"] = split[1] + props["table"] = split[2] + props["state"] = split[3] + props["since"] = split[4] + props["info"] = ' '.join(split[5:]) if len(split) > 5 else "" + data.append(props) else: app.logger.warning("couldn't parse: %s", line)