Skip to content

Commit

Permalink
Merge pull request mikenowak#7 from mikenowak/terminate-if
Browse files Browse the repository at this point in the history
Some extra sanity checks, and execution termination on certain condit…
  • Loading branch information
mikenowak authored Mar 26, 2018
2 parents 2df2849 + 50eb444 commit e486f8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions adv_agentx.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
snmp = ctypes.cdll.LoadLibrary(ctypes.util.find_library('netsnmphelpers'))
axl = ctypes.cdll.LoadLibrary(ctypes.util.find_library('netsnmpagent'))
except BaseException:
print('ERROR: agentx module requires net-snmp libraries.')
print('ERROR: agentx module requires net-snmp libraries, terminating...')
sys.exit(1)

# constants
Expand Down 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("ERROR: Unexpected error in SetValue(): %s" % format(e))
print("WARNING: Unexpected error in SetValue(): %s" % e)

# set error
def SetError(self, error):
Expand Down
4 changes: 2 additions & 2 deletions bird_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def OnUpdate(ax, axd, state):

# main program
if __name__ == '__main__':
print('bird-bgp AgentX starting')
print('bird-bgp-agent AgentX starting')

bird = BirdAgent(
os.environ.get("BIRDCONF") or "/etc/bird/bird.conf",
Expand All @@ -103,4 +103,4 @@ def OnUpdate(ax, axd, state):
CacheInterval=int(os.environ.get("AGENTCACHEINTERVAL") or "30")
)
except KeyboardInterrupt:
print('bird-bgp AgentX terminating')
print('bird-bgp-agent AgentX terminating')
17 changes: 12 additions & 5 deletions birdagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from builtins import object
from adv_agentx import AgentX
from adv_agentx import SnmpGauge32, SnmpCounter32, SnmpIpAddress
import sys
import re
import subprocess
import glob
Expand Down Expand Up @@ -158,9 +159,12 @@ def combinedConfigLines(filename):
for subline in BirdAgent.combinedConfigLines(subconf):
yield subline
except IOError:
print("ERROR: Unable to open %s" % filename)
print("ERROR: Unable to open %s, terminating..." % filename)
sys.exit(1)
except Exception as e:
print("ERROR: Unexpected error in combinedConfigLines(): %s" % format(e))
print(
"ERROR: Unexpected error in combinedConfigLines(): [%s], terminating" % e)
sys.exit(1)

@staticmethod
def bgpKeys():
Expand Down Expand Up @@ -221,7 +225,8 @@ def getBGPState(self):
proto = None

if "timeformat" not in cfg:
print("WARNING: timeformat not configured for this agent's use.")
print("ERROR: timeformat not configured for this agent's use, terminating...")
sys.exit(1)

state = cfg.copy()
bgp_proto = None
Expand Down Expand Up @@ -282,7 +287,7 @@ def getBGPState(self):
state["bgp-peers"][bgp_proto][peerprop_name] = int(
match.group(1))
except:
print("ERROR: Unable to process \"%s\" as \"%s\" for protocol \"%s\"" %
print("WARNING: Unable to process \"%s\" as \"%s\" for protocol \"%s\"" %
(match.group(1), peerprop_name, bgp_proto))

if self._re_birdcli_bgp_end.search(line):
Expand All @@ -301,7 +306,9 @@ def getBGPState(self):
# key 4-tuples by remote ip: src-addr, src-port, dst-addr, dst-port
bgp_sessions[match.group(3)] = match.groups()
except subprocess.CalledProcessError as e:
print("ERROR: Error executing \"ss\" command: %s" % format(e))
print(
"ERROR: Error executing \"ss\" command [%s], terminating..." % e)
sys.exit(1)

# match the connection 4-tuples with bgp-state
for proto in list(state["bgp-peers"].keys()):
Expand Down

0 comments on commit e486f8c

Please sign in to comment.