From 31529a281567a26242bedf194d4d3fdf4006cfbe Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Tue, 10 Jan 2023 15:21:32 +0100 Subject: [PATCH] improvement: add flag for agentx debugging agentx/network.py always turned on debugging. It can be useful to have debugging logs of the main application without the agentx debug logs, as they are quite noisy. Now, ./vpp-snmp-agent.py -d will turn on application debugging but NOT agentx debugging. ./vpp-snmp-agent.py -d -dd will turn on both. NOTE: ./vpp-snmp-agent.py -dd will do nothing, because the '-d' flag determines the global logging level. --- agentx/agent.py | 6 +++++- agentx/network.py | 4 ++-- vpp-snmp-agent.py | 8 +++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/agentx/agent.py b/agentx/agent.py index 7c61384..706c6dc 100644 --- a/agentx/agent.py +++ b/agentx/agent.py @@ -28,7 +28,11 @@ class Agent(object): self._lastupdate = 0 self._update_period = period # Seconds - self._net = Network(server_address=server_address) + try: + debug = args.debug_agent + except: + debug = False + self._net = Network(server_address=server_address, debug=debug) self._oid_list = [] self._args = args diff --git a/agentx/network.py b/agentx/network.py index 4bfeb67..0aff3b5 100644 --- a/agentx/network.py +++ b/agentx/network.py @@ -27,11 +27,11 @@ class NetworkError(Exception): class Network: - def __init__(self, server_address="/var/agentx/master"): + def __init__(self, server_address="/var/agentx/master", debug=False): self.session_id = 0 self.transaction_id = 0 - self.debug = 1 + self.debug = debug # Data Related Variables self.data = {} self.data_idx = [] diff --git a/vpp-snmp-agent.py b/vpp-snmp-agent.py index fa99c8f..134db1b 100755 --- a/vpp-snmp-agent.py +++ b/vpp-snmp-agent.py @@ -388,10 +388,16 @@ def main(): parser.add_argument( "-d", dest="debug", action="store_true", help="""Enable debug, default False""" ) + parser.add_argument( + "-dd", + dest="debug_agent", + action="store_true", + help="""Enable agentx debug, default False""", + ) args = parser.parse_args() if args.debug: - print("Arguments:", args) + print(f"Arguments: {args}") agentx.setup_logging(debug=args.debug)