Skip to content

Commit

Permalink
Update to include per protocol configuation checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenowak committed Mar 27, 2018
1 parent e486f8c commit c8fe1fa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ WantedBy=multi-user.target
```

NB1: The `snmp` user needs to be a member of the `bird` group in order to query bird.

NB2: If you decide to run the script as a non-provileged user the following are also needed:

```
Expand Down
2 changes: 1 addition & 1 deletion adv_agentx.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def SetValue(self, value):
value, ctypes.POINTER(ctypes.c_ubyte)), size)
self.value = value
except Exception as e:
print("WARNING: Unexpected error in SetValue(): %s" % e)
print("WARNING: Unexpected error in SetValue(): %r" % e)

# set error
def SetError(self, error):
Expand Down
15 changes: 14 additions & 1 deletion birdagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def getBGPState(self):
elif cfg["bgpLocalAs"] != int(match.group(2)):
print("WARNING: multiple local AS: %i/%i" %
(cfg["bgpLocalAs"], int(match.group(2))))

match = self._re_config_remote_peer.search(line)
if match:
cfg["bgp-peers"][proto]["bgpPeerRemoteAddr"] = SnmpIpAddress(
Expand All @@ -228,6 +229,18 @@ def getBGPState(self):
print("ERROR: timeformat not configured for this agent's use, terminating...")
sys.exit(1)

# Validate protocol's config
for proto in cfg["bgp-peers"]:
if "bgpPeerLocalAddr" not in cfg["bgp-peers"][proto] and \
"bgpPeerLocalAs" not in cfg["bgp-peers"][proto]:
print(
"WARNING: Protocol \"%s\" does not have a properly formated 'local <ip> as <asn>;' line in the config" % proto)

if "bgpPeerRemoteAddr" not in cfg["bgp-peers"][proto] and \
"bgpPeerRemoteAs" not in cfg["bgp-peers"][proto]:
print(
"WARNING: Protocol \"%s\" does not have a properly formated 'neighbor <ip> as <asn>;' line in the config" % proto)

state = cfg.copy()
bgp_proto = None
# "with"-context-manager for Popen not available in python < 3.2
Expand Down Expand Up @@ -332,7 +345,7 @@ def getBGPState(self):
if srcip != state["bgp-peers"][proto]["bgpPeerLocalAddr"] or \
dstip != state["bgp-peers"][proto]["bgpPeerRemoteAddr"]:
print(
"WARNING: Protocol \"%s\" has mismatch between the configuration file (local: %s, neighbourd %s) and the active BGP session (local: %s, neighbour: %s)" %
"WARNING: Protocol \"%s\" has mismatch between the configuration file (local: %s, neighbor %s) and the active BGP session (local: %s, neighbor: %s)" %
(proto, state["bgp-peers"][proto]["bgpPeerLocalAddr"], state["bgp-peers"][proto]["bgpPeerRemoteAddr"], srcip, dstip))
continue

Expand Down

0 comments on commit c8fe1fa

Please sign in to comment.