change exception-handling

- only error-msg instead of logging.exception
- second logging.debug with exec-trace
This commit is contained in:
JHCD 2015-06-23 18:37:32 +02:00
parent 74c804f4c3
commit c32beae4bb
5 changed files with 75 additions and 22 deletions

View file

@ -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")
logging.error("Error in Alarm processing")
logging.debug("Error in Alarm processing", exc_info=True)

View file

@ -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

View file

@ -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("")
# something very mysterious
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)

View file

@ -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:
#

View file

@ -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")
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)