diff options
author | Hansen, Tony (th1395) <th1395@att.com> | 2022-08-17 21:36:24 +0000 |
---|---|---|
committer | Hansen, Tony (th1395) <th1395@att.com> | 2022-08-22 20:40:07 +0000 |
commit | 4b6b34642374103b8ccf938eb9e970232bfb63ae (patch) | |
tree | 526c304ddc9207831cc27b6b26d01e46be5c763c /snmptrap | |
parent | 5116f87391d00c04b789a59d1abcebbbf80147ad (diff) |
CodeCoverage improvement (60% to 90%)
Change-Id: I579e9d3fedbd6cc2589d189b121fa7dadfb6f7f1
Signed-off-by: Hansen, Tony (th1395) <th1395@att.com>
Issue-ID: DCAEGEN2-3158
Signed-off-by: Hansen, Tony (th1395) <th1395@att.com>
Diffstat (limited to 'snmptrap')
-rw-r--r-- | snmptrap/makefile | 2 | ||||
-rw-r--r-- | snmptrap/mod/trapd_exit.py | 7 | ||||
-rw-r--r-- | snmptrap/mod/trapd_get_cbs_config.py | 29 | ||||
-rw-r--r-- | snmptrap/mod/trapd_http_session.py | 5 | ||||
-rw-r--r-- | snmptrap/mod/trapd_io.py | 41 | ||||
-rw-r--r-- | snmptrap/mod/trapd_runtime_pid.py | 9 | ||||
-rw-r--r-- | snmptrap/mod/trapd_settings.py | 4 | ||||
-rw-r--r-- | snmptrap/mod/trapd_snmpv3.py | 6 | ||||
-rw-r--r-- | snmptrap/mod/trapd_stormwatch.py | 20 | ||||
-rwxr-xr-x | snmptrap/scheduler.sh | 12 | ||||
-rw-r--r-- | snmptrap/snmptrapd.py | 40 | ||||
-rwxr-xr-x | snmptrap/snmptrapd.sh | 26 |
12 files changed, 99 insertions, 102 deletions
diff --git a/snmptrap/makefile b/snmptrap/makefile new file mode 100644 index 0000000..aa9d159 --- /dev/null +++ b/snmptrap/makefile @@ -0,0 +1,2 @@ +runtests: + cd .. && $(MAKE) runtests 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) diff --git a/snmptrap/scheduler.sh b/snmptrap/scheduler.sh index bb2d083..bf989b9 100755 --- a/snmptrap/scheduler.sh +++ b/snmptrap/scheduler.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # ============LICENSE_START======================================================= -# Copyright (c) 2017-2020 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. @@ -56,10 +56,10 @@ _verbosity=$2 _log_message=$3 echo "`date` `date +%s` ${_fx} ${_error_code} ${_log_message}" >> ${log_fd} - + # log_lines=`wc -l ${log_fd} | awk {'print $1'} | bc` # log_lines=$((${log_lines}+1)) - + # if [ ${log_lines} -ge ${max_log_lines} ] # then # if [ -f ${log_fd} ] @@ -178,9 +178,9 @@ do run_daily_jobs # reset last_day last_day=${current_day} - fi - fi - fi + fi + fi + fi fi sleep ${sleep_time} done diff --git a/snmptrap/snmptrapd.py b/snmptrap/snmptrapd.py index ddb6b32..d8d86e5 100644 --- a/snmptrap/snmptrapd.py +++ b/snmptrap/snmptrapd.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. @@ -167,6 +167,7 @@ def load_all_configs(_signum, _frame): def resolve_ip(_loc_ip_addr_str): try: + if int(tds.dns_cache_ip_expires[_loc_ip_addr_str] < int(time.time())): raise Exception( "cache expired for %s at %d - updating value" @@ -515,20 +516,21 @@ def snmp_engine_observer_cb(snmp_engine, execpoint, variables, cbCtx): # tds.trap_dict["notify OID"] = "." + str(enterprise) + ".0." + str(specific_trap) # tds.trap_dict["notify OID len"] = tds.trap_dict["notify OID"].count('.') # tds.trap_dict["sysUptime"] = variables['pdu']['time-stamp'].prettyPrint() + + elif snmp_version == 2: + tds.trap_dict["protocol version"] = "v2c" + + elif snmp_version == 3: + tds.trap_dict["protocol version"] = "v3" + # tds.trap_dict["security level"] = str(variables['securityLevel']) + # tds.trap_dict["context name"] = str( + # variables['contextName'].prettyPrint()) + # tds.trap_dict["security name"] = str(variables['securityName']) + # tds.trap_dict["security engine"] = str( + # variables['contextEngineId'].prettyPrint()) + else: - if snmp_version == 2: - tds.trap_dict["protocol version"] = "v2c" - else: - if snmp_version == 3: - tds.trap_dict["protocol version"] = "v3" - # tds.trap_dict["security level"] = str(variables['securityLevel']) - # tds.trap_dict["context name"] = str( - # variables['contextName'].prettyPrint()) - # tds.trap_dict["security name"] = str(variables['securityName']) - # tds.trap_dict["security engine"] = str( - # variables['contextEngineId'].prettyPrint()) - else: - tds.trap_dict["protocol version"] = "unknown" + tds.trap_dict["protocol version"] = "unknown" # tds.trap_dict['time received'] = epoch_msecond tds.trap_dict["time received"] = epoch_second @@ -672,15 +674,6 @@ def notif_receiver_cb(snmp_engine, stateReference, contextEngineId, contextName, msg = "processing varbinds for %s" % (tds.trap_dict["uuid"]) ecomp_logger(tds.LOG_TYPE_DEBUG, tds.SEV_INFO, tds.CODE_GENERAL, msg) - # help(snmp_engine) - # print(snmp_engine) - # help(varBinds) - # print(varBinds) - # help(cbCtx) - # print(cbCtx) - # for key, val in cbCtx: - # print(key, val) - # FMDL update reset location when batching publishes pdu_varbind_count = 0 payload_varbinds = 0 @@ -735,6 +728,7 @@ def notif_receiver_cb(snmp_engine, stateReference, contextEngineId, contextName, if tds.first_trap: tds.all_traps_json_str = curr_trap_json_str tds.trap_uuids_in_buffer = tds.trap_dict["uuid"] + tds.first_trap = False else: tds.trap_uuids_in_buffer = tds.trap_uuids_in_buffer + ", " + tds.trap_dict["uuid"] diff --git a/snmptrap/snmptrapd.sh b/snmptrap/snmptrapd.sh index 717f660..6755c0c 100755 --- a/snmptrap/snmptrapd.sh +++ b/snmptrap/snmptrapd.sh @@ -2,7 +2,7 @@ # -*- indent-tabs-mode: nil -*- # vi: set expandtab: # # ============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. @@ -66,7 +66,7 @@ fi export PYTHONPATH=${bin_base_dir}/mod:$PYTHONPATH # PYTHONUNBUFFERED: -# set PYTHONUNBUFFERED to a non-empty string to avoid output buffering; +# set PYTHONUNBUFFERED to a non-empty string to avoid output buffering; # comment out for runtime environments/better performance! # export PYTHONUNBUFFERED="True" @@ -77,14 +77,14 @@ export CBS_SIM_JSON=${base_dir}/etc/snmptrapd.json # misc exit_after=1 -# # # # # # # # # # +# # # # # # # # # # # log_msg - log messages to stdout in standard manner -# # # # # # # # # # +# # # # # # # # # # log_msg() { msg=$* - echo "`date +%Y-%m-%dT%H:%M:%S,%N | cut -c1-23` ${msg}" + echo "`date +%Y-%m-%dT%H:%M:%S,%N | cut -c1-23` ${msg}" } # @@ -96,7 +96,7 @@ process_name=$1 pid_file=$2 exec_cmd=$3 - # check if exec_cmd has a pid_file + # check if exec_cmd has a pid_file if [ ! -r ${pid_file} ] then log_msg "Starting ${process_name}" @@ -123,13 +123,13 @@ exec_cmd=$3 fi } -# # # # # # # # # # +# # # # # # # # # # # Start the service -# # # # # # # # # # +# # # # # # # # # # start_service() { # Hints for startup modifications: - # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ # handy for debug (e.g. docker logs output) # log_msg "Runtime env present for ${current_module} placed in ${base_dir}/logs/${current_module}.out" @@ -165,9 +165,9 @@ start_service() fi } -# # # # # # # # # # +# # # # # # # # # # # Stop the service -# # # # # # # # # # +# # # # # # # # # # stop_process() { process_name=$1 @@ -337,7 +337,7 @@ case "$1" in status_service wait ;; - "stop") + "stop") version stop_service ;; @@ -348,7 +348,7 @@ case "$1" in start_service status_service ;; - "status") + "status") version status_service ;; |