Add script for collection subnets from route servers
This commit is contained in:
parent
9fbd4bb1bc
commit
95630556e8
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
from StringIO import StringIO
|
||||
import pprint
|
||||
import shelve
|
||||
import shelve
|
||||
|
||||
#
|
||||
# Add withdrawal option
|
||||
#
|
||||
|
||||
database = shelve.open("/var/lib/bgp_network_collector.db")
|
||||
|
||||
while True:
|
||||
try:
|
||||
line = sys.stdin.readline().strip()
|
||||
# print >> sys.stderr, "GOT A LINE: ", line
|
||||
sys.stdout.flush()
|
||||
|
||||
io = StringIO(line)
|
||||
decoded_update = json.load(io)
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4, stream=sys.stderr)
|
||||
#pp.pprint(decoded_update)
|
||||
|
||||
try:
|
||||
current_announce = decoded_update["neighbor"]["message"]["update"]["announce"]["ipv4 unicast"]
|
||||
#pp.pprint(current_announce)
|
||||
|
||||
for next_hop in current_announce:
|
||||
current_announce_for_certain_next_hop = current_announce[next_hop]
|
||||
|
||||
for prefix_announce in current_announce_for_certain_next_hop:
|
||||
#pp.pprint(current_announce_for_certain_next_hop[prefix_announce])
|
||||
pp.pprint(prefix_announce)
|
||||
|
||||
if type(prefix_announce) != str:
|
||||
prefix_announce = prefix_announce.encode('utf8')
|
||||
|
||||
if not database.has_key(prefix_announce):
|
||||
#print >> sys.stderr, "New data"
|
||||
database[prefix_announce] = 1;
|
||||
else:
|
||||
pass
|
||||
#print >> sys.stderr, "I already have this subnet"
|
||||
|
||||
# call sync for each data portion
|
||||
database.sync()
|
||||
except KeyError:
|
||||
pass
|
||||
except KeyboardInterrupt:
|
||||
database.close()
|
||||
sys.exit(0)
|
||||
except IOError:
|
||||
# most likely a signal during readline
|
||||
database.close()
|
||||
sys.exit(0)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import shelve
|
||||
database = shelve.open("/var/lib/bgp_network_collector.db")
|
||||
for key in sorted(database):
|
||||
print key
|
|
@ -0,0 +1,28 @@
|
|||
group Core_v4 {
|
||||
hold-time 180;
|
||||
local-as 65000;
|
||||
peer-as 65000;
|
||||
router-id 10.0.129.2;
|
||||
#graceful-restart 1200;
|
||||
|
||||
neighbor 10.0.131.2 {
|
||||
local-address 10.0.129.2;
|
||||
description "ExaBGP route server client";
|
||||
|
||||
# Do not establish outgoing connection
|
||||
# passive;
|
||||
|
||||
process stdout {
|
||||
neighbor-changes;
|
||||
|
||||
receive {
|
||||
parsed;
|
||||
update;
|
||||
}
|
||||
|
||||
encoder json;
|
||||
run /usr/local/bin/bgp_network_collector.py;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue