From 350642f7f6f3c4f57730b95b4c7624858b7b20d5 Mon Sep 17 00:00:00 2001 From: Mike Nowak Date: Fri, 23 Mar 2018 22:04:29 +0900 Subject: [PATCH] Various fixes to make this work with librenms --- bird_bgp.py | 5 +++-- birdagent.py | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bird_bgp.py b/bird_bgp.py index 6de2bca..143adb5 100755 --- a/bird_bgp.py +++ b/bird_bgp.py @@ -43,7 +43,8 @@ def OnUpdate(ax, axd, state): ## register variables axd.RegisterVar('bgp', 0) axd.RegisterVar('bgpVersion', "10") - axd.RegisterVar('bgpLocalAs', state.get("bgpLocalAs")) + axd.RegisterVar('bgpLocalAs', 0) + axd.RegisterVar('bgpLocalAs.0', state.get("bgpLocalAs")) # reindex by bgpPeerRemoteAddr peers = {} @@ -51,7 +52,7 @@ def OnUpdate(ax, axd, state): peers[peer.get("bgpPeerRemoteAddr")] = peer for snmpkey in BirdAgent.bgp_keys: - #axd.RegisterVar(snmpkey, 0) + axd.RegisterVar(snmpkey, 0) for peer in sorted(peers.keys(), BirdAgent.ipCompare): oid = "%s.%s"%(snmpkey, peer) if peers[peer].has_key(snmpkey): diff --git a/birdagent.py b/birdagent.py index ad44b92..a05a2c3 100644 --- a/birdagent.py +++ b/birdagent.py @@ -40,7 +40,7 @@ def __init__(self, cfgfile, birdcli, netstatcmd="netstat -na"): } _re_config_include = re.compile("^include\s*\"(/[^\"]*)\".*$") - _re_config_bgp_proto_begin = re.compile("^protocol bgp ([a-zA-Z0-9_]+) \{$") + _re_config_bgp_proto_begin = re.compile("^protocol bgp ([a-zA-Z0-9_]+) .* \{$") _re_config_local_as = re.compile("local ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+) as ([0-9]+);") _re_config_bgp_holdtime = re.compile("hold time ([0-9]+);") _re_config_bgp_keepalive = re.compile("keepalive time ([0-9]+);") @@ -99,8 +99,11 @@ def __init__(self, cfgfile, birdcli, netstatcmd="netstat -na"): bgp_defaults = { 'bgpPeerIdentifier': SnmpIpAddress("0.0.0.0"), + 'bgpPeerLocalAddr': SnmpIpAddress("0.0.0.0"), 'bgpPeerHoldTime': 0, + 'bgpPeerHoldTimeConfigured': 0, 'bgpPeerKeepAlive': 0, + 'bgpPeerKeepAliveConfigured': 0, 'bgpPeerState': 1, 'bgpPeerInUpdates': SnmpCounter32(0), 'bgpPeerOutUpdates': SnmpCounter32(0), @@ -234,6 +237,7 @@ def getBGPState(self): match = self._re_birdcli_bgp_begin.search(line) if match: bgp_proto = match.group(1) + state["bgp-peers"][bgp_proto] = {} timestamp = int(match.group(2)) if not state["bgp-peers"].has_key(bgp_proto): print("WARNING: proto \"%s\" not in config, skipping"%bgp_proto)