mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-01-20 23:30:17 +01:00
use globals.config
This commit is contained in:
parent
5f667678d9
commit
76222da522
19
boswatch.py
19
boswatch.py
|
|
@ -168,8 +168,7 @@ try:
|
|||
try:
|
||||
globals.config = ConfigParser.ConfigParser()
|
||||
globals.config.read(script_path+"/config/config.ini")
|
||||
config = dict(globals.config.items("BOSWatch"))
|
||||
for key,val in config.items():
|
||||
for key,val in globals.config.items("BOSWatch"):
|
||||
logging.debug(" - %s = %s", key, val)
|
||||
except:
|
||||
logging.exception("cannot read config file")
|
||||
|
|
@ -229,7 +228,7 @@ try:
|
|||
if "CRC correct" in decoded: #check CRC is correct
|
||||
fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id
|
||||
if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid
|
||||
if fms_id == fms_id_old and timestamp < fms_time_old + int(config["fms_double_ignore_time"]): #check for double alarm
|
||||
if fms_id == fms_id_old and timestamp < fms_time_old + globals.config.getint("BOSWatch", "fms_double_ignore_time"): #check for double alarm
|
||||
logging.warning("FMS double alarm: %s within %s second(s)", fms_id_old, timestamp-fms_time_old)
|
||||
fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new
|
||||
else:
|
||||
|
|
@ -252,7 +251,7 @@ try:
|
|||
|
||||
zvei_id = decoded[7:12] #ZVEI Code
|
||||
if re.search("[0-9F]{5}", zvei_id): #if ZVEI is valid
|
||||
if zvei_id == zvei_id_old and timestamp < zvei_time_old + int(config["zvei_double_ignore_time"]): #check for double alarm
|
||||
if zvei_id == zvei_id_old and timestamp < zvei_time_old + globals.config.getint("BOSWatch", "zvei_double_ignore_time"): #check for double alarm
|
||||
logging.warning("ZVEI double alarm: %s within %s second(s)", zvei_id_old, timestamp-zvei_time_old)
|
||||
zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new
|
||||
else:
|
||||
|
|
@ -280,9 +279,9 @@ try:
|
|||
poc_text = ""
|
||||
|
||||
if re.search("[0-9]{7}", poc_id): #if POC is valid
|
||||
if poc_id >= int(config["poc_filter_range_start"]):
|
||||
if poc_id <= int(config["poc_filter_range_end"]):
|
||||
if poc_id == poc_id_old and timestamp < poc_time_old + int(config["poc_double_ignore_time"]): #check for double alarm
|
||||
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 == 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
|
||||
else:
|
||||
|
|
@ -314,9 +313,9 @@ try:
|
|||
poc_text = ""
|
||||
|
||||
if re.search("[0-9]{7}", poc_id): #if POC is valid
|
||||
if poc_id >= int(config["poc_filter_range_start"]):
|
||||
if poc_id <= int(config["poc_filter_range_end"]):
|
||||
if poc_id == poc_id_old and timestamp < poc_time_old + int(config["poc_double_ignore_time"]): #check for double alarm
|
||||
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 == poc_id_old and timestamp < poc_time_old + globals.config.getint("BOSWatch", "poc_double_ignore_time"): #check for double alarm
|
||||
logging.warning("POC1200 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
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ def run(typ,freq,data):
|
|||
#ConfigParser
|
||||
logging.debug("reading config file")
|
||||
try:
|
||||
config = dict(globals.config.items("BosMon"))
|
||||
for key,val in config.items():
|
||||
for key,val in globals.config.items("BOSWatch"):
|
||||
logging.debug(" - %s = %s", key, val)
|
||||
except:
|
||||
logging.exception("cannot read config file")
|
||||
|
|
@ -41,8 +40,8 @@ def run(typ,freq,data):
|
|||
headers['Content-type'] = "application/x-www-form-urlencoded"
|
||||
headers['Accept'] = "text/plain"
|
||||
if bosmon_user:
|
||||
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(config["bosmon_user"], config["bosmon_password"])))
|
||||
httprequest = httplib.HTTPConnection(config["bosmon_server"], config["bosmon_port"])
|
||||
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(globals.config.get("BosMon", "bosmon_user"), globals.config.get("BosMon", "bosmon_password"))))
|
||||
httprequest = httplib.HTTPConnection(globals.config.get("BosMon", "bosmon_server"), globals.config.get("BosMon", "bosmon_port"))
|
||||
httprequest.request("POST", "/telegramin/"+bosmon_channel+"/input.xml", params, headers)
|
||||
httpresponse = httprequest.getresponse()
|
||||
if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ def run(typ,freq,data):
|
|||
#ConfigParser
|
||||
logging.debug("reading config file")
|
||||
try:
|
||||
config = dict(globals.config.items("MySQL"))
|
||||
for key,val in config.items():
|
||||
for key,val in globals.config.items("BOSWatch"):
|
||||
logging.debug(" - %s = %s", key, val)
|
||||
except:
|
||||
logging.exception("cannot read config file")
|
||||
|
|
|
|||
|
|
@ -7,23 +7,21 @@ import globals # Global variables
|
|||
def run(typ,freq,data):
|
||||
try:
|
||||
#ConfigParser
|
||||
#config Data in config["OPTION"]
|
||||
logging.debug("reading config file")
|
||||
try:
|
||||
config = dict(globals.config.items("template"))
|
||||
for key,val in config.items():
|
||||
for key,val in globals.config.items("BOSWatch"):
|
||||
logging.debug(" - %s = %s", key, val)
|
||||
except:
|
||||
logging.exception("cannot read config file")
|
||||
|
||||
if typ == "FMS":
|
||||
logging.debug("FMS: %s Status: %s Dir: %s TKI: %s", data["fms"], data["status"], data["direction"], data["tki"])
|
||||
logging.debug(typ + " not supported")
|
||||
elif typ == "ZVEI":
|
||||
logging.debug("ZVEI: %s", data["zvei"])
|
||||
logging.debug(typ + " not supported")
|
||||
elif typ == "POC":
|
||||
logging.debug("POC: %s-%s - %s", data["ric"], data["function"], data["msg"])
|
||||
logging.debug(typ + " not supported")
|
||||
else:
|
||||
logging.warning(typ + " not supportet")
|
||||
logging.warning(typ + " not supported")
|
||||
|
||||
except:
|
||||
logging.exception("unknown error")
|
||||
Loading…
Reference in a new issue