diff options
Diffstat (limited to 'snmptrap/mod')
-rw-r--r-- | snmptrap/mod/trapd_exit.py | 4 | ||||
-rw-r--r-- | snmptrap/mod/trapd_get_cbs_config.py | 23 | ||||
-rw-r--r-- | snmptrap/mod/trapd_http_session.py | 7 | ||||
-rw-r--r-- | snmptrap/mod/trapd_io.py | 171 | ||||
-rw-r--r-- | snmptrap/mod/trapd_runtime_pid.py | 8 | ||||
-rw-r--r-- | snmptrap/mod/trapd_settings.py | 4 | ||||
-rw-r--r-- | snmptrap/mod/trapd_snmpv3.py | 76 | ||||
-rw-r--r-- | snmptrap/mod/trapd_stats_settings.py | 4 | ||||
-rw-r--r-- | snmptrap/mod/trapd_stormwatch.py | 199 | ||||
-rw-r--r-- | snmptrap/mod/trapd_stormwatch_settings.py | 4 | ||||
-rw-r--r-- | snmptrap/mod/trapd_vb_types.py | 31 |
11 files changed, 302 insertions, 229 deletions
diff --git a/snmptrap/mod/trapd_exit.py b/snmptrap/mod/trapd_exit.py index 6d1ea45..1d1ea16 100644 --- a/snmptrap/mod/trapd_exit.py +++ b/snmptrap/mod/trapd_exit.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ trapc_exit_snmptrapd is responsible for removing any existing runtime PID file, and exiting with the provided (param 1) exit code """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" import sys import os diff --git a/snmptrap/mod/trapd_get_cbs_config.py b/snmptrap/mod/trapd_get_cbs_config.py index 272aabe..cfae994 100644 --- a/snmptrap/mod/trapd_get_cbs_config.py +++ b/snmptrap/mod/trapd_get_cbs_config.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ env variable that specifies JSON equiv of CBS config (typically used for testing purposes) """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" import json import os @@ -76,17 +76,14 @@ def get_cbs_config(): stdout_logger(msg) cleanup_and_exit(1, None) else: - msg = ("ONAP controller override specified via CBS_SIM_JSON: %s" % - _cbs_sim_json_file) + msg = "ONAP controller override specified via CBS_SIM_JSON: %s" % _cbs_sim_json_file stdout_logger(msg) try: tds.c_config = json.load(open(_cbs_sim_json_file)) - msg = ("%s loaded and parsed successfully" % - _cbs_sim_json_file) + msg = "%s loaded and parsed successfully" % _cbs_sim_json_file stdout_logger(msg) except Exception as e: - msg = "Unable to load CBS_SIM_JSON " + _cbs_sim_json_file + \ - " (invalid json?) - FATAL ERROR, exiting" + msg = "Unable to load CBS_SIM_JSON " + _cbs_sim_json_file + " (invalid json?) - FATAL ERROR, exiting" stdout_logger(msg) cleanup_and_exit(1, None) @@ -96,24 +93,24 @@ def get_cbs_config(): # recalc timeout, set default if not present try: - tds.timeout_seconds = float(tds.c_config['publisher']['http_milliseconds_timeout'] / 1000.0) + tds.timeout_seconds = float(tds.c_config["publisher"]["http_milliseconds_timeout"] / 1000.0) except Exception as e: tds.timeout_seconds = float(1.5) # recalc seconds_between_retries, set default if not present try: - tds.seconds_between_retries = float(tds.c_config['publisher']['http_milliseconds_between_retries'] / 1000.0) + tds.seconds_between_retries = float(tds.c_config["publisher"]["http_milliseconds_between_retries"] / 1000.0) except Exception as e: - tds.seconds_between_retries = float(.750) + tds.seconds_between_retries = float(0.750) # recalc min_severity_to_log, set default if not present try: - tds.minimum_severity_to_log = int(tds.c_config['files']['minimum_severity_to_log']) + tds.minimum_severity_to_log = int(tds.c_config["files"]["minimum_severity_to_log"]) except Exception as e: tds.minimum_severity_to_log = int(3) try: - tds.publisher_retries = int(tds.c_config['publisher']['http_retries']) + tds.publisher_retries = int(tds.c_config["publisher"]["http_retries"]) except Exception as e: tds.publisher_retries = int(2) diff --git a/snmptrap/mod/trapd_http_session.py b/snmptrap/mod/trapd_http_session.py index 14abb21..7118d00 100644 --- a/snmptrap/mod/trapd_http_session.py +++ b/snmptrap/mod/trapd_http_session.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ trapd_http_session establishes an http session for future use in publishing messages to the dmaap cluster. """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" import os import requests @@ -81,8 +81,7 @@ def close_session_obj(_loc_http_requ_session): return True except Exception as e: msg = "Unable to close current http session - FATAL ERROR, exiting" - ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_FATAL, - tds.CODE_GENERAL, msg) + ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_FATAL, tds.CODE_GENERAL, msg) stdout_logger(msg) cleanup_and_exit(1, tds.pid_file_name) diff --git a/snmptrap/mod/trapd_io.py b/snmptrap/mod/trapd_io.py index 20b99f9..f7c48b7 100644 --- a/snmptrap/mod/trapd_io.py +++ b/snmptrap/mod/trapd_io.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ """ """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" # basics import datetime @@ -54,8 +54,14 @@ def roll_all_logs(): # NOTE: this will go away when onap logging is standardized/available try: # open various ecomp logs - if any fails, exit - for fd in [tds.eelf_error_fd, tds.eelf_debug_fd, tds.eelf_audit_fd, - tds.eelf_metrics_fd, tds.arriving_traps_fd, tds.json_traps_fd]: + for fd in [ + tds.eelf_error_fd, + tds.eelf_debug_fd, + tds.eelf_audit_fd, + tds.eelf_metrics_fd, + tds.arriving_traps_fd, + tds.json_traps_fd, + ]: fd.close() roll_file(tds.eelf_error_file_name) @@ -80,8 +86,7 @@ def roll_all_logs(): try: tds.json_traps_fd = open_file(tds.json_traps_filename) except Exception as e: - msg = ("Error opening json_log %s : %s" % - (json_traps_filename, str(e))) + msg = "Error opening json_log %s : %s" % (json_traps_filename, str(e)) stdout_logger(msg) cleanup_and_exit(1, tds.pid_file_name) @@ -91,8 +96,7 @@ def roll_all_logs(): try: tds.arriving_traps_fd = open_file(tds.arriving_traps_filename) except Exception as e: - msg = ("Error opening arriving traps %s : %s" % - (arriving_traps_filename, str(e))) + msg = "Error opening arriving traps %s : %s" % (arriving_traps_filename, str(e)) stdout_logger(msg) cleanup_and_exit(1, tds.pid_file_name) @@ -111,8 +115,7 @@ def open_eelf_logs(): try: # open various ecomp logs - if any fails, exit - tds.eelf_error_file_name = ( - tds.c_config['files']['eelf_base_dir'] + "/" + tds.c_config['files']['eelf_error']) + tds.eelf_error_file_name = tds.c_config["files"]["eelf_base_dir"] + "/" + tds.c_config["files"]["eelf_error"] tds.eelf_error_fd = open_file(tds.eelf_error_file_name) except Exception as e: @@ -121,8 +124,7 @@ def open_eelf_logs(): cleanup_and_exit(1, tds.pid_file_name) try: - tds.eelf_debug_file_name = ( - tds.c_config['files']['eelf_base_dir'] + "/" + tds.c_config['files']['eelf_debug']) + tds.eelf_debug_file_name = tds.c_config["files"]["eelf_base_dir"] + "/" + tds.c_config["files"]["eelf_debug"] tds.eelf_debug_fd = open_file(tds.eelf_debug_file_name) except Exception as e: @@ -131,8 +133,7 @@ def open_eelf_logs(): cleanup_and_exit(1, tds.pid_file_name) try: - tds.eelf_audit_file_name = ( - tds.c_config['files']['eelf_base_dir'] + "/" + tds.c_config['files']['eelf_audit']) + tds.eelf_audit_file_name = tds.c_config["files"]["eelf_base_dir"] + "/" + tds.c_config["files"]["eelf_audit"] tds.eelf_audit_fd = open_file(tds.eelf_audit_file_name) except Exception as e: msg = "Error opening eelf audit log : " + str(e) @@ -141,7 +142,8 @@ def open_eelf_logs(): try: tds.eelf_metrics_file_name = ( - tds.c_config['files']['eelf_base_dir'] + "/" + tds.c_config['files']['eelf_metrics']) + tds.c_config["files"]["eelf_base_dir"] + "/" + tds.c_config["files"]["eelf_metrics"] + ) tds.eelf_metrics_fd = open_file(tds.eelf_metrics_file_name) except Exception as e: msg = "Error opening eelf metric log : " + str(e) @@ -150,6 +152,7 @@ def open_eelf_logs(): return True + # # # # # # # # # # # # # # # # # # # # fx: roll_log_file -> move provided filename to timestamped version # # # # # # # # # # ## # # # # # # # @@ -160,11 +163,11 @@ def roll_file(_loc_file_name): move active file to timestamped archive """ - _file_name_suffix = "%s" % (datetime.datetime.fromtimestamp(time.time()). - fromtimestamp(time.time()). - strftime('%Y-%m-%dT%H:%M:%S')) + _file_name_suffix = "%s" % ( + datetime.datetime.fromtimestamp(time.time()).fromtimestamp(time.time()).strftime("%Y-%m-%dT%H:%M:%S") + ) - _loc_file_name_bak = _loc_file_name + '.' + _file_name_suffix + _loc_file_name_bak = _loc_file_name + "." + _file_name_suffix # roll existing file if present if os.path.isfile(_loc_file_name): @@ -172,15 +175,13 @@ def roll_file(_loc_file_name): os.rename(_loc_file_name, _loc_file_name_bak) return True except Exception as e: - _msg = ("ERROR: Unable to rename %s to %s" - % (_loc_file_name, - _loc_file_name_bak)) - ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_ERROR, - tds.CODE_GENERAL, _msg) + _msg = "ERROR: Unable to rename %s to %s" % (_loc_file_name, _loc_file_name_bak) + ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_ERROR, tds.CODE_GENERAL, _msg) return False return False + # # # # # # # # # # # # # # fx: open_log_file # # # # # # # # # # # # # @@ -194,17 +195,16 @@ def open_file(_loc_file_name): try: # open append mode just in case so nothing is lost, but should be # non-existent file - _loc_fd = open(_loc_file_name, 'a', 1) + _loc_fd = open(_loc_file_name, "a", 1) return _loc_fd except Exception as e: msg = "Error opening " + _loc_file_name + " append mode - " + str(e) stdout_logger(msg) cleanup_and_exit(1, tds.pid_file_name) - -# # # # # # # # # # # # # -# fx: close_file -# # # # # # # # # # # # # + # # # # # # # # # # # # # + # fx: close_file + # # # # # # # # # # # # # """ close _loc_file_name, return True with success, False otherwise """ @@ -216,11 +216,11 @@ def close_file(_loc_fd, _loc_filename): _loc_fd.close() return True except Exception as e: - msg = "Error closing %s : %s - results indeterminate" % ( - _loc_filename, str(e)) + msg = "Error closing %s : %s - results indeterminate" % (_loc_filename, str(e)) ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_FATAL, tds.CODE_GENERAL, msg) return False + # # # # # # # # # # # # # # # # # # # # fx: ecomp_logger -> log in eelf format until standard # is released for python via LOG-161 @@ -317,13 +317,22 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): # catch invalid log type if _log_type < 1 or _log_type > 5: - msg = ("INVALID log type: %s " % _log_type) - _out_rec = ("%s|%s|%s|%s|%s|%s|%s|%s|%s" - % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, (msg + _msg))) + msg = "INVALID log type: %s " % _log_type + _out_rec = "%s|%s|%s|%s|%s|%s|%s|%s|%s" % ( + calling_fx, + "snmptrapd", + unused, + unused, + unused, + tds.SEV_TYPES[_sev], + _error_code, + unused, + (msg + _msg), + ) try: - tds.eelf_error_fd.write('%s|%s\n' % (t_out, str(_out_rec))) + tds.eelf_error_fd.write("%s|%s\n" % (t_out, str(_out_rec))) if log_to_stdout: - print('%s|%s' % (t_out, str(_out_rec))) + print("%s|%s" % (t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) @@ -335,34 +344,79 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): # _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s' # _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s' # % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)) - _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' - % (unused, unused, calling_fx, unused, "snmptrapd", unused, unused, unused, unused, unused, unused, unused, tds.SEV_TYPES[_sev], unused, unused, unused, unused, unused, unused, unused, unused, unused, unused, unused, unused, unused, _msg)) + _out_rec = "%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s" % ( + unused, + unused, + calling_fx, + unused, + "snmptrapd", + unused, + unused, + unused, + unused, + unused, + unused, + unused, + tds.SEV_TYPES[_sev], + unused, + unused, + unused, + unused, + unused, + unused, + unused, + unused, + unused, + unused, + unused, + unused, + unused, + _msg, + ) try: - tds.eelf_error_fd.write('%s|%s|%s\n' % (t_out, t_out, str(_out_rec))) + tds.eelf_error_fd.write("%s|%s|%s\n" % (t_out, t_out, str(_out_rec))) if log_to_stdout: - print('%s|%s|%s' % (t_out, t_out, str(_out_rec))) + print("%s|%s|%s" % (t_out, t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) elif _log_type == tds.LOG_TYPE_AUDIT: # log message in AUDIT format # _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s' # % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)) - _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s' - % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)) + _out_rec = "%s|%s|%s|%s|%s|%s|%s|%s|%s" % ( + calling_fx, + "snmptrapd", + unused, + unused, + unused, + tds.SEV_TYPES[_sev], + _error_code, + unused, + _msg, + ) try: - tds.eelf_audit_fd.write('%s|%s\n' % (t_out, str(_out_rec))) + tds.eelf_audit_fd.write("%s|%s\n" % (t_out, str(_out_rec))) if log_to_stdout: - print('%s|%s' % (t_out, str(_out_rec))) + print("%s|%s" % (t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) elif _log_type == tds.LOG_TYPE_METRICS: # log message in METRICS format - _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s' - % (calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)) + _out_rec = "%s|%s|%s|%s|%s|%s|%s|%s|%s" % ( + calling_fx, + "snmptrapd", + unused, + unused, + unused, + tds.SEV_TYPES[_sev], + _error_code, + unused, + _msg, + ) try: - tds.eelf_metrics_fd.write('%s|%s\n' % (t_out, str(_out_rec))) + tds.eelf_metrics_fd.write("%s|%s\n" % (t_out, str(_out_rec))) if log_to_stdout: - print('%s|%s' % (t_out, str(_out_rec))) + print("%s|%s" % (t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) @@ -370,17 +424,28 @@ def ecomp_logger(_log_type, _sev, _error_code, _msg): # DLFM: too much I/O !!! # always write to debug; we need ONE logfile that has time-sequence full view !!! # log message in DEBUG format - _out_rec = ("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s" - % (unused, calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)) + _out_rec = "%s|%s|%s|%s|%s|%s|%s|%s|%s|%s" % ( + unused, + calling_fx, + "snmptrapd", + unused, + unused, + unused, + tds.SEV_TYPES[_sev], + _error_code, + unused, + _msg, + ) try: - tds.eelf_debug_fd.write('%s|%s\n' % (t_out, str(_out_rec))) + tds.eelf_debug_fd.write("%s|%s\n" % (t_out, str(_out_rec))) if log_to_stdout: - print('%s|%s' % (t_out, str(_out_rec))) + print("%s|%s" % (t_out, str(_out_rec))) except Exception as e: stdout_logger(str(_out_rec)) return True + # # # # # # # # # # # # # # fx: stdout_logger # # # # # # # # # # # # # @@ -403,4 +468,4 @@ def stdout_logger(_msg): t_out = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S,%f")[:-3] - print('%s %s' % (t_out, _msg)) + print("%s %s" % (t_out, _msg)) diff --git a/snmptrap/mod/trapd_runtime_pid.py b/snmptrap/mod/trapd_runtime_pid.py index 74668f5..c647885 100644 --- a/snmptrap/mod/trapd_runtime_pid.py +++ b/snmptrap/mod/trapd_runtime_pid.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ trapd_runtime_pid maintains a 'PID file' (file that contains the PID of currently running trap receiver) """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" import logging import os @@ -47,8 +47,8 @@ def save_pid(_pid_file_name): """ try: - pid_fd = open(_pid_file_name, 'w') - pid_fd.write('%d' % os.getpid()) + pid_fd = open(_pid_file_name, "w") + pid_fd.write("%d" % os.getpid()) pid_fd.close() except IOError: print("IOError saving PID file %s :" % _pid_file_name) diff --git a/snmptrap/mod/trapd_settings.py b/snmptrap/mod/trapd_settings.py index 41dc18f..26e7c9b 100644 --- a/snmptrap/mod/trapd_settings.py +++ b/snmptrap/mod/trapd_settings.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ """ """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" def init(): diff --git a/snmptrap/mod/trapd_snmpv3.py b/snmptrap/mod/trapd_snmpv3.py index b421ae1..56ecb5c 100644 --- a/snmptrap/mod/trapd_snmpv3.py +++ b/snmptrap/mod/trapd_snmpv3.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ module for snmpv3 support """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" import json import os @@ -60,7 +60,7 @@ def load_snmpv3_credentials(_py_config, _snmp_engine, _cbs_config): try: v3_users = _cbs_config["snmpv3_config"]["usm_users"] except Exception as e: - msg = ("No V3 users defined") + msg = "No V3 users defined" ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) return _py_config, _snmp_engine @@ -68,13 +68,13 @@ def load_snmpv3_credentials(_py_config, _snmp_engine, _cbs_config): # engineId try: - ctx_engine_id = v3_user['engineId'] + ctx_engine_id = v3_user["engineId"] except Exception as e: ctx_engine_id = None # user try: - userName = v3_user['user'] + userName = v3_user["user"] except Exception as e: userName = None @@ -86,40 +86,38 @@ def load_snmpv3_credentials(_py_config, _snmp_engine, _cbs_config): # usmHMACMD5AuthProtocol try: - authKey = v3_user['usmHMACMD5AuthProtocol'] + authKey = v3_user["usmHMACMD5AuthProtocol"] authProtocol = config.usmHMACMD5AuthProtocol except Exception as e: try: - authKey = v3_user['usmHMACSHAAuthProtocol'] + authKey = v3_user["usmHMACSHAAuthProtocol"] authProtocol = config.usmHMACSHAAuthProtocol except Exception as e: try: - authKey = v3_user['usmHMAC128SHA224AuthProtocol'] + authKey = v3_user["usmHMAC128SHA224AuthProtocol"] authProtocol = config.usmHMAC128SHA224AuthProtocol except Exception as e: try: - authKey = v3_user['usmHMAC192SHA256AuthProtocol'] + authKey = v3_user["usmHMAC192SHA256AuthProtocol"] authProtocol = config.usmHMAC192SHA256AuthProtocol except Exception as e: try: - authKey = v3_user['usmHMAC256SHA384AuthProtocol'] + authKey = v3_user["usmHMAC256SHA384AuthProtocol"] authProtocol = config.usmHMAC256SHA384AuthProtocol except Exception as e: try: - authKey = v3_user['usmHMAC384SHA512AuthProtocol'] + authKey = v3_user["usmHMAC384SHA512AuthProtocol"] authProtocol = config.usmHMAC384SHA512AuthProtocol except Exception as e: try: - authKey = v3_user['usmNoAuthProtocol'] + authKey = v3_user["usmNoAuthProtocol"] authProtocol = config.usmNoAuthProtocol except Exception as e: # FMDL: default to NoAuth, or error/skip entry? - msg = ( - "No auth specified for user %s ?" % (userName)) + msg = "No auth specified for user %s ?" % (userName) authKey = None authProtocol = config.usmNoAuthProtocol - ecomp_logger( - tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) # privacy # find options at -> site-packages/pysnmp/entity/config.py @@ -129,56 +127,57 @@ def load_snmpv3_credentials(_py_config, _snmp_engine, _cbs_config): # usm3DESEDEPriv try: - privKey = v3_user['usm3DESEDEPrivProtocol'] + privKey = v3_user["usm3DESEDEPrivProtocol"] privProtocol = config.usm3DESEDEPrivProtocol except Exception as e: # usmAesCfb128Protocol try: - privKey = v3_user['usmAesCfb128Protocol'] + privKey = v3_user["usmAesCfb128Protocol"] privProtocol = config.usmAesCfb128Protocol except Exception as e: # usmAesCfb192Protocol try: - privKey = v3_user['usmAesCfb192Protocol'] + privKey = v3_user["usmAesCfb192Protocol"] privProtocol = config.usmAesCfb192Protocol except Exception as e: # usmAesBlumenthalCfb192Protocol try: - privKey = v3_user['usmAesBlumenthalCfb192Protocol'] + privKey = v3_user["usmAesBlumenthalCfb192Protocol"] privProtocol = config.usmAesBlumenthalCfb192Protocol except Exception as e: # usmAesCfb256Protocol try: - privKey = v3_user['usmAesCfb256Protocol'] + privKey = v3_user["usmAesCfb256Protocol"] privProtocol = config.usmAesCfb256Protocol except Exception as e: # usmAesBlumenthalCfb256Protocol try: - privKey = v3_user['usmAesBlumenthalCfb256Protocol'] + privKey = v3_user["usmAesBlumenthalCfb256Protocol"] privProtocol = config.usmAesBlumenthalCfb256Protocol except Exception as e: # usmDESPrivProtocol try: - privKey = v3_user['usmDESPrivProtocol'] + privKey = v3_user["usmDESPrivProtocol"] privProtocol = config.usmDESPrivProtocol except Exception as e: # usmNoPrivProtocol try: - privKey = v3_user['usmNoPrivProtocol'] + privKey = v3_user["usmNoPrivProtocol"] privProtocol = config.usmNoPrivProtocol except Exception as e: # FMDL: default to NoPriv, or error/skip entry? - msg = ( - "No priv specified for user %s" % (userName)) - ecomp_logger( - tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) + msg = "No priv specified for user %s" % (userName) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) privKey = None privProtocol = config.usmNoPrivProtocol # break # msg = ("userName: %s authKey: %s authProtocol: %s privKey: %s privProtocol: %s engineId: %s % (userName, authKey, authProtocol, privKey, privProtocol, ctx_engine_id)) - msg = ("userName: %s authKey: **** authProtocol: %s privKey: **** privProtocol: %s engineId: ****" % - (userName, authProtocol, privProtocol)) + msg = "userName: %s authKey: **** authProtocol: %s privKey: **** privProtocol: %s engineId: ****" % ( + userName, + authProtocol, + privProtocol, + ) ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) # user: usr-md5-des, auth: MD5, priv DES, contextEngineId: 8000000001020304 @@ -189,16 +188,15 @@ def load_snmpv3_credentials(_py_config, _snmp_engine, _cbs_config): if ctx_engine_id is not None: config.addV3User( - _snmp_engine, userName, - authProtocol, authKey, - privProtocol, privKey, - contextEngineId=v2c.OctetString(hexValue=ctx_engine_id) + _snmp_engine, + userName, + authProtocol, + authKey, + privProtocol, + privKey, + contextEngineId=v2c.OctetString(hexValue=ctx_engine_id), ) else: - config.addV3User( - _snmp_engine, userName, - authProtocol, authKey, - privProtocol, privKey - ) + config.addV3User(_snmp_engine, userName, authProtocol, authKey, privProtocol, privKey) return _py_config, _snmp_engine diff --git a/snmptrap/mod/trapd_stats_settings.py b/snmptrap/mod/trapd_stats_settings.py index df4da0e..2aacb2e 100644 --- a/snmptrap/mod/trapd_stats_settings.py +++ b/snmptrap/mod/trapd_stats_settings.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ """ """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" def init(): diff --git a/snmptrap/mod/trapd_stormwatch.py b/snmptrap/mod/trapd_stormwatch.py index 9e41bd0..4c374bb 100644 --- a/snmptrap/mod/trapd_stormwatch.py +++ b/snmptrap/mod/trapd_stormwatch.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ threshold (storm), and if so it will return "False" so the trap can be logged and immediately discarded """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" import sys import os @@ -98,11 +98,11 @@ def sw_clear_dicts(): sws.sw_config_category.clear() return True except Exception as e: - msg = "unable to reset stormwatch dictionaries - results will be indeterminate: %s" % ( - e) + msg = "unable to reset stormwatch dictionaries - results will be indeterminate: %s" % (e) ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_WARN, tds.CODE_GENERAL, msg) return False + # # # # # # # # # # # # # # fx: sw_load_trap_config # - load trap configurations from CBS response @@ -121,10 +121,10 @@ def sw_load_trap_config(_config): try: sws.sw_storm_active_dict ret = sw_clear_dicts() - msg = ("reset existing sws dictionaries to empty") + msg = "reset existing sws dictionaries to empty" ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) except NameError: - msg = ("sws dictionaries not present - initializing") + msg = "sws dictionaries not present - initializing" ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) ret = sw_init() @@ -134,24 +134,22 @@ def sw_load_trap_config(_config): # get metric % threshold for logging trap count by-agent to metric log try: stats.metric_log_notification_threshold_pct = int( - _config["trap_config"]["metric_log_notification_threshold_pct"]) - msg = ("metric_log_notification_threshold_pct value: %d" % - stats.metric_log_notification_threshold_pct) + _config["trap_config"]["metric_log_notification_threshold_pct"] + ) + msg = "metric_log_notification_threshold_pct value: %d" % stats.metric_log_notification_threshold_pct ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) except Exception as e: - msg = ( - "metric_log_notification_threshold_pct not present in config - default to 25") + msg = "metric_log_notification_threshold_pct not present in config - default to 25" ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg) stats.metric_log_notification_threshold_pct = 25 # get stormwatch interval; default to 60 seconds try: - sws.sw_interval_in_seconds = int( - _config["trap_config"]["sw_interval_in_seconds"]) - msg = ("sw_interval_in_seconds value: %d" % sws.sw_interval_in_seconds) + sws.sw_interval_in_seconds = int(_config["trap_config"]["sw_interval_in_seconds"]) + msg = "sw_interval_in_seconds value: %d" % sws.sw_interval_in_seconds ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) except Exception as e: - msg = ("sw_interval_in_seconds not present in config - default to 60 seconds") + msg = "sw_interval_in_seconds not present in config - default to 60 seconds" ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg) sws.sw_interval_in_seconds = 60 @@ -159,7 +157,7 @@ def sw_load_trap_config(_config): try: notify_oids = _config["trap_config"]["notify_oids"] except Exception as e: - msg = ("no trap_config or notify_oids defined") + msg = "no trap_config or notify_oids defined" ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg) return False @@ -167,65 +165,66 @@ def sw_load_trap_config(_config): for trap_block in notify_oids: # oid try: - _oid = trap_block['oid'] + _oid = trap_block["oid"] except Exception as e: - msg = ( - "missing oid value in notify_oids - oid section of CBS config - using empty value, disregard entry") - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, - tds.CODE_GENERAL, msg) + msg = "missing oid value in notify_oids - oid section of CBS config - using empty value, disregard entry" + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg) _oid = None # sw_high_water_in_interval try: - _sw_high_water_in_interval = int( - trap_block['sw_high_water_in_interval']) + _sw_high_water_in_interval = int(trap_block["sw_high_water_in_interval"]) except Exception as e: msg = ( - "missing sw_high_water_in_interval value in notify_oids - oid section of CBS config - using empty value") - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, - tds.CODE_GENERAL, msg) + "missing sw_high_water_in_interval value in notify_oids - oid section of CBS config - using empty value" + ) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg) _sw_high_water_in_interval = None # sw_low_water_in_interval try: - _sw_low_water_in_interval = int( - trap_block['sw_low_water_in_interval']) + _sw_low_water_in_interval = int(trap_block["sw_low_water_in_interval"]) except Exception as e: msg = ( - "missing sw_low_water_in_interval value in notify_oids - oid section of CBS config - using empty value") - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, - tds.CODE_GENERAL, msg) + "missing sw_low_water_in_interval value in notify_oids - oid section of CBS config - using empty value" + ) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg) _sw_low_water_in_interval = None # category try: - _category = trap_block['category'] + _category = trap_block["category"] except Exception as e: - msg = ( - "missing category value in notify_oids - oid section of CBS config - using empty value") - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, - tds.CODE_GENERAL, msg) + msg = "missing category value in notify_oids - oid section of CBS config - using empty value" + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg) _category = None - if (_oid is not None and _category is not None and - _sw_low_water_in_interval is not None and _sw_high_water_in_interval is not None and - _sw_low_water_in_interval < _sw_high_water_in_interval): + if ( + _oid is not None + and _category is not None + and _sw_low_water_in_interval is not None + and _sw_high_water_in_interval is not None + and _sw_low_water_in_interval < _sw_high_water_in_interval + ): # FMDL: Do we actually need sw_config_oid_dict? - msg = ("oid: %s sw_high_water_in_interval: %d sw_low_water_in_interval: %d category: %s" % ( - _oid, _sw_high_water_in_interval, _sw_low_water_in_interval, _category)) - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, - tds.CODE_GENERAL, msg) + msg = "oid: %s sw_high_water_in_interval: %d sw_low_water_in_interval: %d category: %s" % ( + _oid, + _sw_high_water_in_interval, + _sw_low_water_in_interval, + _category, + ) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) sws.sw_config_oid_dict[_oid] = True sws.sw_config_low_water_in_interval_dict[_oid] = _sw_low_water_in_interval sws.sw_config_high_water_in_interval_dict[_oid] = _sw_high_water_in_interval sws.sw_config_category[_oid] = _category trap_block_counter += 1 else: - msg = ("Missing or incorrect value for stormwatch config entry %d: skipping: %s" % ( - trap_block_counter, trap_block)) - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, - tds.CODE_GENERAL, msg) - + msg = "Missing or incorrect value for stormwatch config entry %d: skipping: %s" % ( + trap_block_counter, + trap_block, + ) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) return trap_block_counter @@ -246,17 +245,18 @@ def sw_log_metrics(): :Variables: """ - msg = "total notifications: %d, interval in seconds: %d" % ( - stats.total_notifications, sws.sw_interval_in_seconds) + msg = "total notifications: %d, interval in seconds: %d" % (stats.total_notifications, sws.sw_interval_in_seconds) ecomp_logger(tds.LOG_TYPE_METRICS, tds.SEV_INFO, tds.CODE_GENERAL, msg) # print metrics for total traps and traps-per-second avg # during sample interval avg_traps_per_second = stats.total_notifications / 60 msg = "total traps: %d, interval in seconds: %d, average traps-per-second: %d" % ( - stats.total_notifications, sws.sw_interval_in_seconds, avg_traps_per_second) - ecomp_logger(tds.LOG_TYPE_METRICS, tds.SEV_WARN, - tds.CODE_GENERAL, msg) + stats.total_notifications, + sws.sw_interval_in_seconds, + avg_traps_per_second, + ) + ecomp_logger(tds.LOG_TYPE_METRICS, tds.SEV_WARN, tds.CODE_GENERAL, msg) # print metrics for any agent that represents more than stats.metric_log_notification_threshold_pct # during sample interval @@ -265,9 +265,13 @@ def sw_log_metrics(): p = c / stats.total_notifications * 100 if p > stats.metric_log_notification_threshold_pct: msg = "agent: %s, notifications: %d, interval in seconds: %d, percent of total traps: %d" % ( - k, c, sws.sw_interval_in_seconds, p) - ecomp_logger(tds.LOG_TYPE_METRICS, tds.SEV_WARN, - tds.CODE_GENERAL, msg) + k, + c, + sws.sw_interval_in_seconds, + p, + ) + ecomp_logger(tds.LOG_TYPE_METRICS, tds.SEV_WARN, tds.CODE_GENERAL, msg) + # # # # # # # # # # # # # # fx: stats_increment_counters @@ -339,8 +343,10 @@ def sw_storm_active(_loc_agent, _loc_oid): # if we are at or above stormwatch interval, re-eval and re-set elapsed_time = int(time.time()) - sws.sw_last_stormwatch_dict_analysis if elapsed_time >= sws.sw_interval_in_seconds: - msg = "%d seconds has elapsed since stormwatch dictionary eval (%d second threshold) - check and reset counters " % ( - elapsed_time, sws.sw_interval_in_seconds) + msg = ( + "%d seconds has elapsed since stormwatch dictionary eval (%d second threshold) - check and reset counters " + % (elapsed_time, sws.sw_interval_in_seconds) + ) ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) sw_log_metrics() sw_reset_counter_dict() @@ -349,8 +355,7 @@ def sw_storm_active(_loc_agent, _loc_oid): # that means it's participating in stormwatch, otherwise bail out try: _high_water_val = sws.sw_config_high_water_in_interval_dict[_loc_oid] - msg = "%s present in stormwatch config - high water value: %d" % ( - _loc_oid, _high_water_val) + msg = "%s present in stormwatch config - high water value: %d" % (_loc_oid, _high_water_val) ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) except Exception as e: return False @@ -375,25 +380,32 @@ def sw_storm_active(_loc_agent, _loc_oid): # if we got this far, trap is in stormwatch configs, we've incremented # counter in sw_storm_counter_dict - figure out if we are over limit if sws.sw_storm_counter_dict[_dict_key] > _high_water_val: - print(f"sws.sw_storm_counter_dict[{_dict_key}]({sws.sw_storm_counter_dict[_dict_key]}) > _high_water_val ({_high_water_val})") + print( + f"sws.sw_storm_counter_dict[{_dict_key}]({sws.sw_storm_counter_dict[_dict_key]}) > _high_water_val ({_high_water_val})" + ) _loc_agent = _dict_key.split()[0] _loc_oid = _dict_key.split()[1] msg = "STORM ACTIVE: received %d events (%s) from %s (greater than high water threshold: %d)" % ( - sws.sw_storm_counter_dict[_dict_key], _loc_oid, _loc_agent, _high_water_val) + sws.sw_storm_counter_dict[_dict_key], + _loc_oid, + _loc_agent, + _high_water_val, + ) ecomp_logger(tds.LOG_TYPE_AUDIT, tds.SEV_WARN, tds.CODE_GENERAL, msg) try: sws.sw_storm_active_dict[_dict_key] = True except Exception as e: - msg = "ERROR setting %s in storm active state: %s " % ( - _dict_key, e) - ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_ERROR, - tds.CODE_GENERAL, msg) + msg = "ERROR setting %s in storm active state: %s " % (_dict_key, e) + ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_ERROR, tds.CODE_GENERAL, msg) return True else: - print(f"NOT sws.sw_storm_counter_dict[{_dict_key}]({sws.sw_storm_counter_dict[_dict_key]}) > _high_water_val ({_high_water_val})") + print( + f"NOT sws.sw_storm_counter_dict[{_dict_key}]({sws.sw_storm_counter_dict[_dict_key]}) > _high_water_val ({_high_water_val})" + ) return False + # # # # # # # # # # # # # # fx: sw_reset_counter_dict # - reset counter dictionary on <interval> boundaries @@ -416,11 +428,9 @@ def sw_reset_counter_dict(): # publish stats to MR... try: msg = "publish counts-by-oid from stats.oid_counter_dict" - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, - tds.CODE_GENERAL, msg) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) msg = "publish count-by-agent from stats.agent_counter_dict" - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, - tds.CODE_GENERAL, msg) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) except Exception as e: msg = "unable to publish counts by oid and agent to MR: " % (e) ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_WARN, tds.CODE_GENERAL, msg) @@ -431,8 +441,7 @@ def sw_reset_counter_dict(): stats.agent_counter_dict.clear() stats.total_notifications = 0 except Exception as e: - msg = "unable to reset counts by oid and agent dictionaries - stats will be INNACURATE: " % ( - e) + msg = "unable to reset counts by oid and agent dictionaries - stats will be INNACURATE: " % (e) ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_WARN, tds.CODE_GENERAL, msg) # </stats> @@ -457,36 +466,45 @@ def sw_reset_counter_dict(): if sws.sw_storm_counter_dict[k] >= _high_water_val: msg = "%s remaining in storm state, received %d events (GE to upper threshold: %d)" % ( - k, sws.sw_storm_counter_dict[k], _high_water_val) - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, - tds.CODE_GENERAL, msg) + k, + sws.sw_storm_counter_dict[k], + _high_water_val, + ) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) sws.sw_storm_counter_dict[k] = 0 else: _low_water_val = sws.sw_config_low_water_in_interval_dict[_loc_oid] if sws.sw_storm_counter_dict[k] < _low_water_val: try: msg = "STORM OVER: received %d events (%s) from %s (less than low water threshold: %d)" % ( - sws.sw_storm_counter_dict[k], _loc_oid, _loc_agent, _low_water_val) - ecomp_logger(tds.LOG_TYPE_AUDIT, tds.SEV_WARN, - tds.CODE_GENERAL, msg) + sws.sw_storm_counter_dict[k], + _loc_oid, + _loc_agent, + _low_water_val, + ) + ecomp_logger(tds.LOG_TYPE_AUDIT, tds.SEV_WARN, tds.CODE_GENERAL, msg) del sws.sw_storm_active_dict[k] sws.sw_storm_counter_dict[k] = 0 except Exception as e: - msg = "unable to remove %s from storm active dictionary - TRAPS MAY BE DISCARDED UNINTENTIONALLY! Reason: %s " % ( - k, e) - ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_ERROR, - tds.CODE_GENERAL, msg) + msg = ( + "unable to remove %s from storm active dictionary - TRAPS MAY BE DISCARDED UNINTENTIONALLY! Reason: %s " + % (k, e) + ) + ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_ERROR, tds.CODE_GENERAL, msg) else: msg = "%s remaining in storm state, received %d events (GE to lower threshold: %d)" % ( - k, sws.sw_storm_counter_dict[k], _low_water_val) - ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_INFO, - tds.CODE_GENERAL, msg) + k, + sws.sw_storm_counter_dict[k], + _low_water_val, + ) + ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_INFO, tds.CODE_GENERAL, msg) sws.sw_storm_counter_dict[k] = 0 sws.sw_last_stormwatch_dict_analysis = int(time.time()) return True + # # # # # # # # # # # # # # fx: sw_increment_counter # - increment OID and agent trap counters @@ -511,14 +529,11 @@ def sw_increment_counter(_dict_key): try: sws.sw_storm_counter_dict[_dict_key] += 1 - msg = "stormwatch counter for %s now: %d" % ( - _dict_key, sws.sw_storm_counter_dict[_dict_key]) - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, - tds.CODE_GENERAL, msg) + msg = "stormwatch counter for %s now: %d" % (_dict_key, sws.sw_storm_counter_dict[_dict_key]) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) return True except Exception as E: msg = "first trap for %s - init stormwatch counter to 1" % (_dict_key) - ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, - tds.CODE_GENERAL, msg) + ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) sws.sw_storm_counter_dict[_dict_key] = 1 return True diff --git a/snmptrap/mod/trapd_stormwatch_settings.py b/snmptrap/mod/trapd_stormwatch_settings.py index f2586f9..a4bc410 100644 --- a/snmptrap/mod/trapd_stormwatch_settings.py +++ b/snmptrap/mod/trapd_stormwatch_settings.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ """ """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" def init(): diff --git a/snmptrap/mod/trapd_vb_types.py b/snmptrap/mod/trapd_vb_types.py index 98d5d2c..0b73e68 100644 --- a/snmptrap/mod/trapd_vb_types.py +++ b/snmptrap/mod/trapd_vb_types.py @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (c) 2018-2020 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ module for converting varbind types from Net-SNMP to PYSNMP """ -__docformat__ = 'restructuredtext' +__docformat__ = "restructuredtext" import json import os @@ -42,18 +42,18 @@ prog_name = os.path.basename(__file__) # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # _pysnmp_to_netsnmp_vb_type = { - 'Integer32': 'integer', - 'Integer': 'integer', - 'Gauge32': 'unsigned', - 'Counter32': 'counter32', - 'OctetString': 'octet', - 'py_type_5': 'hex', - 'py_type_6': 'decimal', - 'Null': 'null', - 'ObjectIdentifier': 'oid', - 'TimeTicks': 'timeticks', - 'IpAddress': 'ipaddress', - 'Bits': 'bits' + "Integer32": "integer", + "Integer": "integer", + "Gauge32": "unsigned", + "Counter32": "counter32", + "OctetString": "octet", + "py_type_5": "hex", + "py_type_6": "decimal", + "Null": "null", + "ObjectIdentifier": "oid", + "TimeTicks": "timeticks", + "IpAddress": "ipaddress", + "Bits": "bits", } default_vb_type = "octet" @@ -77,7 +77,6 @@ def pysnmp_to_netsnmp_varbind_convert(_pysnmp_vb_type): return _netsnmp_vb_type except Exception as e: # if not found, return original pysnmp type - msg = ("%s not configured as pysnmp varbind type - returning %s" - % (_pysnmp_vb_type,default_vb_type)) + msg = "%s not configured as pysnmp varbind type - returning %s" % (_pysnmp_vb_type, default_vb_type) ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) return default_vb_type |