From c32beae4bb651af3725f1bbf8df5a1d9e4a4678c Mon Sep 17 00:00:00 2001 From: JHCD Date: Tue, 23 Jun 2015 18:37:32 +0200 Subject: [PATCH] change exception-handling - only error-msg instead of logging.exception - second logging.debug with exec-trace --- includes/alarmHandler.py | 21 ++++++++++++++----- includes/decoders/poc.py | 2 ++ plugins/BosMon/BosMon.py | 36 +++++++++++++++++++++----------- plugins/jsonSocket/jsonSocket.py | 2 ++ plugins/template/template.py | 36 +++++++++++++++++++++++++++----- 5 files changed, 75 insertions(+), 22 deletions(-) diff --git a/includes/alarmHandler.py b/includes/alarmHandler.py index 4a1b9c5..fa4ab19 100644 --- a/includes/alarmHandler.py +++ b/includes/alarmHandler.py @@ -43,12 +43,23 @@ def processAlarm(typ,freq,data): from includes import filter if filter.checkFilters(typ,data,pluginName,freq): logging.debug("call Plugin: %s", pluginName) - plugin.run(typ,freq,data) - logging.debug("return from: %s", pluginName) + try: + plugin.run(typ,freq,data) + logging.debug("return from: %s", pluginName) + except: + # call next plugin, if one has thrown an exception + logging.debug("return from: %s", pluginName, exc_info=True) + pass else: # RegEX filter off - call plugin directly logging.debug("call Plugin: %s", pluginName) - plugin.run(typ,freq,data) - logging.debug("return from: %s", pluginName) + try: + plugin.run(typ,freq,data) + logging.debug("return from: %s", pluginName) + except: + # call next plugin, if one has thrown an exception + logging.debug("return from: %s", pluginName, exc_info=True) + pass logging.debug("[END ALARM]") except: - logging.exception("Error in Alarm processing") \ No newline at end of file + logging.error("Error in Alarm processing") + logging.debug("Error in Alarm processing", exc_info=True) \ No newline at end of file diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index 4f8abc0..ce4d570 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -105,6 +105,8 @@ def decode(freq, decoded): if re.search("[0-9]{7}", poc_id): #if POC is valid if isAllowed(poc_id): # check for double alarm + logging.debug(" - old id: %s ", globals.poc_id_old) + logging.debug(" - old time: %s ", globals.poc_time_old) if poc_id == globals.poc_id_old and timestamp < globals.poc_time_old + globals.config.getint("POC", "double_ignore_time"): logging.info("POCSAG%s double alarm: %s within %s second(s)", bitrate, globals.poc_id_old, timestamp-globals.poc_time_old) # in case of double alarm, poc_double_ignore_time set new diff --git a/plugins/BosMon/BosMon.py b/plugins/BosMon/BosMon.py index 968c423..cf5da65 100644 --- a/plugins/BosMon/BosMon.py +++ b/plugins/BosMon/BosMon.py @@ -35,7 +35,6 @@ def bosMonRequest(httprequest, params, headers): @param headers: The headers argument should be a mapping of extra HTTP headers to send with the request. @return: nothing - @exception: Exception if httprequest.request failed """ try: # @@ -43,7 +42,9 @@ def bosMonRequest(httprequest, params, headers): # httprequest.request("POST", "/telegramin/"+globals.config.get("BosMon", "bosmon_channel")+"/input.xml", params, headers) except: - logging.exception("request to BosMon failed") + logging.error("request to BosMon failed") + logging.debug("request to BosMon failed", exc_info=True) + raise Exception("request to BosMon failed") else: # # check HTTP-Response @@ -77,9 +78,6 @@ def run(typ,freq,data): @requires: BosMon-Configuration has to be set in the config.ini @return: nothing - @exception: Exception if ConfigParser failed - @exception: Exception if initialize header and connect to BosMon-Server failed - @exception: Exception if urlencoding the params failed """ try: # @@ -90,7 +88,10 @@ def run(typ,freq,data): for key,val in globals.config.items("BosMon"): logging.debug(" - %s = %s", key, val) except: - logging.exception("cannot read config file") + logging.error("cannot read config file") + logging.debug("cannot read config file", exc_info=True) + # Without config, plugin couldn't work + return try: # @@ -105,11 +106,14 @@ def run(typ,freq,data): headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(globals.config.get("BosMon", "bosmon_user"), globals.config.get("BosMon", "bosmon_password")))) logging.debug("connect to BosMon") # open connection to BosMon-Server - httprequest = httplib.HTTPConnection(globals.config.get("BosMon", "bosmon_server"), globals.config.get("BosMon", "bosmon_port")) + httprequest = httplib.HTTPConnection(globals.config.get("BosMon", "bosmon_server"), globals.config.get("BosMon", "bosmon_port"), timeout=5) # debug-level to shell (0=no debug|1) httprequest.set_debuglevel(0) except: - logging.exception("cannot connect to BosMon") + logging.error("cannot connect to BosMon") + logging.debug("cannot connect to BosMon", exc_info=True) + # Without connection, plugin couldn't work + return else: # @@ -141,7 +145,9 @@ def run(typ,freq,data): # dispatch the BosMon-request bosMonRequest(httprequest, params, headers) except: - logging.exception("FMS to BosMon failed") + logging.error("FMS to BosMon failed") + logging.debug("FMS to BosMon failed", exc_info=True) + return elif typ == "ZVEI": logging.debug("Start ZVEI to BosMon") @@ -151,7 +157,9 @@ def run(typ,freq,data): # dispatch the BosMon-request bosMonRequest(httprequest, params, headers) except: - logging.exception("ZVEI to BosMon failed") + logging.error("ZVEI to BosMon failed") + logging.debug("ZVEI to BosMon failed", exc_info=True) + return elif typ == "POC": logging.debug("Start POC to BosMon") @@ -162,7 +170,9 @@ def run(typ,freq,data): # dispatch the BosMon-request bosMonRequest(httprequest, params, headers) except: - logging.exception("POC to BosMon failed") + logging.error("POC to BosMon failed") + logging.debug("POC to BosMon failed", exc_info=True) + return else: logging.warning("Invalid Typ: %s", typ) @@ -172,4 +182,6 @@ def run(typ,freq,data): httprequest.close() except: - logging.exception("") \ No newline at end of file + # something very mysterious + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) \ No newline at end of file diff --git a/plugins/jsonSocket/jsonSocket.py b/plugins/jsonSocket/jsonSocket.py index 4da3012..69766a0 100644 --- a/plugins/jsonSocket/jsonSocket.py +++ b/plugins/jsonSocket/jsonSocket.py @@ -51,6 +51,8 @@ def run(typ,freq,data): except: logging.error("cannot read config file") logging.debug("cannot read config file", exc_info=True) + # Without config, plugin couldn't work + return try: # diff --git a/plugins/template/template.py b/plugins/template/template.py index 5e99e1a..85a92e9 100644 --- a/plugins/template/template.py +++ b/plugins/template/template.py @@ -24,17 +24,42 @@ import logging # Global logger from includes import globals # Global variables - +## +# +# Main function of plugin +# will be called by the alarmHandler +# def run(typ,freq,data): + """ + This function is the implementation of the Plugin. + + If necessary the configuration hast to be set in the config.ini. + + @type typ: string (FMS|ZVEI|POC) + @param typ: Typ of the dataset + @type data: map of data (structure see interface.txt) + @param data: Contains the parameter for dispatch + @type freq: string + @keyword freq: frequency of the SDR Stick + + @requires: If necessary the configuration hast to be set in the config.ini. + + @return: nothing + """ try: - #ConfigParser + # + # ConfigParser + # logging.debug("reading config file") try: for key,val in globals.config.items("template"): logging.debug(" - %s = %s", key, val) except: - logging.exception("cannot read config file") - + logging.error("cannot read config file") + logging.debug("cannot read config file", exc_info=True) + # Without config, plugin couldn't work + return + ########## User Plugin CODE ########## if typ == "FMS": logging.warning("%s not supported", typ) @@ -47,4 +72,5 @@ def run(typ,freq,data): ########## User Plugin CODE ########## except: - logging.exception("unknown error") \ No newline at end of file + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) \ No newline at end of file