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 22:27:48 +02:00
parent c32beae4bb
commit d6b9174112
10 changed files with 132 additions and 61 deletions

View file

@ -48,7 +48,6 @@ def processAlarm(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)
@ -57,9 +56,7 @@ def processAlarm(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.error("Error in Alarm processing")
logging.debug("Error in Alarm processing", exc_info=True)
logging.exception("Error in alarm processing")

View file

@ -62,9 +62,14 @@ def decode(freq, decoded):
from includes import descriptionList
data["description"] = descriptionList.getDescription("FMS", fms_id[0:8])
# processing the alarm
from includes import alarmHandler
alarmHandler.processAlarm("FMS",freq,data)
try:
from includes import alarmHandler
alarmHandler.processAlarm("POC",freq,data)
except:
logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True)
pass
# in every time save old data for double alarm
globals.fms_id_old = fms_id #save last id
globals.fms_time_old = timestamp #save last time
else:

View file

@ -105,8 +105,6 @@ 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
@ -121,9 +119,14 @@ def decode(freq, decoded):
from includes import descriptionList
data["description"] = descriptionList.getDescription("POC", poc_id)
# processing the alarm
from includes import alarmHandler
alarmHandler.processAlarm("POC",freq,data)
try:
from includes import alarmHandler
alarmHandler.processAlarm("POC",freq,data)
except:
logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True)
pass
# in every time save old data for double alarm
globals.poc_id_old = poc_id #save last id
globals.poc_time_old = timestamp #save last time
else:

View file

@ -74,9 +74,14 @@ def decode(freq, decoded):
from includes import descriptionList
data["description"] = descriptionList.getDescription("ZVEI", zvei_id)
# processing the alarm
from includes import alarmHandler
alarmHandler.processAlarm("ZVEI",freq,data)
try:
from includes import alarmHandler
alarmHandler.processAlarm("POC",freq,data)
except:
logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True)
pass
# in every time save old data for double alarm
globals.zvei_id_old = zvei_id # save last id
globals.zvei_time_old = timestamp # save last time
else:

View file

@ -35,6 +35,7 @@ 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 HTTP-Request failed
"""
try:
#
@ -44,7 +45,7 @@ def bosMonRequest(httprequest, params, headers):
except:
logging.error("request to BosMon failed")
logging.debug("request to BosMon failed", exc_info=True)
raise Exception("request to BosMon failed")
raise
else:
#
# check HTTP-Response
@ -94,7 +95,7 @@ def run(typ,freq,data):
return
try:
#
#
# Initialize header an connect to BosMon-Server
#
headers = {}
@ -116,7 +117,7 @@ def run(typ,freq,data):
return
else:
#
#
# Format given data-structure to compatible BosMon string
#
if typ == "FMS":
@ -179,9 +180,12 @@ def run(typ,freq,data):
finally:
logging.debug("close BosMon-Connection")
httprequest.close()
except:
try:
httprequest.close()
except:
pass
except:
# something very mysterious
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)

View file

@ -43,19 +43,20 @@ def run(typ,freq,data):
@requires: Created Database/Tables, see boswatch.sql
@return: nothing
@exception: Exception if ConfigParser failed
@exception: Exception if connect to MySQL failed
@exception: Exception if executing the sql-statement is failed
"""
try:
#
#ConfigParser
#
logging.debug("reading config file")
try:
for key,val in globals.config.items("MySQL"):
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:
#
@ -65,7 +66,11 @@ def run(typ,freq,data):
connection = mysql.connector.connect(host = globals.config.get("MySQL","dbserver"), user = globals.config.get("MySQL","dbuser"), passwd = globals.config.get("MySQL","dbpassword"), db = globals.config.get("MySQL","database"))
cursor = connection.cursor()
except:
logging.exception("cannot connect to MySQL")
logging.error("cannot connect to MySQL")
logging.debug("cannot connect to MySQL", exc_info=True)
# Without connection, plugin couldn't work
return
else:
try:
#
@ -89,11 +94,18 @@ def run(typ,freq,data):
else:
logging.warning("Invalid Typ: %s", typ)
except:
logging.exception("cannot Insert %s", typ)
logging.error("cannot Insert %s", typ)
logging.debug("cannot Insert %s", typ, exc_info=True)
return
finally:
logging.debug("close MySQL")
cursor.close()
connection.close() #Close connection in every case
try:
cursor.close()
connection.close() #Close connection in every case
except:
pass
except:
logging.exception("unknown error")
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)

View file

@ -54,7 +54,9 @@ def doSendmail(server, subject, mailtext):
msg['Priority'] = globals.config.get("eMail", "priority")
server.sendmail(globals.config.get("eMail", "from"), globals.config.get("eMail", "to"), msg.as_string())
except:
logging.exception("send eMail failed")
logging.error("send eMail failed")
logging.debug("send eMail failed", exc_info=True)
raise
##
@ -80,9 +82,6 @@ def run(typ,freq,data):
@requires: eMail-Configuration has to be set in the config.ini
@return: nothing
@exception: Exception if ConfigParser failed
@exception: Exception if connect to SMTP-Server failed
@exception: Exception if sending the eMail failed
"""
try:
#
@ -94,7 +93,10 @@ def run(typ,freq,data):
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:
#
@ -113,7 +115,10 @@ def run(typ,freq,data):
server.login(globals.config.get("eMail", "user"), globals.config.get("eMail", "password"))
except:
logging.exception("cannot connect to eMail")
logging.error("cannot connect to eMail")
logging.debug("cannot connect to eMail", exc_info=True)
# Without connection, plugin couldn't work
return
else:
@ -137,7 +142,9 @@ def run(typ,freq,data):
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.exception("FMS to eMail failed")
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
elif typ == "ZVEI":
logging.debug("Start ZVEI to eMail")
@ -155,7 +162,9 @@ def run(typ,freq,data):
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.exception("ZVEI to eMail failed")
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
elif typ == "POC":
logging.debug("Start POC to eMail")
@ -177,14 +186,21 @@ def run(typ,freq,data):
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.exception("POC to eMail failed")
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
else:
logging.warning("Invalid Typ: %s", typ)
finally:
logging.debug("close eMail-Connection")
server.quit()
try:
server.quit()
except:
pass
except:
logging.exception("")
# something very mysterious
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)

View file

@ -36,9 +36,6 @@ def run(typ,freq,data):
@requires: firEmergency-Configuration has to be set in the config.ini
@return: nothing
@exception: Exception if ConfigParser failed
@exception: Exception ifconnect to firEmergency failed
@exception: Exception if sending the data failed
"""
try:
#
@ -49,7 +46,10 @@ def run(typ,freq,data):
for key,val in globals.config.items("firEmergency"):
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:
#
@ -58,7 +58,11 @@ def run(typ,freq,data):
firSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
firSocket.connect((globals.config.get("firEmergency", "firserver"), globals.config.getint("firEmergency", "firport")))
except:
logging.exception("cannot connect to firEmergency")
logging.error("cannot connect to firEmergency")
logging.debug("cannot connect to firEmergency", exc_info=True)
# Without connection, plugin couldn't work
return
else:
#
# Format given data-structure to xml-string for firEmergency
@ -72,22 +76,32 @@ def run(typ,freq,data):
firXML = "<event>\n<address>"+data["zvei"]+"</address>\n<message>"+data["zvei"]+" alarmiert.</message>\n</event>\n"
firSocket.send(firXML)
except:
logging.exception("ZVEI to firEmergency failed")
logging.error("%s to firEmergency failed", typ)
logging.debug("%s to firEmergency failed", typ, exc_info=True)
# Without connection, plugin couldn't work
return
elif typ == "POC":
logging.debug("POC to firEmergency")
try:
firXML = "<event>\n<address>"+data["ric"]+"</address>\n<message>"+data["msg"]+"</message>\n</event>\n"
firSocket.send(firXML)
except:
logging.exception("POC to firEmergency failed")
logging.error("%s to firEmergency failed", typ)
logging.debug("%s to firEmergency failed", typ, exc_info=True)
# Without connection, plugin couldn't work
return
else:
logging.warning("Invalid Typ: %s", typ)
finally:
logging.debug("close firEmergency-Connection")
firSocket.close()
try:
firSocket.close()
except:
pass
except:
logging.exception("unknown error")
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)

View file

@ -36,9 +36,6 @@ def run(typ,freq,data):
@requires: httpRequest-Configuration has to be set in the config.ini
@return: nothing
@exception: Exception if ConfigParser failed
@exception: Exception if http Request failed
@exception: Exception if http Response failed
"""
try:
#
@ -49,7 +46,10 @@ def run(typ,freq,data):
for key,val in globals.config.items("httpRequest"):
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:
#
@ -79,7 +79,10 @@ def run(typ,freq,data):
httprequest.request("GET", url[5]) #send URL Querry per GET
except:
logging.exception("cannot send HTTP request")
logging.error("cannot send HTTP request")
logging.debug("cannot send HTTP request", exc_info=True)
return
else:
try:
#
@ -91,11 +94,17 @@ def run(typ,freq,data):
else:
logging.warning("HTTP response: %s - %s" , str(httpresponse.status), str(httpresponse.reason))
except: #otherwise
logging.exception("cannot get HTTP response")
logging.error("cannot get HTTP response")
logging.debug("cannot get HTTP response", exc_info=True)
return
finally:
logging.debug("close HTTP-Connection")
httprequest.close()
try:
httprequest.close()
except:
pass
except:
logging.exception("unknown error")
logging.error("unknown error")
logging.debug("unknown error", exc_info=True)

View file

@ -69,6 +69,8 @@ def run(typ,freq,data):
except:
logging.error("cannot initialize %s-socket", globals.config.get("jsonSocket", "protocol"))
logging.debug("cannot initialize %s-socket", globals.config.get("jsonSocket", "protocol"), exc_info=True)
# Without connection, plugin couldn't work
return
else:
# toDo is equals for all types, so only check if typ is supported
@ -83,13 +85,17 @@ def run(typ,freq,data):
except:
logging.error("%s to %s failed", typ, globals.config.get("jsonSocket", "protocol"))
logging.debug("%s to %s failed", typ, globals.config.get("jsonSocket", "protocol"), exc_info=True)
return
else:
logging.warning("Invalid Typ: %s", typ)
finally:
logging.debug("close %s-Connection", globals.config.get("jsonSocket", "protocol"))
sock.close()
try:
sock.close()
except:
pass
except:
# something very mysterious