aboutsummaryrefslogtreecommitdiffstats
path: root/bin/mod
diff options
context:
space:
mode:
Diffstat (limited to 'bin/mod')
-rw-r--r--bin/mod/trapd_exit.py63
-rw-r--r--bin/mod/trapd_file_utils.py220
-rw-r--r--bin/mod/trapd_get_cbs_config.py116
-rw-r--r--bin/mod/trapd_http_session.py61
-rw-r--r--bin/mod/trapd_logging.py199
-rw-r--r--bin/mod/trapd_runtime_pid.py94
-rw-r--r--bin/mod/trapd_settings.py168
7 files changed, 921 insertions, 0 deletions
diff --git a/bin/mod/trapd_exit.py b/bin/mod/trapd_exit.py
new file mode 100644
index 0000000..a7ffc8a
--- /dev/null
+++ b/bin/mod/trapd_exit.py
@@ -0,0 +1,63 @@
+# ============LICENSE_START=======================================================
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2017-2018 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+"""
+trapc_exit_snmptrapd is responsible for removing any existing runtime PID
+file, and exiting with the provided (param 1) exit code
+"""
+
+__docformat__ = 'restructuredtext'
+
+import sys
+import os
+import string
+from trapd_runtime_pid import save_pid, rm_pid
+
+prog_name = os.path.basename(__file__)
+
+
+# # # # # # # # # # # # #
+# fx: cleanup_and_exit
+# - remove pid file
+# - exit with supplied return code
+# # # # # # # # # # # # #
+def cleanup_and_exit(_loc_exit_code, _pid_file_name):
+ """
+ Remove existing PID file, and exit with provided exit code
+ :Parameters:
+ _loc_exit_code
+ value to return to calling shell upon exit
+ _pid_file_name
+ name of file that contains current process ID (for
+ removal)
+ :Exceptions:
+ none
+ :Keywords:
+ runtime PID exit
+ :Variables:
+ _num_params
+ number of parameters passed to module
+ """
+
+ _num_params = len(locals())
+
+ if _num_params == 2:
+ rc = rm_pid(_pid_file_name)
+ sys.exit(_loc_exit_code)
diff --git a/bin/mod/trapd_file_utils.py b/bin/mod/trapd_file_utils.py
new file mode 100644
index 0000000..2da099b
--- /dev/null
+++ b/bin/mod/trapd_file_utils.py
@@ -0,0 +1,220 @@
+# ============LICENSE_START=======================================================)
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2018 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+"""
+"""
+
+__docformat__ = 'restructuredtext'
+
+# basics
+import datetime
+import errno
+import inspect
+import json
+import logging
+import logging.handlers
+import os
+import sys
+import string
+import time
+import traceback
+import unicodedata
+
+# dcae_snmptrap
+import trapd_settings as tds
+from trapd_logging import ecomp_logger, stdout_logger
+from trapd_exit import cleanup_and_exit
+
+prog_name = os.path.basename(__file__)
+
+
+# # # # # # # # # # # # # # # # # # #
+# fx: roll_all_logs -> roll all logs to timestamped backup
+# # # # # # # # # # ## # # # # # # #
+
+
+def roll_all_logs():
+ """
+ roll all active logs to timestamped version, open new one
+ based on frequency defined in files.roll_frequency
+ """
+
+ # first roll all the eelf files
+ # 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]:
+ fd.close()
+
+ roll_file(tds.eelf_error_file_name)
+ roll_file(tds.eelf_debug_file_name)
+ roll_file(tds.eelf_audit_file_name)
+ roll_file(tds.eelf_metrics_file_name)
+
+ except Exception as e:
+ msg = "Error closing logs: " + str(e)
+ stdout_logger(msg)
+ cleanup_and_exit(1, tds.pid_file_name)
+
+ reopened_successfully = open_eelf_logs()
+ if not reopened_successfully:
+ msg = "Error re-opening EELF logs during roll-over to timestamped versions - EXITING"
+ stdout_logger(msg)
+ cleanup_and_exit(1, tds.pid_file_name)
+
+ # json log
+ roll_file(tds.json_traps_filename)
+
+ 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)))
+ stdout_logger(msg)
+ cleanup_and_exit(1, tds.pid_file_name)
+
+ # arriving trap log
+ roll_file(tds.arriving_traps_filename)
+
+ 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)))
+ stdout_logger(msg)
+ cleanup_and_exit(1, tds.pid_file_name)
+
+
+
+# # # # # # # # # # # # # # # # # # #
+# fx: setup_ecomp_logs -> log in eelf format until standard
+# is released for python via LOG-161
+# # # # # # # # # # ## # # # # # # #
+
+
+def open_eelf_logs():
+ """
+ open various (multiple ???) 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_fd = open_file(tds.eelf_error_file_name)
+
+ except Exception as e:
+ msg = "Error opening eelf error log : " + str(e)
+ stdout_logger(msg)
+ 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_fd = open_file(tds.eelf_debug_file_name)
+
+ except Exception as e:
+ msg = "Error opening eelf debug log : " + str(e)
+ stdout_logger(msg)
+ 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_fd = open_file(tds.eelf_audit_file_name)
+ except Exception as e:
+ msg = "Error opening eelf audit log : " + str(e)
+ stdout_logger(msg)
+ cleanup_and_exit(1, tds.pid_file_name)
+
+ try:
+ tds.eelf_metrics_file_name = (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)
+ stdout_logger(msg)
+ cleanup_and_exit(1, tds.pid_file_name)
+
+ return True
+
+# # # # # # # # # # # # # # # # # # #
+# fx: roll_log_file -> move provided filename to timestamped version
+# # # # # # # # # # ## # # # # # # #
+
+
+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'))
+
+ _loc_file_name_bak = _loc_file_name + '.' + _file_name_suffix
+
+ # roll existing file if present
+ if os.path.isfile(_loc_file_name):
+ try:
+ os.rename(_loc_file_name, _loc_file_name_bak)
+ except:
+ _msg = ("ERROR: Unable to rename %s to %s"
+ % (_loc_file_name,
+ _loc_file_name_bak))
+ ecomp_logger(tds.LOG_TYPE_ERROR, tds.SEV_CRIT, tds.CODE_GENERAL, _msg)
+
+
+# # # # # # # # # # # # #
+# fx: open_log_file
+# # # # # # # # # # # # #
+
+
+def open_file(_loc_file_name):
+ """
+ open _loc_file_name, return file handle
+ """
+
+
+ try:
+ # open append mode just in case so nothing is lost, but should be
+ # non-existent file
+ _loc_fd = open(_loc_file_name, 'a')
+ 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
+# # # # # # # # # # # # #
+ """
+ close _loc_file_name, return True with success, False otherwise
+ """
+
+
+def close_file(_loc_fd, _loc_filename):
+
+ try:
+ _loc_fd.close()
+ return True
+ except Exception as 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
diff --git a/bin/mod/trapd_get_cbs_config.py b/bin/mod/trapd_get_cbs_config.py
new file mode 100644
index 0000000..775e0b2
--- /dev/null
+++ b/bin/mod/trapd_get_cbs_config.py
@@ -0,0 +1,116 @@
+# ============LICENSE_START=======================================================
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2018 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+"""
+Look for CBS broker and return application config; if not present, look for
+env variable that specifies JSON equiv of CBS config (typically used for
+testing purposes)
+"""
+
+__docformat__ = 'restructuredtext'
+
+import json
+import os
+import sys
+import string
+import time
+import traceback
+import collections
+
+import trapd_settings as tds
+from onap_dcae_cbs_docker_client.client import get_config
+from trapd_exit import cleanup_and_exit
+from trapd_logging import stdout_logger
+
+prog_name = os.path.basename(__file__)
+
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# function: trapd_get_config_sim
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+
+def get_cbs_config():
+ """
+ Get config values from CBS or JSON file (fallback)
+ :Parameters:
+ none
+ :Exceptions:
+ """
+
+ tds.c_config = {}
+
+ # See if we are in a config binding service (CBS) /controller environment
+ try:
+ tds.c_config = get_config()
+ if tds.c_config == {}:
+ msg = "Unable to fetch CBS config or it is erroneously empty - trying override/simulator config"
+ stdout_logger(msg)
+
+ # if no CBS present, default to JSON config specified via CBS_SIM_JSON env var
+ except Exception as e:
+ 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:
+ msg = "CBS_SIM_JSON not defined - FATAL ERROR, exiting"
+ stdout_logger(msg)
+ cleanup_and_exit(1, pid_file_name)
+
+ if _cbs_sim_json_file == "None":
+ msg = "CBS_SIM_JSON not defined - FATAL ERROR, exiting"
+ stdout_logger(msg)
+ cleanup_and_exit(1, pid_file_name)
+ else:
+ 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))
+ 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, tds.pid_file_name)
+
+ # recalc timeout, set default if not present
+ try:
+ tds.timeout_seconds = tds.c_config['publisher.http_timeout_milliseconds'] / 1000.0
+ except:
+ tds.timeout_seconds = 1.5
+
+ # recalc seconds_between_retries, set default if not present
+ try:
+ tds.seconds_between_retries = tds.c_config['publisher.http_milliseconds_between_retries'] / 1000.0
+ except:
+ tds.seconds_between_retries = .750
+
+ # recalc min_severity_to_log, set default if not present
+ try:
+ tds.minimum_severity_to_log = tds.c_config['files.minimum_severity_to_log']
+ except:
+ tds.minimum_severity_to_log = 3
+
+ try:
+ tds.publisher_retries = tds.c_config['publisher.http_retries']
+ except:
+ tds.publisher_retries = 3
+
+ return True
diff --git a/bin/mod/trapd_http_session.py b/bin/mod/trapd_http_session.py
new file mode 100644
index 0000000..2e0b77e
--- /dev/null
+++ b/bin/mod/trapd_http_session.py
@@ -0,0 +1,61 @@
+# ============LICENSE_START=======================================================
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2017-2018 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+"""
+trapd_http_session establishes an http session for future use in publishing
+messages to the dmaap cluster.
+"""
+
+__docformat__ = 'restructuredtext'
+
+import os
+import requests
+import traceback
+
+# snmptrapd
+import trapd_settings
+
+prog_name = os.path.basename(__file__)
+
+
+# # # # # # # # # # # # #
+# fx: init_session_obj
+# # # # # # # # # # # # #
+def init_session_obj():
+ """
+ Initializes and returns a http request session object for later use
+ :Parameters:
+ none
+ :Exceptions:
+ session object creation
+ this function will throw an exception if unable to create
+ a new session object
+ :Keywords:
+ http request session
+ :Variables:
+ none
+ """
+
+ try:
+ _loc_session = requests.Session()
+ except Exception as e:
+ return None
+
+ return _loc_session
diff --git a/bin/mod/trapd_logging.py b/bin/mod/trapd_logging.py
new file mode 100644
index 0000000..435f03e
--- /dev/null
+++ b/bin/mod/trapd_logging.py
@@ -0,0 +1,199 @@
+# ============LICENSE_START=======================================================)
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2018 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+"""
+"""
+
+__docformat__ = 'restructuredtext'
+
+# basics
+import datetime
+import errno
+import inspect
+import json
+import logging
+import logging.handlers
+import os
+import sys
+import string
+import time
+import traceback
+import unicodedata
+
+import trapd_settings as tds
+
+prog_name = os.path.basename(__file__)
+
+
+# # # # # # # # # # # # # # # # # # #
+# fx: ecomp_logger -> log in eelf format until standard
+# is released for python via LOG-161
+# # # # # # # # # # ## # # # # # # #
+
+def ecomp_logger(_log_type, _sev, _error_code, _msg):
+ """
+ Log to ecomp-style logfiles. Logs include:
+
+ Note: this will be updated when https://jira.onap.org/browse/LOG-161
+ is closed/available; until then, we resort to a generic format with
+ valuable info in "extra=" field (?)
+
+ :Parameters:
+ _msg -
+ :Exceptions:
+ none
+ :Keywords:
+ eelf logging
+ :Log Styles:
+
+ :error.log:
+
+ if CommonLogger.verbose: print("using CommonLogger.ErrorFile")
+ self._logger.log(50, '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' \
+ % (requestID, threadID, serviceName, partnerName, targetEntity, targetServiceName,
+ errorCategory, errorCode, errorDescription, detailMessage))
+
+ error.log example:
+
+ 2018-02-20T07:21:34,007+00:00||MainThread|snmp_log_monitor||||FATAL|900||Tue Feb 20 07:21:11 UTC 2018 CRITICAL: [a0cae74e-160e-11e8-8f9f-0242ac110002] ALL publish attempts failed to DMAPP server: dcae-mrtr-zltcrdm5bdce1.1dff83.rdm5b.tci.att.com, topic: DCAE-COLLECTOR-UCSNMP, 339 trap(s) not published in epoch_serno range: 15191112530000 - 15191112620010
+
+ :debug.log:
+
+ if CommonLogger.verbose: print("using CommonLogger.DebugFile")
+ self._logger.log(50, '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' \
+ % (requestID, threadID, serverName, serviceName, instanceUUID, upperLogLevel,
+ severity, serverIPAddress, server, IPAddress, className, timer, detailMessage))
+
+ debug.log example:
+
+ none available
+
+ :audit.log:
+
+ if CommonLogger.verbose: print("using CommonLogger.AuditFile")
+ endAuditTime, endAuditMsec = self._getTime()
+ if self._begTime is not None:
+ d = {'begtime': self._begTime, 'begmsecs': self._begMsec, 'endtime': endAuditTime,
+ 'endmsecs': endAuditMsec}
+ else:
+ d = {'begtime': endAuditTime, 'begmsecs': endAuditMsec, 'endtime': endAuditTime,
+ 'endmsecs': endAuditMsec}
+
+ self._logger.log(50, '%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' \
+ % (requestID, serviceInstanceID, threadID, serverName, serviceName, partnerName,
+ statusCode, responseCode, responseDescription, instanceUUID, upperLogLevel,
+ severity, serverIPAddress, timer, server, IPAddress, className, unused,
+ processKey, customField1, customField2, customField3, customField4,
+ detailMessage), extra=d)
+
+
+ :metrics.log:
+
+ self._logger.log(50,'%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' \
+ % (requestID, serviceInstanceID, threadID, serverName, serviceName, partnerName,
+ targetEntity, targetServiceName, statusCode, responseCode, responseDescription,
+ instanceUUID, upperLogLevel, severity, serverIPAddress, timer, server,
+ IPAddress,
+ className, unused, processKey, targetVirtualEntity, customField1, customField2,
+ customField3, customField4, detailMessage), extra=d)
+
+ metrics.log example:
+
+ none available
+
+
+ """
+
+ unused = ""
+
+ # ct = time.time()
+ # lt = time.localtime(ct)
+ # t_hman = time.strftime(DateFmt, lt)
+ # t_ms = (ct - int(ct)) * 1000
+ # above were various attempts at setting time string found in other
+ # libs; instead, let's keep it real:
+ t_out = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S,%f")[:-3]
+ calling_fx = inspect.stack()[1][3]
+
+ # FIXME: this entire module is a hack to override concept of prog logging
+ # written across multiple files (???), making diagnostics IMPOSSIBLE!
+ # Hoping to leverage ONAP logging libraries & standards when available
+
+ # 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|%s" \
+ % ((t_out, calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, (msg + _msg))))
+ tds.eelf_error_fd.write('%s\n' % str(_out_rec))
+ return False
+
+ if _sev >= tds.minimum_severity_to_log:
+ # log to appropriate eelf log (different files ??)
+ if _log_type == tds.LOG_TYPE_ERROR:
+ _out_rec = ('%s|%s|%s|%s|%s|%s|%s|%s|%s|%s' \
+ % ((t_out, calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)))
+ tds.eelf_error_fd.write('%s\n' % 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|%s' \
+ % ((t_out, calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)))
+ tds.eelf_audit_fd.write('%s\n' % 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|%s' \
+ % ((t_out, calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)))
+ tds.eelf_metrics_fd.write('%s\n' % str(_out_rec))
+
+ # DEBUG *AND* others - there *MUST BE* a single time-sequenced log for diagnostics!
+ # FIXME: too much I/O !!!
+ # always write to debug; we need ONE logfile that has time-sequence full view !!!
+ # if (_log_type == tds.LOG_TYPE_DEBUG and _sev >= tds.current_min_sev_log_level) or (_log_type != tds.LOG_TYPE_DEBUG):
+
+ # log message in DEBUG format
+ _out_rec = ("%s|%s|%s|%s|%s|%s|%s|%s|%s|%s" \
+ % ((t_out, calling_fx, "snmptrapd", unused, unused, unused, tds.SEV_TYPES[_sev], _error_code, unused, _msg)))
+ tds.eelf_debug_fd.write('%s\n' % str(_out_rec))
+
+ return True
+
+# # # # # # # # # # # # #
+# fx: stdout_logger
+# # # # # # # # # # # # #
+
+
+def stdout_logger(_msg):
+ """
+ Log info/errors to stdout. This is done:
+ - for critical runtime issues
+
+ :Parameters:
+ _msg
+ message to print
+ :Exceptions:
+ none
+ :Keywords:
+ log stdout
+ :Variables:
+ """
+
+ t_out = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S,%f")[:-3]
+ # calling_fx = inspect.stack()[1][3]
+
+ print('%s %s' % ( t_out, _msg))
diff --git a/bin/mod/trapd_runtime_pid.py b/bin/mod/trapd_runtime_pid.py
new file mode 100644
index 0000000..c6ef76e
--- /dev/null
+++ b/bin/mod/trapd_runtime_pid.py
@@ -0,0 +1,94 @@
+# ============LICENSE_START=======================================================
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2017-2018 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+"""
+trapd_runtime_pid maintains a 'PID file' (file that contains the
+PID of currently running trap receiver)
+"""
+
+__docformat__ = 'restructuredtext'
+
+import logging
+import os
+import string
+import time
+import traceback
+
+prog_name = os.path.basename(__file__)
+
+
+# # # # # # # # # # # # #
+# fx: save_pid - save PID of running process
+# # # # # # # # # # # # #
+def save_pid(_pid_file_name):
+ """
+ Save the current process ID in a file for external
+ access.
+ :Parameters:
+ none
+ :Exceptions:
+ file open
+ this function will catch exception of unable to
+ open/create _pid_file_name
+ :Keywords:
+ pid /var/run
+ """
+
+ try:
+ 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)
+ 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
+
+
+# # # # # # # # # # # # #
+# fx: rm_pid - remove PID of running process
+# # # # # # # # # # # # #
+def rm_pid(_pid_file_name):
+ """
+ Remove the current process ID file before exiting.
+ :Parameters:
+ none
+ :Exceptions:
+ file open
+ this function will catch exception of unable to find or remove
+ _pid_file_name
+ :Keywords:
+ pid /var/run
+ """
+
+ try:
+ if os.path.isfile(_pid_file_name):
+ os.remove(_pid_file_name)
+ return True
+ else:
+ return False
+
+ except IOError:
+ print("Error removing Runtime PID file: %s" % _pid_file_name)
+ return False
diff --git a/bin/mod/trapd_settings.py b/bin/mod/trapd_settings.py
new file mode 100644
index 0000000..735b68c
--- /dev/null
+++ b/bin/mod/trapd_settings.py
@@ -0,0 +1,168 @@
+# ============LICENSE_START=======================================================)
+# org.onap.dcae
+# ================================================================================
+# Copyright (c) 2018 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+#
+# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+#
+"""
+"""
+
+__docformat__ = 'restructuredtext'
+
+def init():
+
+ # <CONSUL config cache>
+ # consul config or simulated via json file
+ global c_config
+ c_config = None
+ # </CONSUL config cache>
+
+ # <DNS cache>
+ #
+ # dns_cache_ip_to_name
+ # key [ip address] -> fqdn
+ # dns_cache_ip_expires
+ # key [ip address] -> epoch time this entry expires and must be reloaded
+ global dns_cache_ip_to_name
+ dns_cache_ip_to_name = {}
+ global dns_cache_ip_expires
+ dns_cache_ip_expires = {}
+ # </DNS cache>
+
+ # <EELF logs>
+ global eelf_error_file_name
+ eelf_error_file_name = ""
+ global eelf_error_fd
+ eelf_error_fd = None
+
+ global eelf_debug_file_name
+ eelf_debug_file_name = ""
+ global eelf_debug_fd
+ eelf_debug_fd = None
+
+ global eelf_audit_file_name
+ eelf_audit_file_name = ""
+ global eelf_audit_fd
+ eelf_audit_fd = None
+
+ global eelf_metrics_file_name
+ eelf_metrics_file_name = ""
+ global eelf_metrics_fd
+ eelf_metrics_fd = None
+
+ global last_minute
+ last_minute = 0
+ global last_hour
+ last_hour = 0
+ global last_day
+ last_day = 0
+ # </EELF logs>
+
+ # <trap dictionary and corresponding strings for publish
+ global first_trap
+ first_trap = True
+ global first_varbind
+ first_varbind = True
+ global trap_dict
+ trap_dict = {}
+ global all_traps_str
+ all_traps_str = ""
+ global all_vb_json_str
+ all_vb_json_str = ""
+ global trap_uuids_in_buffer
+ trap_uuids_in_buffer = ""
+ # </trap and varbind dictionaries>
+
+ # <publish timers and counters>
+ global traps_in_minute
+ traps_in_minute = 0
+ global last_epoch_second
+ last_epoch_second = 0
+ global traps_since_last_publish
+ traps_since_last_publish = 0
+ global last_pub_time
+ last_pub_time = 0
+ global milliseconds_since_last_publish
+ milliseconds_since_last_publish = 0
+ global timeout_seconds
+ timeout_seconds = 1.5
+ global seconds_between_retries
+ seconds_between_retries = 2
+ global publisher_retries
+ publisher_retries = 2
+ # </publish timers and counters>
+
+ # <publish http request session (persistent as much as possible)>
+ global http_requ_session
+ http_requ_session = None
+ # </publish http request session>
+
+ # <json log of traps published>
+ global json_traps_filename
+ json_log_filename = ""
+ global json_traps_fd
+ json_fd = None
+ # </json log of traps published>
+
+ # <log of arriving traps >
+ global arriving_traps_filename
+ arriving_traps_filename = ""
+ global arriving_traps_fd
+ arriving_traps_fd = None
+ # <log of arriving traps >
+
+ # <runtime PID>
+ global pid_file_name
+ pid_file_name = ""
+
+ # <logging types and severities>
+ global LOG_TYPES
+ global LOG_TYPE_NONE
+ global LOG_TYPE_ERROR
+ global LOG_TYPE_DEBUG
+ global LOG_TYPE_AUDIT
+ global LOG_TYPE_METRICS
+ LOG_TYPES = ["none", "ERROR", "DEBUG", "AUDIT", "METRICS"]
+ LOG_TYPE_NONE = 0
+ LOG_TYPE_ERROR = 1
+ LOG_TYPE_DEBUG = 2
+ LOG_TYPE_AUDIT = 3
+ LOG_TYPE_METRICS = 4
+
+ global SEV_TYPES
+ global SEV_NONE
+ global SEV_DETAILED
+ global SEV_INFO
+ global SEV_WARN
+ global SEV_CRIT
+ global SEV_FATAL
+ SEV_TYPES = ["none", "DETAILED", "INFO", "WARN", "CRITICAL", "FATAL"]
+ SEV_NONE = 0
+ SEV_DETAILED = 1
+ SEV_INFO = 2
+ SEV_WARN = 3
+ SEV_CRIT = 4
+ SEV_FATAL = 5
+
+ global CODE_GENERAL
+ CODE_GENERAL="100"
+
+ global minimum_severity_to_log
+ minimum_severity_to_log=3
+
+
+ # </logging types and severities>