aboutsummaryrefslogtreecommitdiffstats
path: root/snmptrap/mod
diff options
context:
space:
mode:
Diffstat (limited to 'snmptrap/mod')
-rw-r--r--snmptrap/mod/trapd_exit.py7
-rw-r--r--snmptrap/mod/trapd_get_cbs_config.py29
-rw-r--r--snmptrap/mod/trapd_http_session.py5
-rw-r--r--snmptrap/mod/trapd_io.py41
-rw-r--r--snmptrap/mod/trapd_runtime_pid.py9
-rw-r--r--snmptrap/mod/trapd_settings.py4
-rw-r--r--snmptrap/mod/trapd_snmpv3.py6
-rw-r--r--snmptrap/mod/trapd_stormwatch.py20
8 files changed, 61 insertions, 60 deletions
diff --git a/snmptrap/mod/trapd_exit.py b/snmptrap/mod/trapd_exit.py
index 1d1ea16..0959399 100644
--- a/snmptrap/mod/trapd_exit.py
+++ b/snmptrap/mod/trapd_exit.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 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.
@@ -46,13 +46,8 @@ def cleanup_and_exit(_loc_exit_code, _pid_file_name):
none
:Keywords:
runtime PID exit
- :Variables:
- _num_params
- number of parameters passed to module
"""
- # _num_params = len(locals())
-
if _pid_file_name is not None:
rc = rm_pid(_pid_file_name)
sys.exit(_loc_exit_code)
diff --git a/snmptrap/mod/trapd_get_cbs_config.py b/snmptrap/mod/trapd_get_cbs_config.py
index cfae994..9ed7916 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-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 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.
@@ -64,28 +64,23 @@ def get_cbs_config():
msg = "ONAP controller not present, trying json config override via CBS_SIM_JSON env variable"
stdout_logger(msg)
- try:
- _cbs_sim_json_file = os.getenv("CBS_SIM_JSON", "None")
- except Exception as e:
+ _cbs_sim_json_file = os.getenv("CBS_SIM_JSON")
+
+ if _cbs_sim_json_file is None:
msg = "CBS_SIM_JSON not defined - FATAL ERROR, exiting"
stdout_logger(msg)
cleanup_and_exit(1, None)
- if _cbs_sim_json_file == "None":
- msg = "CBS_SIM_JSON not defined - FATAL ERROR, exiting"
+ 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
stdout_logger(msg)
- cleanup_and_exit(1, None)
- else:
- msg = "ONAP controller override specified via CBS_SIM_JSON: %s" % _cbs_sim_json_file
+ except Exception as e:
+ msg = "Unable to load CBS_SIM_JSON " + _cbs_sim_json_file + " (invalid json?) - FATAL ERROR, exiting"
stdout_logger(msg)
- try:
- tds.c_config = json.load(open(_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"
- stdout_logger(msg)
- cleanup_and_exit(1, None)
+ cleanup_and_exit(1, None)
# display consul config returned, regardless of source
msg = "cbs config: %s" % json.dumps(tds.c_config)
diff --git a/snmptrap/mod/trapd_http_session.py b/snmptrap/mod/trapd_http_session.py
index 7118d00..1c93edc 100644
--- a/snmptrap/mod/trapd_http_session.py
+++ b/snmptrap/mod/trapd_http_session.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 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.
@@ -23,6 +23,9 @@ __docformat__ = "restructuredtext"
import os
import requests
import traceback
+from trapd_io import ecomp_logger, stdout_logger
+import trapd_settings as tds
+from trapd_exit import cleanup_and_exit
prog_name = os.path.basename(__file__)
diff --git a/snmptrap/mod/trapd_io.py b/snmptrap/mod/trapd_io.py
index f7c48b7..2ba44b4 100644
--- a/snmptrap/mod/trapd_io.py
+++ b/snmptrap/mod/trapd_io.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 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.
@@ -54,15 +54,19 @@ 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, nm in [
+ (tds.eelf_error_fd, "error"),
+ (tds.eelf_debug_fd, "debug"),
+ (tds.eelf_audit_fd, "eelf"),
+ (tds.eelf_metrics_fd, "metrics"),
+ (tds.arriving_traps_fd, "arriving_traps"),
+ (tds.json_traps_fd, "json_traps"),
]:
- fd.close()
+ if fd is None:
+ msg = "Error closing log file for " + nm
+ stdout_logger(msg)
+ else:
+ fd.close()
roll_file(tds.eelf_error_file_name)
roll_file(tds.eelf_debug_file_name)
@@ -86,7 +90,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" % (tds.json_traps_filename, str(e))
stdout_logger(msg)
cleanup_and_exit(1, tds.pid_file_name)
@@ -96,7 +100,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" % (tds.arriving_traps_filename, str(e))
stdout_logger(msg)
cleanup_and_exit(1, tds.pid_file_name)
@@ -119,6 +123,7 @@ def open_eelf_logs():
tds.eelf_error_fd = open_file(tds.eelf_error_file_name)
except Exception as e:
+ # here if we cannot create the filename
msg = "Error opening eelf error log : " + str(e)
stdout_logger(msg)
cleanup_and_exit(1, tds.pid_file_name)
@@ -128,6 +133,7 @@ def open_eelf_logs():
tds.eelf_debug_fd = open_file(tds.eelf_debug_file_name)
except Exception as e:
+ # here if we cannot create the filename
msg = "Error opening eelf debug log : " + str(e)
stdout_logger(msg)
cleanup_and_exit(1, tds.pid_file_name)
@@ -136,6 +142,7 @@ def open_eelf_logs():
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:
+ # here if we cannot create the filename
msg = "Error opening eelf audit log : " + str(e)
stdout_logger(msg)
cleanup_and_exit(1, tds.pid_file_name)
@@ -146,6 +153,7 @@ def open_eelf_logs():
)
tds.eelf_metrics_fd = open_file(tds.eelf_metrics_file_name)
except Exception as e:
+ # here if we cannot create the filename
msg = "Error opening eelf metric log : " + str(e)
stdout_logger(msg)
cleanup_and_exit(1, tds.pid_file_name)
@@ -202,15 +210,14 @@ def open_file(_loc_file_name):
stdout_logger(msg)
cleanup_and_exit(1, tds.pid_file_name)
- # # # # # # # # # # # # #
- # fx: close_file
- # # # # # # # # # # # # #
- """
- close _loc_file_name, return True with success, False otherwise
- """
+
+# # # # # # # # # # # # #
+# fx: close_file
+# # # # # # # # # # # # #
def close_file(_loc_fd, _loc_filename):
+ """ close _loc_file_name, return True with success, False otherwise """
try:
_loc_fd.close()
diff --git a/snmptrap/mod/trapd_runtime_pid.py b/snmptrap/mod/trapd_runtime_pid.py
index c647885..0a9eac6 100644
--- a/snmptrap/mod/trapd_runtime_pid.py
+++ b/snmptrap/mod/trapd_runtime_pid.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2017-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2022 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.
@@ -53,11 +53,7 @@ def save_pid(_pid_file_name):
except IOError:
print("IOError saving PID file %s :" % _pid_file_name)
return False
- # except:
- # print("Error saving PID file %s :" % _pid_file_name)
- # return False
else:
- # print("Runtime PID file: %s" % _pid_file_name)
return True
@@ -76,7 +72,6 @@ def rm_pid(_pid_file_name):
:Keywords:
pid /var/run
"""
-
try:
if os.path.isfile(_pid_file_name):
os.remove(_pid_file_name)
@@ -84,6 +79,6 @@ def rm_pid(_pid_file_name):
else:
return False
- except IOError:
+ except:
print("Error removing Runtime PID file: %s" % _pid_file_name)
return False
diff --git a/snmptrap/mod/trapd_settings.py b/snmptrap/mod/trapd_settings.py
index 26e7c9b..33cf56b 100644
--- a/snmptrap/mod/trapd_settings.py
+++ b/snmptrap/mod/trapd_settings.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 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.
@@ -114,7 +114,7 @@ def init():
global json_traps_filename
json_traps_filename = ""
global json_traps_fd
- json_fd = None
+ json_traps_fd = None
# </json log of traps published>
# <log of arriving traps >
diff --git a/snmptrap/mod/trapd_snmpv3.py b/snmptrap/mod/trapd_snmpv3.py
index 56ecb5c..1a1cc0c 100644
--- a/snmptrap/mod/trapd_snmpv3.py
+++ b/snmptrap/mod/trapd_snmpv3.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2018-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2018-2022 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.
@@ -82,8 +82,6 @@ def load_snmpv3_credentials(_py_config, _snmp_engine, _cbs_config):
# find options at -> site-packages/pysnmp/entity/config.py
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
- # print("Checking auth for %s" % (userName))
-
# usmHMACMD5AuthProtocol
try:
authKey = v3_user["usmHMACMD5AuthProtocol"]
@@ -123,8 +121,6 @@ def load_snmpv3_credentials(_py_config, _snmp_engine, _cbs_config):
# find options at -> site-packages/pysnmp/entity/config.py
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
- # print("Checking priv for %s" % (userName))
-
# usm3DESEDEPriv
try:
privKey = v3_user["usm3DESEDEPrivProtocol"]
diff --git a/snmptrap/mod/trapd_stormwatch.py b/snmptrap/mod/trapd_stormwatch.py
index 4c374bb..d0ff5a7 100644
--- a/snmptrap/mod/trapd_stormwatch.py
+++ b/snmptrap/mod/trapd_stormwatch.py
@@ -1,5 +1,5 @@
# ============LICENSE_START=======================================================
-# Copyright (c) 2020-2021 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2020-2022 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.
@@ -65,8 +65,8 @@ def sw_init():
# # # # # # # # # # # # #
-# fx: sw_storm_active
-# - check if storm is active for agent/oid
+# fx: sw_clear_dicts
+# - clear out all dictionaries in stats
# - returns True if yes, False if no
# # # # # # # # # # # # #
def sw_clear_dicts():
@@ -97,7 +97,9 @@ def sw_clear_dicts():
if hasattr(sws, "sw_config_category"):
sws.sw_config_category.clear()
return True
+
except Exception as e:
+ print(f">>>> got exception {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
@@ -123,7 +125,8 @@ def sw_load_trap_config(_config):
ret = sw_clear_dicts()
msg = "reset existing sws dictionaries to empty"
ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg)
- except NameError:
+
+ except (NameError, AttributeError):
msg = "sws dictionaries not present - initializing"
ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg)
ret = sw_init()
@@ -138,6 +141,7 @@ def sw_load_trap_config(_config):
)
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"
ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg)
@@ -148,6 +152,7 @@ def sw_load_trap_config(_config):
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"
ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg)
@@ -156,16 +161,18 @@ def sw_load_trap_config(_config):
# add trap configs from CBS json structure to running config
try:
notify_oids = _config["trap_config"]["notify_oids"]
+
except Exception as e:
msg = "no trap_config or notify_oids defined"
ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_WARN, tds.CODE_GENERAL, msg)
- return False
+ return 0
trap_block_counter = 0
for trap_block in notify_oids:
# oid
try:
_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)
@@ -174,6 +181,7 @@ def sw_load_trap_config(_config):
# sw_high_water_in_interval
try:
_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"
@@ -184,6 +192,7 @@ def sw_load_trap_config(_config):
# sw_low_water_in_interval
try:
_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"
@@ -194,6 +203,7 @@ def sw_load_trap_config(_config):
# category
try:
_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)