diff --git a/lg.py b/lg.py index b1d24ff..24c30f4 100755 --- a/lg.py +++ b/lg.py @@ -317,7 +317,7 @@ def get_as_name(_as): """ if not _as.isdigit(): - return _as + return _as.strip() if _as not in ASNAME_CACHE: whois_answer = whois_command("as%s" % _as) @@ -332,6 +332,14 @@ def get_as_name(_as): else: return "AS%s\r%s" % (_as, ASNAME_CACHE[_as]) +def get_as_number_from_protocol_name(host, proto, protocol): + ret, res = bird_command(host, proto, "show protocols all %s" % protocol) + re_asnumber = re.search("Neighbor AS:\s*(\d*)", res) + if re_asnumber: + return re_asnumber.group(1) + else: + return "?????" + @app.route("/bgpmap/") def show_bgpmap(): @@ -350,7 +358,7 @@ def show_bgpmap(): def add_node(_as, **kwargs): if _as not in nodes: - kwargs["label"] = kwargs.get("label", get_as_name(_as)) + kwargs["label"] = '<
' + kwargs.get("label", get_as_name(_as)).replace("\r"," ") + " |
" + graph.create_dot() + "") return Response(graph.create_png(), mimetype='image/png') @@ -430,17 +456,14 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text): peer_protocol_name = expr.group(3).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 if peer_ip in rt_ips: path = [rt_host] break - else: # retreive as number from bird - ret, res = bird_command(host, proto, "show protocols all %s" % peer_protocol_name) - re_asnumber = re.search("Neighbor AS:\s*(\d*)", res) - if re_asnumber: - path = [re_asnumber.group(1)] - else: - print "Missing retreive some information for the path" - path = ["as?????"] + else: + # ugly hack for good printing + 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)))] if line.startswith("BGP.as_path:"): path.extend(line.replace("BGP.as_path:", "").strip().split(" "))