mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-01-24 00:50:22 +01:00
implement MySQL-plugin
This commit is contained in:
parent
a942688775
commit
9000b77349
12
boswatch.py
Normal file → Executable file
12
boswatch.py
Normal file → Executable file
|
|
@ -203,8 +203,10 @@ try:
|
|||
#decoded = str(multimon_ng.stdout.readline()) #Get line data from multimon stdout
|
||||
|
||||
#only for develop
|
||||
decoded = "ZVEI2: 25832"
|
||||
#decoded = "ZVEI2: 25832"
|
||||
#decoded = "FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=III(mit NA,ohneSIGNAL)) CRC correct\n'"
|
||||
#decoded = "POCSAG512: Address: 1234567 Function: 0 Alpha: Hello World"
|
||||
#decoded = "POCSAG512: Address: 1234567 Function: 1 Alpha: XXMSG MEfeweffsjh"
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
|
@ -233,7 +235,7 @@ try:
|
|||
fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new
|
||||
else:
|
||||
logging.info("FMS:%s Status:%s Richtung:%s TKI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi)
|
||||
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tki":fms_tsi}
|
||||
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tsi":fms_tsi}
|
||||
throwAlarm("FMS",data)
|
||||
|
||||
fms_id_old = fms_id #save last id
|
||||
|
|
@ -280,7 +282,7 @@ try:
|
|||
|
||||
if re.search("[0-9]{7}", poc_id): #if POC is valid
|
||||
if poc_id >= globals.config.getint("BOSWatch", "poc_filter_range_start"):
|
||||
if poc_id <= globals.config.getint("BOSWatch", "poc_filter_range_end"):
|
||||
if poc_id <= globals.config.getint("BOSWatch", "poc_filter_range_end"):
|
||||
if poc_id == poc_id_old and timestamp < poc_time_old + globals.config.getint("BOSWatch", "poc_double_ignore_time"): #check for double alarm
|
||||
logging.warning("POC512 double alarm: %s within %s second(s)", poc_id_old, timestamp-poc_time_old)
|
||||
poc_time_old = timestamp #in case of double alarm, poc_double_ignore_time set new
|
||||
|
|
@ -292,9 +294,9 @@ try:
|
|||
poc_id_old = poc_id #save last id
|
||||
poc_time_old = timestamp #save last time
|
||||
else:
|
||||
logging.warning("POCSAG512: %s out of filter range", poc_id)
|
||||
logging.warning("POCSAG512: %s out of filter range (high)", poc_id)
|
||||
else:
|
||||
logging.warning("POCSAG512: %s out of filter range", poc_id)
|
||||
logging.warning("POCSAG512: %s out of filter range (low)", poc_id)
|
||||
else:
|
||||
logging.warning("No valid POCSAG512: %s", poc_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -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…
Reference in a new issue