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.
This commit is contained in:
Pim van Pelt
2023-01-10 15:21:32 +01:00
parent 0d7dea37f5
commit 31529a2815
3 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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 = []

View File

@ -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)