Update bgp-summ.py
This commit is contained in:
parent
61ec8b669b
commit
063eeaa14e
1 changed files with 48 additions and 9 deletions
57
bgp-summ.py
57
bgp-summ.py
|
|
@ -17,19 +17,27 @@ def run_curl_command():
|
||||||
def parse_bgp_data(data):
|
def parse_bgp_data(data):
|
||||||
ipv4_section = ""
|
ipv4_section = ""
|
||||||
ipv6_section = ""
|
ipv6_section = ""
|
||||||
|
ipv4_info = {}
|
||||||
|
ipv6_info = {}
|
||||||
|
|
||||||
if "data" in data:
|
if "data" in data:
|
||||||
raw_data = data["data"]
|
raw_data = data["data"]
|
||||||
|
|
||||||
if "IPv4 Unicast Summary" in raw_data:
|
if "IPv4 Unicast Summary" in raw_data:
|
||||||
ipv4_section = raw_data.split("IPv4 Unicast Summary (VRF default):")[1].split("IPv6 Unicast Summary (VRF default):")[0].strip()
|
ipv4_raw = raw_data.split("IPv4 Unicast Summary (VRF default):")[1]
|
||||||
|
ipv4_section = ipv4_raw.split("IPv6 Unicast Summary (VRF default):")[0].strip()
|
||||||
|
ipv4_info = extract_bgp_info(ipv4_raw)
|
||||||
|
|
||||||
if "IPv6 Unicast Summary" in raw_data:
|
if "IPv6 Unicast Summary" in raw_data:
|
||||||
ipv6_section = raw_data.split("IPv6 Unicast Summary (VRF default):")[1].strip()
|
ipv6_raw = raw_data.split("IPv6 Unicast Summary (VRF default):")[1].strip()
|
||||||
|
ipv6_section = ipv6_raw
|
||||||
|
ipv6_info = extract_bgp_info(ipv6_raw)
|
||||||
|
|
||||||
def process_peers(peer_data):
|
def process_peers(peer_data):
|
||||||
peers = []
|
peers = []
|
||||||
for line in peer_data.split("\n"):
|
for line in peer_data.split("\n"):
|
||||||
|
if line.strip().startswith("Neighbor"):
|
||||||
|
continue
|
||||||
if line.strip():
|
if line.strip():
|
||||||
peer_info = line.split()
|
peer_info = line.split()
|
||||||
if len(peer_info) >= 12:
|
if len(peer_info) >= 12:
|
||||||
|
|
@ -52,9 +60,31 @@ def parse_bgp_data(data):
|
||||||
ipv4_peers = process_peers(ipv4_section)
|
ipv4_peers = process_peers(ipv4_section)
|
||||||
ipv6_peers = process_peers(ipv6_section)
|
ipv6_peers = process_peers(ipv6_section)
|
||||||
|
|
||||||
return ipv4_peers, ipv6_peers
|
return ipv4_info, ipv4_peers, ipv6_info, ipv6_peers
|
||||||
|
|
||||||
def generate_html_table(ipv4_peers, ipv6_peers):
|
def extract_bgp_info(raw_data):
|
||||||
|
lines = raw_data.split("\n")
|
||||||
|
info = {}
|
||||||
|
for line in lines:
|
||||||
|
if "BGP router identifier" in line:
|
||||||
|
parts = line.split(",")
|
||||||
|
info["router_id"] = parts[0].split("identifier")[1].strip()
|
||||||
|
info["local_as"] = parts[1].split("number")[1].strip().split(" ")[0]
|
||||||
|
if "vrf-id" in parts[-1]:
|
||||||
|
info["vrf_id"] = parts[-1].split("vrf-id")[1].strip()
|
||||||
|
if "BGP table version" in line:
|
||||||
|
info["table_version"] = line.split("version")[1].strip()
|
||||||
|
if "RIB entries" in line:
|
||||||
|
parts = line.split(",")
|
||||||
|
info["rib_entries"] = parts[0].split("entries")[1].strip()
|
||||||
|
info["rib_memory"] = parts[1].split("using")[1].strip()
|
||||||
|
if "Peers" in line:
|
||||||
|
parts = line.split(",")
|
||||||
|
info["peers"] = parts[0].split("Peers")[1].strip()
|
||||||
|
info["peers_memory"] = parts[1].split("using")[1].strip()
|
||||||
|
return info
|
||||||
|
|
||||||
|
def generate_html_table(ipv4_info, ipv4_peers, ipv6_info, ipv6_peers):
|
||||||
html_template = """
|
html_template = """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
@ -98,6 +128,10 @@ def generate_html_table(ipv4_peers, ipv6_peers):
|
||||||
<h1 class="center-align">Core1.Doet.pixelHosting.nl BGP summary</h1>
|
<h1 class="center-align">Core1.Doet.pixelHosting.nl BGP summary</h1>
|
||||||
|
|
||||||
<h4>IPv4 Unicast Summary</h4>
|
<h4>IPv4 Unicast Summary</h4>
|
||||||
|
<p>BGP Router ID: {{ ipv4_info.router_id }}, Local AS Number: {{ ipv4_info.local_as }} VRF ID: {{ ipv4_info.vrf_id }}</p>
|
||||||
|
<p>BGP Table Version: {{ ipv4_info.table_version }}</p>
|
||||||
|
<p>RIB Entries: {{ ipv4_info.rib_entries }}, using {{ ipv4_info.rib_memory }}</p>
|
||||||
|
<p>Peers: {{ ipv4_info.peers }}, using {{ ipv4_info.peers_memory }}</p>
|
||||||
<input type="text" id="ipv4Search" placeholder="Search in IPv4 table..." onkeyup="filterTable('ipv4Search', 'ipv4Table')">
|
<input type="text" id="ipv4Search" placeholder="Search in IPv4 table..." onkeyup="filterTable('ipv4Search', 'ipv4Table')">
|
||||||
<table class="striped" id="ipv4Table">
|
<table class="striped" id="ipv4Table">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
@ -137,6 +171,10 @@ def generate_html_table(ipv4_peers, ipv6_peers):
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h4>IPv6 Unicast Summary</h4>
|
<h4>IPv6 Unicast Summary</h4>
|
||||||
|
<p>BGP Router ID: {{ ipv6_info.router_id }}, Local AS Number: {{ ipv6_info.local_as }} VRF ID: {{ ipv6_info.vrf_id }}</p>
|
||||||
|
<p>BGP Table Version: {{ ipv6_info.table_version }}</p>
|
||||||
|
<p>RIB Entries: {{ ipv6_info.rib_entries }}, using {{ ipv6_info.rib_memory }}</p>
|
||||||
|
<p>Peers: {{ ipv6_info.peers }}, using {{ ipv6_info.peers_memory }}</p>
|
||||||
<input type="text" id="ipv6Search" placeholder="Search in IPv6 table..." onkeyup="filterTable('ipv6Search', 'ipv6Table')">
|
<input type="text" id="ipv6Search" placeholder="Search in IPv6 table..." onkeyup="filterTable('ipv6Search', 'ipv6Table')">
|
||||||
<table class="striped" id="ipv6Table">
|
<table class="striped" id="ipv6Table">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
@ -210,17 +248,16 @@ def generate_html_table(ipv4_peers, ipv6_peers):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template = Template(html_template)
|
template = Template(html_template)
|
||||||
html_output = template.render(ipv4_peers=ipv4_peers, ipv6_peers=ipv6_peers)
|
html_output = template.render(ipv4_info=ipv4_info, ipv4_peers=ipv4_peers, ipv6_info=ipv6_info, ipv6_peers=ipv6_peers)
|
||||||
|
|
||||||
return html_output
|
return html_output
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def bgp_peer_summary():
|
def bgp_peer_summary():
|
||||||
data = run_curl_command()
|
data = run_curl_command()
|
||||||
|
|
||||||
ipv4_peers, ipv6_peers = parse_bgp_data(data)
|
ipv4_info, ipv4_peers, ipv6_info, ipv6_peers = parse_bgp_data(data)
|
||||||
|
|
||||||
html_output = generate_html_table(ipv4_peers, ipv6_peers)
|
html_output = generate_html_table(ipv4_info, ipv4_peers, ipv6_info, ipv6_peers)
|
||||||
|
|
||||||
return render_template_string(html_output)
|
return render_template_string(html_output)
|
||||||
|
|
||||||
|
|
@ -228,10 +265,12 @@ def bgp_peer_summary():
|
||||||
def bgp_peer_summary_json():
|
def bgp_peer_summary_json():
|
||||||
data = run_curl_command()
|
data = run_curl_command()
|
||||||
|
|
||||||
ipv4_peers, ipv6_peers = parse_bgp_data(data)
|
ipv4_info, ipv4_peers, ipv6_info, ipv6_peers = parse_bgp_data(data)
|
||||||
|
|
||||||
json_data = {
|
json_data = {
|
||||||
|
"ipv4_info": ipv4_info,
|
||||||
"ipv4_peers": ipv4_peers,
|
"ipv4_peers": ipv4_peers,
|
||||||
|
"ipv6_info": ipv6_info,
|
||||||
"ipv6_peers": ipv6_peers
|
"ipv6_peers": ipv6_peers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue