mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-05 14:35:17 +00:00
change exception-handling
- only error-msg instead of logging.exception - second logging.debug with exec-trace
This commit is contained in:
parent
c32beae4bb
commit
d6b9174112
10 changed files with 132 additions and 61 deletions
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue