mirror of
https://github.com/sileht/bird-lg.git
synced 2025-03-25 21:44:27 +01:00
Correctly parse bird-2.0 output
This commit is contained in:
parent
58c1b01719
commit
026123063c
1 changed files with 21 additions and 11 deletions
32
lg.py
32
lg.py
|
@ -223,8 +223,7 @@ def whois():
|
|||
|
||||
|
||||
SUMMARY_UNWANTED_PROTOS = ["Kernel", "Static", "Device"]
|
||||
SUMMARY_RE_MATCH = r"(?P<name>[\w_]+)\s+(?P<proto>\w+)\s+(?P<table>\w+)\s+(?P<state>\w+)\s+(?P<since>((|\d\d\d\d-\d\d-\d\d\s)|(\d\d:)\d\d:\d\d|\w\w\w\d\d))($|\s+(?P<info>.*))"
|
||||
|
||||
SUMMARY_RE_MATCH = r"(?P<name>[\w_]+)\s+(?P<proto>\w+)\s+(?P<table>\w+|-{3})\s+(?P<state>\w+)\s+(?P<since>((|\d\d\d\d-\d\d-\d\d\s)|(\d\d:)\d\d:\d\d|\w\w\w\d\d|\d\d:\d\d:\d\d\.\d\d\d))($|\s+(?P<info>.*))"
|
||||
|
||||
@app.route("/summary/<hosts>")
|
||||
@app.route("/summary/<hosts>/<proto>")
|
||||
|
@ -533,21 +532,29 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text):
|
|||
path = None
|
||||
paths = []
|
||||
net_dest = None
|
||||
peer_protocol_name = None
|
||||
for line in text:
|
||||
line = line.strip()
|
||||
|
||||
expr = re.search(r'(.*)via\s+([0-9a-fA-F:\.]+)\s+on.*\[(\w+)\s+', line)
|
||||
expr = re.search(r'(.*)unicast\s+\[(\w+)\s+', line)
|
||||
if expr:
|
||||
if expr.group(1).strip():
|
||||
net_dest = expr.group(1).strip()
|
||||
peer_protocol_name = expr.group(2).strip()
|
||||
|
||||
expr2 = re.search(r'(.*)via\s+([0-9a-fA-F:\.]+)\s+on\s+\w+(\s+\[(\w+)\s+)?', line)
|
||||
if expr2:
|
||||
if path:
|
||||
path.append(net_dest)
|
||||
paths.append(path)
|
||||
path = None
|
||||
|
||||
if expr.group(1).strip():
|
||||
net_dest = expr.group(1).strip()
|
||||
if expr2.group(1).strip():
|
||||
net_dest = expr2.group(1).strip()
|
||||
|
||||
peer_ip = expr.group(2).strip()
|
||||
peer_protocol_name = expr.group(3).strip()
|
||||
peer_ip = expr2.group(2).strip()
|
||||
if expr2.group(4):
|
||||
peer_protocol_name = expr2.group(4).strip()
|
||||
# Check if via line is a internal route
|
||||
for rt_host, rt_ips in app.config["ROUTER_IP"].iteritems():
|
||||
# Special case for internal routing
|
||||
|
@ -559,15 +566,18 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text):
|
|||
path = [ peer_protocol_name ]
|
||||
# path = ["%s\r%s" % (peer_protocol_name, get_as_name(get_as_number_from_protocol_name(host, proto, peer_protocol_name)))]
|
||||
|
||||
expr2 = re.search(r'(.*)unreachable\s+\[(\w+)\s+', line)
|
||||
if expr2:
|
||||
expr3 = re.search(r'(.*)unreachable\s+\[(\w+)\s+', line)
|
||||
if expr3:
|
||||
if path:
|
||||
path.append(net_dest)
|
||||
paths.append(path)
|
||||
path = None
|
||||
|
||||
if expr2.group(1).strip():
|
||||
net_dest = expr2.group(1).strip()
|
||||
if path is None:
|
||||
path = [ expr3.group(2).strip() ]
|
||||
|
||||
if expr3.group(1).strip():
|
||||
net_dest = expr3.group(1).strip()
|
||||
|
||||
if line.startswith("BGP.as_path:"):
|
||||
path.extend(line.replace("BGP.as_path:", "").strip().split(" "))
|
||||
|
|
Loading…
Add table
Reference in a new issue