mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-04 14:07:25 +00:00
implement MySQL-plugin
This commit is contained in:
parent
a942688775
commit
9000b77349
3 changed files with 38 additions and 19 deletions
|
|
@ -3,28 +3,45 @@
|
|||
|
||||
import logging # Global logger
|
||||
import globals # Global variables
|
||||
import mysql
|
||||
import mysql.connector
|
||||
|
||||
def run(typ,freq,data):
|
||||
try:
|
||||
#ConfigParser
|
||||
logging.debug("reading config file")
|
||||
try:
|
||||
for key,val in globals.config.items("BOSWatch"):
|
||||
for key,val in globals.config.items("MySQL"):
|
||||
logging.debug(" - %s = %s", key, val)
|
||||
except:
|
||||
logging.exception("cannot read config file")
|
||||
|
||||
if typ == "FMS":
|
||||
#logging.debug("FMS: %s Status: %s Dir: %s", data["fms"], data["status"], data["direction"])
|
||||
logging.debug("FMS")
|
||||
elif typ == "ZVEI":
|
||||
#logging.debug("ZVEI: %s", data["zvei"])
|
||||
logging.debug("ZVEI")
|
||||
elif typ == "POC":
|
||||
#logging.debug("POC: %s/%s - %s", data["ric"], data["function"], data["msg"])
|
||||
logging.debug("POC")
|
||||
else:
|
||||
logging.warning(typ + " not supportet")
|
||||
|
||||
#open DB-Connection
|
||||
try:
|
||||
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()
|
||||
|
||||
if typ == "FMS":
|
||||
#data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tsi":fms_tsi}
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableFMS")+" (time,fms,status,direction,tsi) VALUES (NOW(),%s,%s,%s,%s)",(data["fms"],data["status"],data["direction"],data["tsi"]))
|
||||
|
||||
elif typ == "ZVEI":
|
||||
#data = {"zvei":zvei_id}
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableZVEI")+" (time,zvei) VALUES (NOW(),"+data["zvei"]+")")
|
||||
|
||||
elif typ == "POC":
|
||||
#data = {"ric":poc_id, "function":poc_sub, "msg":poc_text}
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tablePOC")+" (time,ric,funktion,text) VALUES (NOW(),%s,%s,%s)",(data["ric"],data["function"],data["msg"]))
|
||||
|
||||
else:
|
||||
logging.warning(typ + " not supportet")
|
||||
return
|
||||
|
||||
cursor.close()
|
||||
connection.commit()
|
||||
except:
|
||||
logging.exception("%s to MySQL failed", typ)
|
||||
finally:
|
||||
connection.close() #Close connection in every case
|
||||
except:
|
||||
logging.exception("unknown error")
|
||||
|
|
@ -14,7 +14,7 @@ FMS:
|
|||
- fms
|
||||
- status
|
||||
- direction
|
||||
- tki
|
||||
- tsi
|
||||
|
||||
POCSAG:
|
||||
- ric
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue