mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2025-12-06 07:42:03 +01:00
rename globals. call to globalVars.
This commit is contained in:
parent
f8fcda94b6
commit
e938cdcd6d
72
boswatch.py
72
boswatch.py
|
|
@ -76,21 +76,21 @@ try:
|
||||||
#
|
#
|
||||||
# Script-pathes
|
# Script-pathes
|
||||||
#
|
#
|
||||||
globals.script_path = os.path.dirname(os.path.abspath(__file__))
|
globalVars.script_path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set log_path
|
# Set log_path
|
||||||
#
|
#
|
||||||
if args.usevarlog:
|
if args.usevarlog:
|
||||||
globals.log_path = "/var/log/BOSWatch/"
|
globalVars.log_path = "/var/log/BOSWatch/"
|
||||||
else:
|
else:
|
||||||
globals.log_path = globals.script_path+"/log/"
|
globalVars.log_path = globalVars.script_path+"/log/"
|
||||||
|
|
||||||
#
|
#
|
||||||
# If necessary create log-path
|
# If necessary create log-path
|
||||||
#
|
#
|
||||||
if not os.path.exists(globals.log_path):
|
if not os.path.exists(globalVars.log_path):
|
||||||
os.mkdir(globals.log_path)
|
os.mkdir(globalVars.log_path)
|
||||||
except:
|
except:
|
||||||
# we couldn't work without logging -> exit
|
# we couldn't work without logging -> exit
|
||||||
print "ERROR: cannot initialize paths"
|
print "ERROR: cannot initialize paths"
|
||||||
|
|
@ -106,7 +106,7 @@ try:
|
||||||
#formatter = logging.Formatter('%(asctime)s - %(module)-15s %(funcName)-15s [%(levelname)-8s] %(message)s', '%d.%m.%Y %H:%M:%S')
|
#formatter = logging.Formatter('%(asctime)s - %(module)-15s %(funcName)-15s [%(levelname)-8s] %(message)s', '%d.%m.%Y %H:%M:%S')
|
||||||
formatter = logging.Formatter('%(asctime)s - %(module)-15s [%(levelname)-8s] %(message)s', '%d.%m.%Y %H:%M:%S')
|
formatter = logging.Formatter('%(asctime)s - %(module)-15s [%(levelname)-8s] %(message)s', '%d.%m.%Y %H:%M:%S')
|
||||||
# create a file logger
|
# create a file logger
|
||||||
fh = MyTimedRotatingFileHandler.MyTimedRotatingFileHandler(globals.log_path+"boswatch.log", "midnight", interval=1, backupCount=999)
|
fh = MyTimedRotatingFileHandler.MyTimedRotatingFileHandler(globalVars.log_path+"boswatch.log", "midnight", interval=1, backupCount=999)
|
||||||
# Starts with log level >= Debug
|
# Starts with log level >= Debug
|
||||||
# will be changed with config.ini-param later
|
# will be changed with config.ini-param later
|
||||||
fh.setLevel(logging.DEBUG)
|
fh.setLevel(logging.DEBUG)
|
||||||
|
|
@ -135,9 +135,9 @@ try:
|
||||||
# Clear the logfiles
|
# Clear the logfiles
|
||||||
#
|
#
|
||||||
fh.doRollover()
|
fh.doRollover()
|
||||||
rtl_log = open(globals.log_path+"rtl_fm.log", "w")
|
rtl_log = open(globalVars.log_path+"rtl_fm.log", "w")
|
||||||
mon_log = open(globals.log_path+"multimon.log", "w")
|
mon_log = open(globalVars.log_path+"multimon.log", "w")
|
||||||
rawMmOut = open(globals.log_path+"mm_raw.txt", "w")
|
rawMmOut = open(globalVars.log_path+"mm_raw.txt", "w")
|
||||||
rtl_log.write("")
|
rtl_log.write("")
|
||||||
mon_log.write("")
|
mon_log.write("")
|
||||||
rawMmOut.write("")
|
rawMmOut.write("")
|
||||||
|
|
@ -157,8 +157,8 @@ try:
|
||||||
# For debug display/log args
|
# For debug display/log args
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
logging.debug("SW Version: %s",globals.versionNr)
|
logging.debug("SW Version: %s",globalVars.versionNr)
|
||||||
logging.debug("Build Date: %s",globals.buildDate)
|
logging.debug("Build Date: %s",globalVars.buildDate)
|
||||||
logging.debug("BOSWatch given arguments")
|
logging.debug("BOSWatch given arguments")
|
||||||
if args.test:
|
if args.test:
|
||||||
logging.debug(" - Test-Mode!")
|
logging.debug(" - Test-Mode!")
|
||||||
|
|
@ -208,10 +208,10 @@ try:
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
logging.debug("reading config file")
|
logging.debug("reading config file")
|
||||||
globals.config = ConfigParser.ConfigParser()
|
globalVars.config = ConfigParser.ConfigParser()
|
||||||
globals.config.read(globals.script_path+"/config/config.ini")
|
globalVars.config.read(globalVars.script_path+"/config/config.ini")
|
||||||
# if given loglevel is debug:
|
# if given loglevel is debug:
|
||||||
if globals.config.getint("BOSWatch","loglevel") == 10:
|
if globalVars.config.getint("BOSWatch","loglevel") == 10:
|
||||||
configHandler.checkConfig("BOSWatch")
|
configHandler.checkConfig("BOSWatch")
|
||||||
configHandler.checkConfig("FMS")
|
configHandler.checkConfig("FMS")
|
||||||
configHandler.checkConfig("ZVEI")
|
configHandler.checkConfig("ZVEI")
|
||||||
|
|
@ -227,10 +227,10 @@ try:
|
||||||
# Set the loglevel and backupCount of the file handler
|
# Set the loglevel and backupCount of the file handler
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
logging.debug("set loglevel of fileHandler to: %s",globals.config.getint("BOSWatch","loglevel"))
|
logging.debug("set loglevel of fileHandler to: %s",globalVars.config.getint("BOSWatch","loglevel"))
|
||||||
fh.setLevel(globals.config.getint("BOSWatch","loglevel"))
|
fh.setLevel(globalVars.config.getint("BOSWatch","loglevel"))
|
||||||
logging.debug("set backupCount of fileHandler to: %s", globals.config.getint("BOSWatch","backupCount"))
|
logging.debug("set backupCount of fileHandler to: %s", globalVars.config.getint("BOSWatch","backupCount"))
|
||||||
fh.setBackupCount(globals.config.getint("BOSWatch","backupCount"))
|
fh.setBackupCount(globalVars.config.getint("BOSWatch","backupCount"))
|
||||||
except:
|
except:
|
||||||
# It's an error, but we could work without that stuff...
|
# It's an error, but we could work without that stuff...
|
||||||
logging.error("cannot set loglevel of fileHandler")
|
logging.error("cannot set loglevel of fileHandler")
|
||||||
|
|
@ -244,16 +244,16 @@ try:
|
||||||
try:
|
try:
|
||||||
if configHandler.checkConfig("NMAHandler"):
|
if configHandler.checkConfig("NMAHandler"):
|
||||||
# is NMAHandler enabled?
|
# is NMAHandler enabled?
|
||||||
if globals.config.getboolean("NMAHandler", "enableHandler") == True:
|
if globalVars.config.getboolean("NMAHandler", "enableHandler") == True:
|
||||||
# we only could do something, if an APIKey is given:
|
# we only could do something, if an APIKey is given:
|
||||||
if len(globals.config.get("NMAHandler","APIKey")) > 0:
|
if len(globalVars.config.get("NMAHandler","APIKey")) > 0:
|
||||||
logging.debug("add NMA logging handler")
|
logging.debug("add NMA logging handler")
|
||||||
from includes import NMAHandler
|
from includes import NMAHandler
|
||||||
if globals.config.get("NMAHandler","appName") == "":
|
if globalVars.config.get("NMAHandler","appName") == "":
|
||||||
nmaHandler = NMAHandler.NMAHandler(globals.config.get("NMAHandler","APIKey"))
|
nmaHandler = NMAHandler.NMAHandler(globalVars.config.get("NMAHandler","APIKey"))
|
||||||
else:
|
else:
|
||||||
nmaHandler = NMAHandler.NMAHandler(globals.config.get("NMAHandler","APIKey"), globals.config.get("NMAHandler","appName"))
|
nmaHandler = NMAHandler.NMAHandler(globalVars.config.get("NMAHandler","APIKey"), globalVars.config.get("NMAHandler","appName"))
|
||||||
nmaHandler.setLevel(globals.config.getint("NMAHandler","loglevel"))
|
nmaHandler.setLevel(globalVars.config.getint("NMAHandler","loglevel"))
|
||||||
myLogger.addHandler(nmaHandler)
|
myLogger.addHandler(nmaHandler)
|
||||||
except:
|
except:
|
||||||
# It's an error, but we could work without that stuff...
|
# It's an error, but we could work without that stuff...
|
||||||
|
|
@ -280,7 +280,7 @@ try:
|
||||||
# Load filters
|
# Load filters
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
if globals.config.getboolean("BOSWatch","useRegExFilter"):
|
if globalVars.config.getboolean("BOSWatch","useRegExFilter"):
|
||||||
from includes import regexFilter
|
from includes import regexFilter
|
||||||
regexFilter.loadFilters()
|
regexFilter.loadFilters()
|
||||||
except:
|
except:
|
||||||
|
|
@ -293,7 +293,7 @@ try:
|
||||||
# Load description lists
|
# Load description lists
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
if globals.config.getboolean("FMS","idDescribed") or globals.config.getboolean("ZVEI","idDescribed") or globals.config.getboolean("POC","idDescribed"):
|
if globalVars.config.getboolean("FMS","idDescribed") or globalVars.config.getboolean("ZVEI","idDescribed") or globalVars.config.getboolean("POC","idDescribed"):
|
||||||
from includes import descriptionList
|
from includes import descriptionList
|
||||||
descriptionList.loadDescriptionLists()
|
descriptionList.loadDescriptionLists()
|
||||||
except:
|
except:
|
||||||
|
|
@ -309,13 +309,13 @@ try:
|
||||||
if not args.test:
|
if not args.test:
|
||||||
logging.debug("starting rtl_fm")
|
logging.debug("starting rtl_fm")
|
||||||
command = ""
|
command = ""
|
||||||
if globals.config.has_option("BOSWatch","rtl_path"):
|
if globalVars.config.has_option("BOSWatch","rtl_path"):
|
||||||
command = globals.config.get("BOSWatch","rtl_path")
|
command = globalVars.config.get("BOSWatch","rtl_path")
|
||||||
command = command+"rtl_fm -d "+str(args.device)+" -f "+str(freqConverter.freqToHz(args.freq))+" -M fm -p "+str(args.error)+" -E DC -F 0 -l "+str(args.squelch)+" -g "+str(args.gain)+" -s 22050"
|
command = command+"rtl_fm -d "+str(args.device)+" -f "+str(freqConverter.freqToHz(args.freq))+" -M fm -p "+str(args.error)+" -E DC -F 0 -l "+str(args.squelch)+" -g "+str(args.gain)+" -s 22050"
|
||||||
rtl_fm = subprocess.Popen(command.split(),
|
rtl_fm = subprocess.Popen(command.split(),
|
||||||
#stdin=rtl_fm.stdout,
|
#stdin=rtl_fm.stdout,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=open(globals.log_path+"rtl_fm.log","a"),
|
stderr=open(globalVars.log_path+"rtl_fm.log","a"),
|
||||||
shell=False)
|
shell=False)
|
||||||
# rtl_fm doesn't self-destruct, when an error occurs
|
# rtl_fm doesn't self-destruct, when an error occurs
|
||||||
# wait a moment to give the subprocess a chance to write the logfile
|
# wait a moment to give the subprocess a chance to write the logfile
|
||||||
|
|
@ -336,13 +336,13 @@ try:
|
||||||
if not args.test:
|
if not args.test:
|
||||||
logging.debug("starting multimon-ng")
|
logging.debug("starting multimon-ng")
|
||||||
command = ""
|
command = ""
|
||||||
if globals.config.has_option("BOSWatch","multimon_path"):
|
if globalVars.config.has_option("BOSWatch","multimon_path"):
|
||||||
command = globals.config.get("BOSWatch","multimon_path")
|
command = globalVars.config.get("BOSWatch","multimon_path")
|
||||||
command = command+"multimon-ng "+str(demodulation)+" -f alpha -t raw /dev/stdin - "
|
command = command+"multimon-ng "+str(demodulation)+" -f alpha -t raw /dev/stdin - "
|
||||||
multimon_ng = subprocess.Popen(command.split(),
|
multimon_ng = subprocess.Popen(command.split(),
|
||||||
stdin=rtl_fm.stdout,
|
stdin=rtl_fm.stdout,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=open(globals.log_path+"multimon.log","a"),
|
stderr=open(globalVars.log_path+"multimon.log","a"),
|
||||||
shell=False)
|
shell=False)
|
||||||
# multimon-ng doesn't self-destruct, when an error occurs
|
# multimon-ng doesn't self-destruct, when an error occurs
|
||||||
# wait a moment to give the subprocess a chance to write the logfile
|
# wait a moment to give the subprocess a chance to write the logfile
|
||||||
|
|
@ -367,9 +367,9 @@ try:
|
||||||
decoder.decode(freqConverter.freqToHz(args.freq), decoded)
|
decoder.decode(freqConverter.freqToHz(args.freq), decoded)
|
||||||
|
|
||||||
# write multimon-ng raw data
|
# write multimon-ng raw data
|
||||||
if globals.config.getboolean("BOSWatch","writeMultimonRaw"):
|
if globalVars.config.getboolean("BOSWatch","writeMultimonRaw"):
|
||||||
try:
|
try:
|
||||||
rawMmOut = open(globals.log_path+"mm_raw.txt", "a")
|
rawMmOut = open(globalVars.log_path+"mm_raw.txt", "a")
|
||||||
rawMmOut.write(decoded)
|
rawMmOut.write(decoded)
|
||||||
except:
|
except:
|
||||||
logging.warning("cannot write raw multimon data")
|
logging.warning("cannot write raw multimon data")
|
||||||
|
|
@ -377,7 +377,7 @@ try:
|
||||||
rawMmOut.close()
|
rawMmOut.close()
|
||||||
else:
|
else:
|
||||||
logging.debug("start testing")
|
logging.debug("start testing")
|
||||||
testFile = open(globals.script_path+"/testdata/testdata.txt","r")
|
testFile = open(globalVars.script_path+"/testdata/testdata.txt","r")
|
||||||
for testData in testFile:
|
for testData in testFile:
|
||||||
if (len(testData.rstrip(' \t\n\r')) > 1) and ("#" not in testData[0]):
|
if (len(testData.rstrip(' \t\n\r')) > 1) and ("#" not in testData[0]):
|
||||||
logging.info("Testdata: %s", testData.rstrip(' \t\n\r'))
|
logging.info("Testdata: %s", testData.rstrip(' \t\n\r'))
|
||||||
|
|
@ -417,7 +417,7 @@ finally:
|
||||||
# Close Logging
|
# Close Logging
|
||||||
logging.debug("close Logging")
|
logging.debug("close Logging")
|
||||||
# Waiting for all Threads to write there logs
|
# Waiting for all Threads to write there logs
|
||||||
if globals.config.getboolean("BOSWatch","processAlarmAsync") == True:
|
if globalVars.config.getboolean("BOSWatch","processAlarmAsync") == True:
|
||||||
logging.debug("waiting 3s for threads...")
|
logging.debug("waiting 3s for threads...")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
logging.info("BOSWatch exit()")
|
logging.info("BOSWatch exit()")
|
||||||
|
|
|
||||||
|
|
@ -79,14 +79,14 @@ try:
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
logging.debug("reading config file")
|
logging.debug("reading config file")
|
||||||
globals.config = ConfigParser.SafeConfigParser()
|
globalData.config = ConfigParser.SafeConfigParser()
|
||||||
globals.config.read("config.ini")
|
globalData.config.read("config.ini")
|
||||||
# if given loglevel is debug:
|
# if given loglevel is debug:
|
||||||
logging.debug("- [AlarmMonitor]")
|
logging.debug("- [AlarmMonitor]")
|
||||||
for key,val in globals.config.items("AlarmMonitor"):
|
for key,val in globalData.config.items("AlarmMonitor"):
|
||||||
logging.debug("-- %s = %s", key, val)
|
logging.debug("-- %s = %s", key, val)
|
||||||
logging.debug("- [Display]")
|
logging.debug("- [Display]")
|
||||||
for key,val in globals.config.items("Display"):
|
for key,val in globalData.config.items("Display"):
|
||||||
logging.debug("-- %s = %s", key, val)
|
logging.debug("-- %s = %s", key, val)
|
||||||
except:
|
except:
|
||||||
# we couldn't work without config -> exit
|
# we couldn't work without config -> exit
|
||||||
|
|
@ -106,7 +106,7 @@ try:
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
from displayServices import displayPainter, autoTurnOffDisplay, eventHandler
|
from displayServices import displayPainter, autoTurnOffDisplay, eventHandler
|
||||||
globals.screenBackground = pygame.Color(globals.config.get("AlarmMonitor","colourGreen"))
|
globalData.screenBackground = pygame.Color(globalData.config.get("AlarmMonitor","colourGreen"))
|
||||||
logging.debug("Start displayPainter-thread")
|
logging.debug("Start displayPainter-thread")
|
||||||
Thread(target=displayPainter).start()
|
Thread(target=displayPainter).start()
|
||||||
logging.debug("start autoTurnOffDisplay-thread")
|
logging.debug("start autoTurnOffDisplay-thread")
|
||||||
|
|
@ -124,7 +124,7 @@ try:
|
||||||
#
|
#
|
||||||
logging.debug("Start socketServer")
|
logging.debug("Start socketServer")
|
||||||
sock = socket.socket () # TCP
|
sock = socket.socket () # TCP
|
||||||
sock.bind(("",globals.config.getint("AlarmMonitor","socketPort")))
|
sock.bind(("",globalData.config.getint("AlarmMonitor","socketPort")))
|
||||||
sock.listen(5)
|
sock.listen(5)
|
||||||
logging.debug("socketServer runs")
|
logging.debug("socketServer runs")
|
||||||
|
|
||||||
|
|
@ -132,45 +132,45 @@ try:
|
||||||
# Build Lists out of config-entries
|
# Build Lists out of config-entries
|
||||||
#
|
#
|
||||||
logging.debug("create lists")
|
logging.debug("create lists")
|
||||||
keepAliveRICs = [int(x.strip()) for x in globals.config.get("AlarmMonitor","keepAliveRICs").replace(";", ",").split(",")]
|
keepAliveRICs = [int(x.strip()) for x in globalData.config.get("AlarmMonitor","keepAliveRICs").replace(";", ",").split(",")]
|
||||||
logging.debug("-- keepAliveRICs: %s", keepAliveRICs)
|
logging.debug("-- keepAliveRICs: %s", keepAliveRICs)
|
||||||
alarmRICs = [int(x.strip()) for x in globals.config.get("AlarmMonitor","alarmRICs").replace(";", ",").split(",")]
|
alarmRICs = [int(x.strip()) for x in globalData.config.get("AlarmMonitor","alarmRICs").replace(";", ",").split(",")]
|
||||||
logging.debug("-- alarmRICs: %s", alarmRICs)
|
logging.debug("-- alarmRICs: %s", alarmRICs)
|
||||||
functionCharTestAlarm = [str(x.strip()) for x in globals.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
|
functionCharTestAlarm = [str(x.strip()) for x in globalData.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
|
||||||
logging.debug("-- functionCharTestAlarm: %s", functionCharTestAlarm)
|
logging.debug("-- functionCharTestAlarm: %s", functionCharTestAlarm)
|
||||||
functionCharAlarm = [str(x.strip()) for x in globals.config.get("AlarmMonitor","functionCharAlarm").replace(";", ",").split(",")]
|
functionCharAlarm = [str(x.strip()) for x in globalData.config.get("AlarmMonitor","functionCharAlarm").replace(";", ",").split(",")]
|
||||||
logging.debug("-- functionCharAlarm: %s", functionCharAlarm)
|
logging.debug("-- functionCharAlarm: %s", functionCharAlarm)
|
||||||
|
|
||||||
#
|
#
|
||||||
# try to read History from MySQL-DB
|
# try to read History from MySQL-DB
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
if globals.config.getboolean("AlarmMonitor","loadHistory") == True:
|
if globalData.config.getboolean("AlarmMonitor","loadHistory") == True:
|
||||||
import mysql.connector
|
import mysql.connector
|
||||||
|
|
||||||
for key,val in globals.config.items("MySQL"):
|
for key,val in globalData.config.items("MySQL"):
|
||||||
logging.debug("-- %s = %s", key, val)
|
logging.debug("-- %s = %s", key, val)
|
||||||
|
|
||||||
# Connect to DB
|
# Connect to DB
|
||||||
logging.debug("connect to MySQL")
|
logging.debug("connect to MySQL")
|
||||||
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"), charset='utf8')
|
connection = mysql.connector.connect(host = globalData.config.get("MySQL","dbserver"), user = globalData.config.get("MySQL","dbuser"), passwd = globalData.config.get("MySQL","dbpassword"), db = globalData.config.get("MySQL","database"), charset='utf8')
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
logging.debug("MySQL connected")
|
logging.debug("MySQL connected")
|
||||||
|
|
||||||
# read countKeepAlive
|
# read countKeepAlive
|
||||||
# precondition: keepAliveRICs set
|
# precondition: keepAliveRICs set
|
||||||
if (len(keepAliveRICs) > 0):
|
if (len(keepAliveRICs) > 0):
|
||||||
sql = "SELECT COUNT(*) FROM "+globals.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globals.config.get("AlarmMonitor","keepAliveRICs")+")"
|
sql = "SELECT COUNT(*) FROM "+globalData.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globalData.config.get("AlarmMonitor","keepAliveRICs")+")"
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
result = int(cursor.fetchone()[0])
|
result = int(cursor.fetchone()[0])
|
||||||
if result > 0:
|
if result > 0:
|
||||||
globals.countKeepAlive = result
|
globalData.countKeepAlive = result
|
||||||
logging.debug("-- countKeepAlive: %s", globals.countKeepAlive)
|
logging.debug("-- countKeepAlive: %s", globalData.countKeepAlive)
|
||||||
|
|
||||||
# read countAlarm
|
# read countAlarm
|
||||||
# precondition: alarmRics and functionChar set
|
# precondition: alarmRics and functionChar set
|
||||||
if (len(alarmRICs) > 0) and (len(functionCharAlarm) > 0):
|
if (len(alarmRICs) > 0) and (len(functionCharAlarm) > 0):
|
||||||
sql = "SELECT COUNT(*) FROM "+globals.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globals.config.get("AlarmMonitor","alarmRICs")+")"
|
sql = "SELECT COUNT(*) FROM "+globalData.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globalData.config.get("AlarmMonitor","alarmRICs")+")"
|
||||||
if len(functionCharAlarm) == 1:
|
if len(functionCharAlarm) == 1:
|
||||||
sql += " AND functionChar IN ('" + functionCharAlarm[0] + "')"
|
sql += " AND functionChar IN ('" + functionCharAlarm[0] + "')"
|
||||||
elif len(functionCharAlarm) > 1:
|
elif len(functionCharAlarm) > 1:
|
||||||
|
|
@ -178,13 +178,13 @@ try:
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
result = int(cursor.fetchone()[0])
|
result = int(cursor.fetchone()[0])
|
||||||
if result > 0:
|
if result > 0:
|
||||||
globals.countAlarm = result
|
globalData.countAlarm = result
|
||||||
logging.debug("-- countAlarm: %s", globals.countAlarm)
|
logging.debug("-- countAlarm: %s", globalData.countAlarm)
|
||||||
|
|
||||||
# read countTestAlarm
|
# read countTestAlarm
|
||||||
# precondition: alarmRics and functionCharTestAlarm set
|
# precondition: alarmRics and functionCharTestAlarm set
|
||||||
if (len(alarmRICs) > 0) and (len(functionCharTestAlarm) > 0):
|
if (len(alarmRICs) > 0) and (len(functionCharTestAlarm) > 0):
|
||||||
sql = "SELECT COUNT(*) FROM "+globals.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globals.config.get("AlarmMonitor","alarmRICs")+")"
|
sql = "SELECT COUNT(*) FROM "+globalData.config.get("MySQL","tablePOC")+" WHERE ric IN ("+globalData.config.get("AlarmMonitor","alarmRICs")+")"
|
||||||
if len(functionCharTestAlarm) == 1:
|
if len(functionCharTestAlarm) == 1:
|
||||||
sql += " AND functionChar IN ('" + functionCharTestAlarm[0] + "')"
|
sql += " AND functionChar IN ('" + functionCharTestAlarm[0] + "')"
|
||||||
elif len(functionCharTestAlarm) > 1:
|
elif len(functionCharTestAlarm) > 1:
|
||||||
|
|
@ -192,14 +192,14 @@ try:
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
result = int(cursor.fetchone()[0])
|
result = int(cursor.fetchone()[0])
|
||||||
if result > 0:
|
if result > 0:
|
||||||
globals.countTestAlarm = result
|
globalData.countTestAlarm = result
|
||||||
logging.debug("-- countTestAlarm: %s", globals.countTestAlarm)
|
logging.debug("-- countTestAlarm: %s", globalData.countTestAlarm)
|
||||||
|
|
||||||
# read the last 5 events in reverse order
|
# read the last 5 events in reverse order
|
||||||
# precondition: alarmRics and (functionChar or functionCharTestAlarm) set
|
# precondition: alarmRics and (functionChar or functionCharTestAlarm) set
|
||||||
if (len(alarmRICs) > 0) and ((len(functionCharAlarm) > 0) or (len(functionCharTestAlarm) > 0)):
|
if (len(alarmRICs) > 0) and ((len(functionCharAlarm) > 0) or (len(functionCharTestAlarm) > 0)):
|
||||||
sql = "SELECT UNIX_TIMESTAMP(time), ric, functionChar, msg, description FROM "+globals.config.get("MySQL","tablePOC")
|
sql = "SELECT UNIX_TIMESTAMP(time), ric, functionChar, msg, description FROM "+globalData.config.get("MySQL","tablePOC")
|
||||||
sql += " WHERE ric IN ("+globals.config.get("AlarmMonitor","alarmRICs")+")"
|
sql += " WHERE ric IN ("+globalData.config.get("AlarmMonitor","alarmRICs")+")"
|
||||||
functionChar = functionCharAlarm + functionCharTestAlarm
|
functionChar = functionCharAlarm + functionCharTestAlarm
|
||||||
if len(functionChar) == 1:
|
if len(functionChar) == 1:
|
||||||
sql += " AND functionChar IN ('" + functionChar[0] + "')"
|
sql += " AND functionChar IN ('" + functionChar[0] + "')"
|
||||||
|
|
@ -215,8 +215,8 @@ try:
|
||||||
data['functionChar'] = functionChar
|
data['functionChar'] = functionChar
|
||||||
data['msg'] = msg
|
data['msg'] = msg
|
||||||
data['description'] = description
|
data['description'] = description
|
||||||
globals.alarmHistory.append(data)
|
globalData.alarmHistory.append(data)
|
||||||
logging.debug("-- history data loaded: %s", len(globals.alarmHistory))
|
logging.debug("-- history data loaded: %s", len(globalData.alarmHistory))
|
||||||
|
|
||||||
logging.info("history loaded from database")
|
logging.info("history loaded from database")
|
||||||
# if db is enabled
|
# if db is enabled
|
||||||
|
|
@ -239,10 +239,10 @@ try:
|
||||||
#
|
#
|
||||||
alarmSound = False
|
alarmSound = False
|
||||||
try:
|
try:
|
||||||
if globals.config.getboolean("AlarmMonitor","playSound") == True:
|
if globalData.config.getboolean("AlarmMonitor","playSound") == True:
|
||||||
if not globals.config.get("AlarmMonitor","soundFile") == "":
|
if not globalData.config.get("AlarmMonitor","soundFile") == "":
|
||||||
pygame.mixer.init()
|
pygame.mixer.init()
|
||||||
alarmSound = pygame.mixer.Sound(globals.config.get("AlarmMonitor","soundFile"))
|
alarmSound = pygame.mixer.Sound(globalData.config.get("AlarmMonitor","soundFile"))
|
||||||
logging.info("alarm with sound")
|
logging.info("alarm with sound")
|
||||||
except:
|
except:
|
||||||
# error, but we could work without sound
|
# error, but we could work without sound
|
||||||
|
|
@ -250,14 +250,14 @@ try:
|
||||||
logging.debug("cannot initialise alarm sound", exc_info=True)
|
logging.debug("cannot initialise alarm sound", exc_info=True)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
globals.startTime = int(time.time())
|
globalData.startTime = int(time.time())
|
||||||
logging.info("alarmMonitor started - on standby")
|
logging.info("alarmMonitor started - on standby")
|
||||||
|
|
||||||
#
|
#
|
||||||
# Main Program
|
# Main Program
|
||||||
# (Threads will set abort to True if an error occurs)
|
# (Threads will set abort to True if an error occurs)
|
||||||
#
|
#
|
||||||
while globals.abort == False:
|
while globalData.abort == False:
|
||||||
# accept connections from outside
|
# accept connections from outside
|
||||||
(clientsocket, address) = sock.accept()
|
(clientsocket, address) = sock.accept()
|
||||||
logging.debug("connected client: %s", address)
|
logging.debug("connected client: %s", address)
|
||||||
|
|
@ -284,35 +284,35 @@ try:
|
||||||
# keep alive calculation with additional RICs
|
# keep alive calculation with additional RICs
|
||||||
if int(parsed_json['ric']) in keepAliveRICs:
|
if int(parsed_json['ric']) in keepAliveRICs:
|
||||||
logging.info("POCSAG is alive")
|
logging.info("POCSAG is alive")
|
||||||
globals.lastAlarm = curtime
|
globalData.lastAlarm = curtime
|
||||||
globals.countKeepAlive += 1
|
globalData.countKeepAlive += 1
|
||||||
|
|
||||||
# (test) alarm processing
|
# (test) alarm processing
|
||||||
elif int(parsed_json['ric']) in alarmRICs:
|
elif int(parsed_json['ric']) in alarmRICs:
|
||||||
if parsed_json['functionChar'] in functionCharTestAlarm:
|
if parsed_json['functionChar'] in functionCharTestAlarm:
|
||||||
logging.info("--> Probealarm: %s", parsed_json['ric'])
|
logging.info("--> Probealarm: %s", parsed_json['ric'])
|
||||||
globals.screenBackground = pygame.Color(globals.config.get("AlarmMonitor","colourYellow"))
|
globalData.screenBackground = pygame.Color(globalData.config.get("AlarmMonitor","colourYellow"))
|
||||||
globals.countTestAlarm += 1
|
globalData.countTestAlarm += 1
|
||||||
elif parsed_json['functionChar'] in functionCharAlarm:
|
elif parsed_json['functionChar'] in functionCharAlarm:
|
||||||
logging.info("--> Alarm: %s", parsed_json['ric'])
|
logging.info("--> Alarm: %s", parsed_json['ric'])
|
||||||
globals.screenBackground = pygame.Color(globals.config.get("AlarmMonitor","colourRed"))
|
globalData.screenBackground = pygame.Color(globalData.config.get("AlarmMonitor","colourRed"))
|
||||||
globals.countAlarm += 1
|
globalData.countAlarm += 1
|
||||||
|
|
||||||
# forward data to alarmMonitor
|
# forward data to alarmMonitor
|
||||||
globals.data = parsed_json
|
globalData.data = parsed_json
|
||||||
globals.data['timestamp'] = curtime
|
globalData.data['timestamp'] = curtime
|
||||||
logging.debug("-- data: %s", parsed_json)
|
logging.debug("-- data: %s", parsed_json)
|
||||||
# save 5 alarm history entries
|
# save 5 alarm history entries
|
||||||
globals.alarmHistory.append(globals.data)
|
globalData.alarmHistory.append(globalData.data)
|
||||||
if len(globals.alarmHistory) > 5:
|
if len(globalData.alarmHistory) > 5:
|
||||||
globals.alarmHistory.pop(0)
|
globalData.alarmHistory.pop(0)
|
||||||
# update lastAlarm for keep alive calculation
|
# update lastAlarm for keep alive calculation
|
||||||
globals.lastAlarm = curtime
|
globalData.lastAlarm = curtime
|
||||||
# enable display for n seconds:
|
# enable display for n seconds:
|
||||||
globals.enableDisplayUntil = curtime + globals.config.getint("AlarmMonitor","showAlarmTime")
|
globalData.enableDisplayUntil = curtime + globalData.config.getint("AlarmMonitor","showAlarmTime")
|
||||||
# tell alarm-thread to turn on the display
|
# tell alarm-thread to turn on the display
|
||||||
globals.navigation = "alarmPage"
|
globalData.navigation = "alarmPage"
|
||||||
globals.showDisplay = True;
|
globalData.showDisplay = True;
|
||||||
|
|
||||||
# play alarmSound...
|
# play alarmSound...
|
||||||
if not alarmSound == False:
|
if not alarmSound == False:
|
||||||
|
|
@ -337,7 +337,7 @@ except:
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
logging.info("socketServer shuting down")
|
logging.info("socketServer shuting down")
|
||||||
globals.running = False
|
globalData.running = False
|
||||||
sock.close()
|
sock.close()
|
||||||
logging.debug("socket closed")
|
logging.debug("socket closed")
|
||||||
if not alarmSound == False:
|
if not alarmSound == False:
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,11 @@ def autoTurnOffDisplay():
|
||||||
"""
|
"""
|
||||||
Asynchronous function to turn of the display backlight
|
Asynchronous function to turn of the display backlight
|
||||||
|
|
||||||
@requires: globals.showDisplay - status of backlight
|
@requires: globalData.showDisplay - status of backlight
|
||||||
@requires: globals.enableDisplayUntil - given timestamp to turn off backlight
|
@requires: globalData.enableDisplayUntil - given timestamp to turn off backlight
|
||||||
@requires: globals.running - service runs as long as this is True
|
@requires: globalData.running - service runs as long as this is True
|
||||||
|
|
||||||
In case of an exception the function set globals.abort to True.
|
In case of an exception the function set globalData.abort to True.
|
||||||
This will terminate the main program.
|
This will terminate the main program.
|
||||||
|
|
||||||
@return: nothing
|
@return: nothing
|
||||||
|
|
@ -37,11 +37,11 @@ def autoTurnOffDisplay():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Running will be set to False if main program is shutting down
|
# Running will be set to False if main program is shutting down
|
||||||
while globals.running == True:
|
while globalData.running == True:
|
||||||
# check if timestamp is in the past
|
# check if timestamp is in the past
|
||||||
if (globals.showDisplay == True) and (globals.enableDisplayUntil < int(time.time())):
|
if (globalData.showDisplay == True) and (globalData.enableDisplayUntil < int(time.time())):
|
||||||
globals.showDisplay = False
|
globalData.showDisplay = False
|
||||||
globals.navigation = "alarmPage"
|
globalData.navigation = "alarmPage"
|
||||||
logging.info("display turned off")
|
logging.info("display turned off")
|
||||||
# we will do this only one time per second
|
# we will do this only one time per second
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
@ -49,7 +49,7 @@ def autoTurnOffDisplay():
|
||||||
logging.error("unknown error in autoTurnOffDisplay-thread")
|
logging.error("unknown error in autoTurnOffDisplay-thread")
|
||||||
logging.debug("unknown error in autoTurnOffDisplay-thread", exc_info=True)
|
logging.debug("unknown error in autoTurnOffDisplay-thread", exc_info=True)
|
||||||
# abort main program
|
# abort main program
|
||||||
globals.abort = True
|
globalData.abort = True
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
logging.debug("exit autoTurnOffDisplay-thread")
|
logging.debug("exit autoTurnOffDisplay-thread")
|
||||||
|
|
@ -65,12 +65,12 @@ def eventHandler():
|
||||||
Asynchronous function to handle pygames events
|
Asynchronous function to handle pygames events
|
||||||
in particular the touchscreen events
|
in particular the touchscreen events
|
||||||
|
|
||||||
@requires: globals.showDisplay - status of backlight
|
@requires: globalData.showDisplay - status of backlight
|
||||||
@requires: globals.enableDisplayUntil - timestamp to turn off backlight
|
@requires: globalData.enableDisplayUntil - timestamp to turn off backlight
|
||||||
@requires: globals.running - service runs as long as this is True
|
@requires: globalData.running - service runs as long as this is True
|
||||||
@requires: configuration has to be set in the config.ini
|
@requires: configuration has to be set in the config.ini
|
||||||
|
|
||||||
In case of an exception the function set globals.abort to True.
|
In case of an exception the function set globalData.abort to True.
|
||||||
This will terminate the main program.
|
This will terminate the main program.
|
||||||
|
|
||||||
@return: nothing
|
@return: nothing
|
||||||
|
|
@ -89,7 +89,7 @@ def eventHandler():
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
# Running will be set to False if main program is shutting down
|
# Running will be set to False if main program is shutting down
|
||||||
while globals.running == True:
|
while globalData.running == True:
|
||||||
# This limits the while loop to a max of 2 times per second.
|
# This limits the while loop to a max of 2 times per second.
|
||||||
# Leave this out and we will use all CPU we can.
|
# Leave this out and we will use all CPU we can.
|
||||||
clock.tick(2)
|
clock.tick(2)
|
||||||
|
|
@ -100,7 +100,7 @@ def eventHandler():
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
# event-handler for QUIT
|
# event-handler for QUIT
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
globals.running = False
|
globalData.running = False
|
||||||
|
|
||||||
# if touchscreen pressed
|
# if touchscreen pressed
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
|
@ -111,29 +111,29 @@ def eventHandler():
|
||||||
pygame.mixer.stop()
|
pygame.mixer.stop()
|
||||||
|
|
||||||
# touching the dark display will turn it on for n sec
|
# touching the dark display will turn it on for n sec
|
||||||
if globals.showDisplay == False:
|
if globalData.showDisplay == False:
|
||||||
logging.info("turn ON display")
|
logging.info("turn ON display")
|
||||||
globals.enableDisplayUntil = curtime + globals.config.getint("AlarmMonitor","showDisplayTime")
|
globalData.enableDisplayUntil = curtime + globalData.config.getint("AlarmMonitor","showDisplayTime")
|
||||||
globals.navigation == "alarmPage"
|
globalData.navigation == "alarmPage"
|
||||||
globals.showDisplay = True
|
globalData.showDisplay = True
|
||||||
else:
|
else:
|
||||||
# touching the enabled display will be content sensitive...
|
# touching the enabled display will be content sensitive...
|
||||||
# if top 2/3: turn of display
|
# if top 2/3: turn of display
|
||||||
yBoundary = globals.config.getint("Display","displayHeight") - 80
|
yBoundary = globalData.config.getint("Display","displayHeight") - 80
|
||||||
if 0 <= posY <= yBoundary:
|
if 0 <= posY <= yBoundary:
|
||||||
logging.info("turn OFF display")
|
logging.info("turn OFF display")
|
||||||
globals.showDisplay = False
|
globalData.showDisplay = False
|
||||||
globals.navigation = "alarmPage"
|
globalData.navigation = "alarmPage"
|
||||||
else:
|
else:
|
||||||
# we are in the navigation area
|
# we are in the navigation area
|
||||||
globals.enableDisplayUntil = curtime + globals.config.getint("AlarmMonitor","showDisplayTime")
|
globalData.enableDisplayUntil = curtime + globalData.config.getint("AlarmMonitor","showDisplayTime")
|
||||||
if 0 <= posX <= 110:
|
if 0 <= posX <= 110:
|
||||||
globals.navigation = "historyPage"
|
globalData.navigation = "historyPage"
|
||||||
elif 111 <= posX <= 210:
|
elif 111 <= posX <= 210:
|
||||||
globals.navigation = "statusPage"
|
globalData.navigation = "statusPage"
|
||||||
else:
|
else:
|
||||||
globals.screenBackground = pygame.Color(globals.config.get("AlarmMonitor","colourGreen"))
|
globalData.screenBackground = pygame.Color(globalData.config.get("AlarmMonitor","colourGreen"))
|
||||||
globals.navigation = "alarmPage"
|
globalData.navigation = "alarmPage"
|
||||||
## end if showDisplay
|
## end if showDisplay
|
||||||
## end if event MOUSEBUTTONDOWN
|
## end if event MOUSEBUTTONDOWN
|
||||||
## end for event
|
## end for event
|
||||||
|
|
@ -141,7 +141,7 @@ def eventHandler():
|
||||||
logging.error("unknown error in eventHandler-thread")
|
logging.error("unknown error in eventHandler-thread")
|
||||||
logging.debug("unknown error in eventHandler-thread", exc_info=True)
|
logging.debug("unknown error in eventHandler-thread", exc_info=True)
|
||||||
# abort main program
|
# abort main program
|
||||||
globals.abort = True
|
globalData.abort = True
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
logging.debug("exit eventHandler-thread")
|
logging.debug("exit eventHandler-thread")
|
||||||
|
|
@ -156,14 +156,14 @@ def displayPainter():
|
||||||
"""
|
"""
|
||||||
Asynchronous function to build the display content
|
Asynchronous function to build the display content
|
||||||
|
|
||||||
@requires: globals.showDisplay - status of backlight
|
@requires: globalData.showDisplay - status of backlight
|
||||||
@requires: globals.enableDisplayUntil - given timestamp when backlight will turned off
|
@requires: globalData.enableDisplayUntil - given timestamp when backlight will turned off
|
||||||
@requires: globals.running - service runs as long as this is True
|
@requires: globalData.running - service runs as long as this is True
|
||||||
@requires: globals.data - data of the last alarm
|
@requires: globalData.data - data of the last alarm
|
||||||
@requires: globals.lastAlarm - timestamp of the last processing (see alarmRICs and keepAliveRICs)
|
@requires: globalData.lastAlarm - timestamp of the last processing (see alarmRICs and keepAliveRICs)
|
||||||
@requires: configuration has to be set in the config.ini
|
@requires: configuration has to be set in the config.ini
|
||||||
|
|
||||||
In case of an exception the function set globals.abort to True.
|
In case of an exception the function set globalData.abort to True.
|
||||||
This will terminate the main program.
|
This will terminate the main program.
|
||||||
|
|
||||||
@return: nothing
|
@return: nothing
|
||||||
|
|
@ -187,12 +187,12 @@ def displayPainter():
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
# set up GPIO pin for output
|
# set up GPIO pin for output
|
||||||
GPIO.setup(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.OUT)
|
GPIO.setup(globalData.config.getint("Display","GPIOPinForBacklight"), GPIO.OUT)
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
#screen size
|
#screen size
|
||||||
size = (globals.config.getint("Display","displayWidth"), globals.config.getint("Display","displayHeight"))
|
size = (globalData.config.getint("Display","displayWidth"), globalData.config.getint("Display","displayHeight"))
|
||||||
screen = pygame.display.set_mode(size)
|
screen = pygame.display.set_mode(size)
|
||||||
|
|
||||||
# disable mouse cursor
|
# disable mouse cursor
|
||||||
|
|
@ -219,12 +219,12 @@ def displayPainter():
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
# Build Lists out of config-entries
|
# Build Lists out of config-entries
|
||||||
functionCharTestAlarm = [x.strip() for x in globals.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
|
functionCharTestAlarm = [x.strip() for x in globalData.config.get("AlarmMonitor","functionCharTestAlarm").replace(";", ",").split(",")]
|
||||||
|
|
||||||
logging.debug("displayPainter-thread started")
|
logging.debug("displayPainter-thread started")
|
||||||
|
|
||||||
# Running will be set to False if main program is shutting down
|
# Running will be set to False if main program is shutting down
|
||||||
while globals.running == True:
|
while globalData.running == True:
|
||||||
# This limits the while loop to a max of 2 times per second.
|
# This limits the while loop to a max of 2 times per second.
|
||||||
# Leave this out and we will use all CPU we can.
|
# Leave this out and we will use all CPU we can.
|
||||||
clock.tick(2)
|
clock.tick(2)
|
||||||
|
|
@ -232,48 +232,48 @@ def displayPainter():
|
||||||
# current time for this loop:
|
# current time for this loop:
|
||||||
curtime = int(time.time())
|
curtime = int(time.time())
|
||||||
|
|
||||||
if globals.showDisplay == True:
|
if globalData.showDisplay == True:
|
||||||
# Enable LCD display
|
# Enable LCD display
|
||||||
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.HIGH)
|
GPIO.output(globalData.config.getint("Display","GPIOPinForBacklight"), GPIO.HIGH)
|
||||||
# Clear the screen and set the screen background
|
# Clear the screen and set the screen background
|
||||||
screen.fill(globals.screenBackground)
|
screen.fill(globalData.screenBackground)
|
||||||
# paint black rect, so Background looks like a boarder
|
# paint black rect, so Background looks like a boarder
|
||||||
widthX = globals.config.getint("Display","displayWidth") - 20
|
widthX = globalData.config.getint("Display","displayWidth") - 20
|
||||||
widthY = globals.config.getint("Display","displayHeight") - 20
|
widthY = globalData.config.getint("Display","displayHeight") - 20
|
||||||
pygame.draw.rect(screen, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")), (10, 10, widthX, widthY))
|
pygame.draw.rect(screen, pygame.Color(globalData.config.get("AlarmMonitor","colourBlack")), (10, 10, widthX, widthY))
|
||||||
# header
|
# header
|
||||||
header = fontHeader.render("Alarm-Monitor", 1, pygame.Color(globals.config.get("AlarmMonitor","colourRed")))
|
header = fontHeader.render("Alarm-Monitor", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourRed")))
|
||||||
(width, height) = fontHeader.size("Alarm-Monitor")
|
(width, height) = fontHeader.size("Alarm-Monitor")
|
||||||
x = (int(globals.config.getint("Display","displayWidth")) - width)/2
|
x = (int(globalData.config.getint("Display","displayWidth")) - width)/2
|
||||||
screen.blit(header, (x, 20))
|
screen.blit(header, (x, 20))
|
||||||
|
|
||||||
# show time of last alarm
|
# show time of last alarm
|
||||||
if globals.lastAlarm > 0:
|
if globalData.lastAlarm > 0:
|
||||||
try:
|
try:
|
||||||
# format last alarm
|
# format last alarm
|
||||||
lastAlarmString = time.strftime("%H:%M:%S", time.localtime(globals.lastAlarm))
|
lastAlarmString = time.strftime("%H:%M:%S", time.localtime(globalData.lastAlarm))
|
||||||
# Color time:
|
# Color time:
|
||||||
# red: lastAlarm more than n (delayForRed) seconds past
|
# red: lastAlarm more than n (delayForRed) seconds past
|
||||||
if (int(globals.lastAlarm) + globals.config.getint("AlarmMonitor","delayForRed")) < curtime:
|
if (int(globalData.lastAlarm) + globalData.config.getint("AlarmMonitor","delayForRed")) < curtime:
|
||||||
timeColour = pygame.Color(globals.config.get("AlarmMonitor","colourRed"))
|
timeColour = pygame.Color(globalData.config.get("AlarmMonitor","colourRed"))
|
||||||
# yellow: lastAlarm more than n (delayForYellow) seconds past
|
# yellow: lastAlarm more than n (delayForYellow) seconds past
|
||||||
elif (int(globals.lastAlarm) + globals.config.getint("AlarmMonitor","delayForYellow")) < curtime:
|
elif (int(globalData.lastAlarm) + globalData.config.getint("AlarmMonitor","delayForYellow")) < curtime:
|
||||||
timeColour = pygame.Color(globals.config.get("AlarmMonitor","colourYellow"))
|
timeColour = pygame.Color(globalData.config.get("AlarmMonitor","colourYellow"))
|
||||||
# dgrey: normal
|
# dgrey: normal
|
||||||
else:
|
else:
|
||||||
timeColour = pygame.Color(globals.config.get("AlarmMonitor","colourGreen"))
|
timeColour = pygame.Color(globalData.config.get("AlarmMonitor","colourGreen"))
|
||||||
lastAlarm = fontTime.render(lastAlarmString, 1, timeColour)
|
lastAlarm = fontTime.render(lastAlarmString, 1, timeColour)
|
||||||
(width, height) = fontTime.size(lastAlarmString)
|
(width, height) = fontTime.size(lastAlarmString)
|
||||||
x = globals.config.getint("Display","displayWidth") - 20 - width
|
x = globalData.config.getint("Display","displayWidth") - 20 - width
|
||||||
screen.blit(lastAlarm, (x, 20))
|
screen.blit(lastAlarm, (x, 20))
|
||||||
except:
|
except:
|
||||||
logging.debug("unknown error in lastAlarm", exc_info=True)
|
logging.debug("unknown error in lastAlarm", exc_info=True)
|
||||||
pass
|
pass
|
||||||
## end if globals.lastAlarm > 0
|
## end if globalData.lastAlarm > 0
|
||||||
|
|
||||||
# show remaining time before display will be turned off:
|
# show remaining time before display will be turned off:
|
||||||
restZeit = globals.enableDisplayUntil - curtime +1
|
restZeit = globalData.enableDisplayUntil - curtime +1
|
||||||
zeit = fontTime.render(str(restZeit), 1, pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")))
|
zeit = fontTime.render(str(restZeit), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")))
|
||||||
screen.blit(zeit, (20, 20))
|
screen.blit(zeit, (20, 20))
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -281,10 +281,10 @@ def displayPainter():
|
||||||
# default is "alarmPage"
|
# default is "alarmPage"
|
||||||
#
|
#
|
||||||
# Startpoint for content
|
# Startpoint for content
|
||||||
if globals.navigation == "historyPage":
|
if globalData.navigation == "historyPage":
|
||||||
try:
|
try:
|
||||||
y = 50
|
y = 50
|
||||||
for data in reversed(globals.alarmHistory):
|
for data in reversed(globalData.alarmHistory):
|
||||||
# Layout:
|
# Layout:
|
||||||
# Date Description
|
# Date Description
|
||||||
# Time Msg
|
# Time Msg
|
||||||
|
|
@ -300,9 +300,9 @@ def displayPainter():
|
||||||
|
|
||||||
# get colour
|
# get colour
|
||||||
if data['functionChar'] in functionCharTestAlarm:
|
if data['functionChar'] in functionCharTestAlarm:
|
||||||
colour = globals.config.get("AlarmMonitor","colourYellow")
|
colour = globalData.config.get("AlarmMonitor","colourYellow")
|
||||||
else:
|
else:
|
||||||
colour = globals.config.get("AlarmMonitor","colourRed")
|
colour = globalData.config.get("AlarmMonitor","colourRed")
|
||||||
|
|
||||||
# Paint Date/Time
|
# Paint Date/Time
|
||||||
screen.blit(fontHistory.render(dateString, 1, pygame.Color(colour)), (20, y))
|
screen.blit(fontHistory.render(dateString, 1, pygame.Color(colour)), (20, y))
|
||||||
|
|
@ -310,9 +310,9 @@ def displayPainter():
|
||||||
|
|
||||||
# Paint Description
|
# Paint Description
|
||||||
try:
|
try:
|
||||||
textLines = wrapline(data['description'], fontHistory, (globals.config.getint("Display","displayWidth") - shifting - 40))
|
textLines = wrapline(data['description'], fontHistory, (globalData.config.getint("Display","displayWidth") - shifting - 40))
|
||||||
for index, item in enumerate(textLines):
|
for index, item in enumerate(textLines):
|
||||||
textZeile = fontHistory.render(item, 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
textZeile = fontHistory.render(item, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||||
screen.blit(textZeile, (20 + shifting, y))
|
screen.blit(textZeile, (20 + shifting, y))
|
||||||
y += height
|
y += height
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
@ -320,9 +320,9 @@ def displayPainter():
|
||||||
|
|
||||||
# Paint Msg
|
# Paint Msg
|
||||||
try:
|
try:
|
||||||
textLines = wrapline(data['msg'].replace("*", " * "), fontHistory, (globals.config.getint("Display","displayWidth") - shifting - 40))
|
textLines = wrapline(data['msg'].replace("*", " * "), fontHistory, (globalData.config.getint("Display","displayWidth") - shifting - 40))
|
||||||
for index, item in enumerate(textLines):
|
for index, item in enumerate(textLines):
|
||||||
textZeile = fontHistory.render(item, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
textZeile = fontHistory.render(item, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
screen.blit(textZeile, (20 + shifting, y))
|
screen.blit(textZeile, (20 + shifting, y))
|
||||||
y += height
|
y += height
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
@ -331,65 +331,65 @@ def displayPainter():
|
||||||
# line spacing for next dataset
|
# line spacing for next dataset
|
||||||
y += 2
|
y += 2
|
||||||
|
|
||||||
## end for globals.alarmHistory
|
## end for globalData.alarmHistory
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
## end if globals.navigation == "historyPage"
|
## end if globalData.navigation == "historyPage"
|
||||||
|
|
||||||
elif globals.navigation == "statusPage":
|
elif globalData.navigation == "statusPage":
|
||||||
(width, height) = fontStatusContent.size("Anzahl Test-Alarme:")
|
(width, height) = fontStatusContent.size("Anzahl Test-Alarme:")
|
||||||
y = 70
|
y = 70
|
||||||
x = width + 10
|
x = width + 10
|
||||||
# Running since:
|
# Running since:
|
||||||
title = fontStatusContent.render("Gestartet:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
title = fontStatusContent.render("Gestartet:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||||
content = fontStatusContent.render(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globals.startTime)), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
content = fontStatusContent.render(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globalData.startTime)), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
screen.blit(title, (20, y))
|
screen.blit(title, (20, y))
|
||||||
screen.blit(content, (20 +x, y))
|
screen.blit(content, (20 +x, y))
|
||||||
y += height + 10
|
y += height + 10
|
||||||
|
|
||||||
# Last Alarm
|
# Last Alarm
|
||||||
title = fontStatusContent.render("Letzte Nachricht:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
title = fontStatusContent.render("Letzte Nachricht:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||||
if globals.lastAlarm > 0:
|
if globalData.lastAlarm > 0:
|
||||||
content = fontStatusContent.render(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globals.lastAlarm)), 1, timeColour)
|
content = fontStatusContent.render(time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globalData.lastAlarm)), 1, timeColour)
|
||||||
else:
|
else:
|
||||||
content = fontStatusContent.render("-", 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
content = fontStatusContent.render("-", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
screen.blit(title, (20, y))
|
screen.blit(title, (20, y))
|
||||||
screen.blit(content, (20 +x, y))
|
screen.blit(content, (20 +x, y))
|
||||||
y += height + 10
|
y += height + 10
|
||||||
|
|
||||||
# Number of Alarms
|
# Number of Alarms
|
||||||
title = fontStatusContent.render("Anzahl Alarme:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
title = fontStatusContent.render("Anzahl Alarme:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||||
content = fontStatusContent.render(str(globals.countAlarm), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
content = fontStatusContent.render(str(globalData.countAlarm), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
screen.blit(title, (20, y))
|
screen.blit(title, (20, y))
|
||||||
screen.blit(content, (20 +x, y))
|
screen.blit(content, (20 +x, y))
|
||||||
y += height + 10
|
y += height + 10
|
||||||
|
|
||||||
# Number of TestAlarms
|
# Number of TestAlarms
|
||||||
title = fontStatusContent.render("Anzahl Test-Alarme:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
title = fontStatusContent.render("Anzahl Test-Alarme:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||||
content = fontStatusContent.render(str(globals.countTestAlarm), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
content = fontStatusContent.render(str(globalData.countTestAlarm), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
screen.blit(title, (20, y))
|
screen.blit(title, (20, y))
|
||||||
screen.blit(content, (20 +x, y))
|
screen.blit(content, (20 +x, y))
|
||||||
y += height + 10
|
y += height + 10
|
||||||
|
|
||||||
# Number of DAU-Msgs
|
# Number of DAU-Msgs
|
||||||
title = fontStatusContent.render("Anzahl DAU-Tests:", 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
title = fontStatusContent.render("Anzahl DAU-Tests:", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||||
content = fontStatusContent.render(str(globals.countKeepAlive), 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
content = fontStatusContent.render(str(globalData.countKeepAlive), 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
screen.blit(title, (20, y))
|
screen.blit(title, (20, y))
|
||||||
screen.blit(content, (20 +x, y))
|
screen.blit(content, (20 +x, y))
|
||||||
y += height + 10
|
y += height + 10
|
||||||
|
|
||||||
## end if globals.navigation == "statusPage"
|
## end if globalData.navigation == "statusPage"
|
||||||
|
|
||||||
else:
|
else:
|
||||||
y = 50
|
y = 50
|
||||||
|
|
||||||
# Paint Date/Time
|
# Paint Date/Time
|
||||||
try:
|
try:
|
||||||
dateTimeString = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globals.data['timestamp']))
|
dateTimeString = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime(globalData.data['timestamp']))
|
||||||
dateTimeRow = fontStatus.render(dateTimeString, 1, pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")))
|
dateTimeRow = fontStatus.render(dateTimeString, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")))
|
||||||
(width, height) = fontStatus.size(dateTimeString)
|
(width, height) = fontStatus.size(dateTimeString)
|
||||||
x = (int(globals.config.getint("Display","displayWidth")) - width)/2
|
x = (int(globalData.config.getint("Display","displayWidth")) - width)/2
|
||||||
screen.blit(dateTimeRow, (x, y))
|
screen.blit(dateTimeRow, (x, y))
|
||||||
y += height + 10
|
y += height + 10
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
@ -397,10 +397,10 @@ def displayPainter():
|
||||||
|
|
||||||
# Paint Description
|
# Paint Description
|
||||||
try:
|
try:
|
||||||
textLines = wrapline(globals.data['description'], fontRIC, (globals.config.getint("Display","displayWidth") - 40))
|
textLines = wrapline(globalData.data['description'], fontRIC, (globalData.config.getint("Display","displayWidth") - 40))
|
||||||
(width, height) = fontStatus.size(globals.data['description'])
|
(width, height) = fontStatus.size(globalData.data['description'])
|
||||||
for index, item in enumerate(textLines):
|
for index, item in enumerate(textLines):
|
||||||
textRow = fontRIC.render(item, 1, pygame.Color(globals.config.get("AlarmMonitor","colourWhite")))
|
textRow = fontRIC.render(item, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourWhite")))
|
||||||
screen.blit(textRow, (20, y))
|
screen.blit(textRow, (20, y))
|
||||||
y += height + 5
|
y += height + 5
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
@ -409,10 +409,10 @@ def displayPainter():
|
||||||
# Paint Msg
|
# Paint Msg
|
||||||
try:
|
try:
|
||||||
y += 10
|
y += 10
|
||||||
textLines = wrapline(globals.data['msg'].replace("*", " * "), fontMsg, (globals.config.getint("Display","displayWidth") - 40))
|
textLines = wrapline(globalData.data['msg'].replace("*", " * "), fontMsg, (globalData.config.getint("Display","displayWidth") - 40))
|
||||||
(width, height) = fontStatus.size(globals.data['msg'])
|
(width, height) = fontStatus.size(globalData.data['msg'])
|
||||||
for index, item in enumerate(textLines):
|
for index, item in enumerate(textLines):
|
||||||
textRow = fontMsg.render(item, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
textRow = fontMsg.render(item, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
screen.blit(textRow, (20, y))
|
screen.blit(textRow, (20, y))
|
||||||
y += height
|
y += height
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
@ -422,47 +422,47 @@ def displayPainter():
|
||||||
# paint navigation buttons
|
# paint navigation buttons
|
||||||
buttonWidth = 80
|
buttonWidth = 80
|
||||||
buttonHeight = 25
|
buttonHeight = 25
|
||||||
buttonY = globals.config.getint("Display","displayHeight") - buttonHeight - 2
|
buttonY = globalData.config.getint("Display","displayHeight") - buttonHeight - 2
|
||||||
|
|
||||||
round_rect(screen, ( 20, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
round_rect(screen, ( 20, buttonY, buttonWidth, buttonHeight), pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
buttonText = fontButton.render("Verlauf", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")))
|
buttonText = fontButton.render("Verlauf", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourBlack")))
|
||||||
(width, height) = fontButton.size("Verlauf")
|
(width, height) = fontButton.size("Verlauf")
|
||||||
textX = 20 + (buttonWidth - width)/2
|
textX = 20 + (buttonWidth - width)/2
|
||||||
textY = buttonY + (buttonHeight - height)/2
|
textY = buttonY + (buttonHeight - height)/2
|
||||||
screen.blit(buttonText, (textX, textY))
|
screen.blit(buttonText, (textX, textY))
|
||||||
|
|
||||||
round_rect(screen, (120, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
round_rect(screen, (120, buttonY, buttonWidth, buttonHeight), pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
buttonText = fontButton.render("Status", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")))
|
buttonText = fontButton.render("Status", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourBlack")))
|
||||||
(width, height) = fontButton.size("Status")
|
(width, height) = fontButton.size("Status")
|
||||||
textX = 120 + (buttonWidth - width)/2
|
textX = 120 + (buttonWidth - width)/2
|
||||||
textY = buttonY + (buttonHeight - height)/2
|
textY = buttonY + (buttonHeight - height)/2
|
||||||
screen.blit(buttonText, (textX, textY))
|
screen.blit(buttonText, (textX, textY))
|
||||||
|
|
||||||
round_rect(screen, (220, buttonY, buttonWidth, buttonHeight), pygame.Color(globals.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globals.config.get("AlarmMonitor","colourGrey")))
|
round_rect(screen, (220, buttonY, buttonWidth, buttonHeight), pygame.Color(globalData.config.get("AlarmMonitor","colourDimGrey")), 10, 1, pygame.Color(globalData.config.get("AlarmMonitor","colourGrey")))
|
||||||
buttonText = fontButton.render("Gelesen", 1, pygame.Color(globals.config.get("AlarmMonitor","colourBlack")))
|
buttonText = fontButton.render("Gelesen", 1, pygame.Color(globalData.config.get("AlarmMonitor","colourBlack")))
|
||||||
(width, height) = fontButton.size("Gelesen")
|
(width, height) = fontButton.size("Gelesen")
|
||||||
textX = 220 + (buttonWidth - width)/2
|
textX = 220 + (buttonWidth - width)/2
|
||||||
textY = buttonY + (buttonHeight - height)/2
|
textY = buttonY + (buttonHeight - height)/2
|
||||||
screen.blit(buttonText, (textX, textY))
|
screen.blit(buttonText, (textX, textY))
|
||||||
|
|
||||||
## end if globals.showDisplay == True
|
## end if globalData.showDisplay == True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
|
GPIO.output(globalData.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
|
||||||
|
|
||||||
# Update display...
|
# Update display...
|
||||||
pygame.display.update()
|
pygame.display.update()
|
||||||
## end while globals.running == True
|
## end while globalData.running == True
|
||||||
|
|
||||||
except:
|
except:
|
||||||
logging.error("unknown error in displayPainter-thread")
|
logging.error("unknown error in displayPainter-thread")
|
||||||
logging.debug("unknown error in displayPainter-thread", exc_info=True)
|
logging.debug("unknown error in displayPainter-thread", exc_info=True)
|
||||||
# abort main program
|
# abort main program
|
||||||
globals.abort = True
|
globalData.abort = True
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
finally:
|
finally:
|
||||||
logging.debug("exit displayPainter-thread")
|
logging.debug("exit displayPainter-thread")
|
||||||
GPIO.output(globals.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
|
GPIO.output(globalData.config.getint("Display","GPIOPinForBacklight"), GPIO.LOW)
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ def processAlarmHandler(typ, freq, data):
|
||||||
@return: nothing
|
@return: nothing
|
||||||
@exception: Exception if starting a Thread failed
|
@exception: Exception if starting a Thread failed
|
||||||
"""
|
"""
|
||||||
if globals.config.getboolean("BOSWatch","processAlarmAsync") == True:
|
if globalVars.config.getboolean("BOSWatch","processAlarmAsync") == True:
|
||||||
logging.debug("starting processAlarm async")
|
logging.debug("starting processAlarm async")
|
||||||
try:
|
try:
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
@ -74,9 +74,9 @@ def processAlarm(typ, freq, data):
|
||||||
# timestamp, to make sure, that all plugins use the same time
|
# timestamp, to make sure, that all plugins use the same time
|
||||||
data['timestamp'] = int(time.time())
|
data['timestamp'] = int(time.time())
|
||||||
# Go to all plugins in pluginList
|
# Go to all plugins in pluginList
|
||||||
for pluginName, plugin in globals.pluginList.items():
|
for pluginName, plugin in globalVars.pluginList.items():
|
||||||
# if enabled use RegEx-filter
|
# if enabled use RegEx-filter
|
||||||
if globals.config.getint("BOSWatch","useRegExFilter"):
|
if globalVars.config.getint("BOSWatch","useRegExFilter"):
|
||||||
from includes import regexFilter
|
from includes import regexFilter
|
||||||
if regexFilter.checkFilters(typ, data, pluginName, freq):
|
if regexFilter.checkFilters(typ, data, pluginName, freq):
|
||||||
logging.debug("call Plugin: %s", pluginName)
|
logging.debug("call Plugin: %s", pluginName)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ def checkRTL():
|
||||||
@exception: Exception when checkRTL throws an unexpected error
|
@exception: Exception when checkRTL throws an unexpected error
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
rtlLog = open(globals.log_path+"rtl_fm.log","r").read()
|
rtlLog = open(globalVars.log_path+"rtl_fm.log","r").read()
|
||||||
if ("exiting" in rtlLog) or ("Failed to open" in rtlLog):
|
if ("exiting" in rtlLog) or ("Failed to open" in rtlLog):
|
||||||
logging.debug("\n%s", rtlLog)
|
logging.debug("\n%s", rtlLog)
|
||||||
raise OSError("starting rtl_fm returns an error")
|
raise OSError("starting rtl_fm returns an error")
|
||||||
|
|
@ -41,7 +41,7 @@ def checkMultimon():
|
||||||
@exception: Exception when checkMultimon throws an unexpected error
|
@exception: Exception when checkMultimon throws an unexpected error
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
multimonLog = open(globals.log_path+"multimon.log","r").read()
|
multimonLog = open(globalVars.log_path+"multimon.log","r").read()
|
||||||
if ("invalid" in multimonLog) or ("error" in multimonLog):
|
if ("invalid" in multimonLog) or ("error" in multimonLog):
|
||||||
logging.debug("\n%s", multimonLog)
|
logging.debug("\n%s", multimonLog)
|
||||||
raise OSError("starting multimon-ng returns an error")
|
raise OSError("starting multimon-ng returns an error")
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ def decode(freq, decoded):
|
||||||
logging.info("FMS:%s Status:%s Richtung:%s TSI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi)
|
logging.info("FMS:%s Status:%s Richtung:%s TSI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi)
|
||||||
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "directionText":fms_directionText, "tsi":fms_tsi, "description":fms_id[0:8]}
|
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "directionText":fms_directionText, "tsi":fms_tsi, "description":fms_id[0:8]}
|
||||||
# If enabled, look up description
|
# If enabled, look up description
|
||||||
if globals.config.getint("FMS", "idDescribed"):
|
if globalVars.config.getint("FMS", "idDescribed"):
|
||||||
from includes import descriptionList
|
from includes import descriptionList
|
||||||
data["description"] = descriptionList.getDescription("FMS", fms_id[0:8])
|
data["description"] = descriptionList.getDescription("FMS", fms_id[0:8])
|
||||||
# processing the alarm
|
# processing the alarm
|
||||||
|
|
|
||||||
|
|
@ -34,22 +34,22 @@ def isAllowed(poc_id):
|
||||||
"""
|
"""
|
||||||
# 1.) If allowed RICs is set, only they will path,
|
# 1.) If allowed RICs is set, only they will path,
|
||||||
# If RIC is the right one return True, else False
|
# If RIC is the right one return True, else False
|
||||||
if globals.config.get("POC", "allow_ric"):
|
if globalVars.config.get("POC", "allow_ric"):
|
||||||
if poc_id in globals.config.get("POC", "allow_ric"):
|
if poc_id in globalVars.config.get("POC", "allow_ric"):
|
||||||
logging.info("RIC %s is allowed", poc_id)
|
logging.info("RIC %s is allowed", poc_id)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
logging.info("RIC %s is not in the allowed list", poc_id)
|
logging.info("RIC %s is not in the allowed list", poc_id)
|
||||||
return False
|
return False
|
||||||
# 2.) If denied RIC, return False
|
# 2.) If denied RIC, return False
|
||||||
elif poc_id in globals.config.get("POC", "deny_ric"):
|
elif poc_id in globalVars.config.get("POC", "deny_ric"):
|
||||||
logging.info("RIC %s is denied by config.ini", poc_id)
|
logging.info("RIC %s is denied by config.ini", poc_id)
|
||||||
return False
|
return False
|
||||||
# 3.) Check Range, return False if outside def. range
|
# 3.) Check Range, return False if outside def. range
|
||||||
elif int(poc_id) < globals.config.getint("POC", "filter_range_start"):
|
elif int(poc_id) < globalVars.config.getint("POC", "filter_range_start"):
|
||||||
logging.info("RIC %s out of filter range (start)", poc_id)
|
logging.info("RIC %s out of filter range (start)", poc_id)
|
||||||
return False
|
return False
|
||||||
elif int(poc_id) > globals.config.getint("POC", "filter_range_end"):
|
elif int(poc_id) > globalVars.config.getint("POC", "filter_range_end"):
|
||||||
logging.info("RIC %s out of filter range (end)", poc_id)
|
logging.info("RIC %s out of filter range (end)", poc_id)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
@ -111,7 +111,7 @@ def decode(freq, decoded):
|
||||||
# Add function as character a-d to dataset
|
# Add function as character a-d to dataset
|
||||||
data["functionChar"] = data["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d")
|
data["functionChar"] = data["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d")
|
||||||
# If enabled, look up description
|
# If enabled, look up description
|
||||||
if globals.config.getint("POC", "idDescribed"):
|
if globalVars.config.getint("POC", "idDescribed"):
|
||||||
from includes import descriptionList
|
from includes import descriptionList
|
||||||
data["description"] = descriptionList.getDescription("POC", poc_id)
|
data["description"] = descriptionList.getDescription("POC", poc_id)
|
||||||
# processing the alarm
|
# processing the alarm
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ def decode(freq, decoded):
|
||||||
logging.info("5-Ton: %s", zvei_id)
|
logging.info("5-Ton: %s", zvei_id)
|
||||||
data = {"zvei":zvei_id, "description":zvei_id}
|
data = {"zvei":zvei_id, "description":zvei_id}
|
||||||
# If enabled, look up description
|
# If enabled, look up description
|
||||||
if globals.config.getint("ZVEI", "idDescribed"):
|
if globalVars.config.getint("ZVEI", "idDescribed"):
|
||||||
from includes import descriptionList
|
from includes import descriptionList
|
||||||
data["description"] = descriptionList.getDescription("ZVEI", zvei_id)
|
data["description"] = descriptionList.getDescription("ZVEI", zvei_id)
|
||||||
# processing the alarm
|
# processing the alarm
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ def loadCSV(typ, idField):
|
||||||
resultList = {}
|
resultList = {}
|
||||||
try:
|
try:
|
||||||
logging.debug("-- loading %s.csv", typ)
|
logging.debug("-- loading %s.csv", typ)
|
||||||
with open(globals.script_path+'/csv/'+typ+'.csv') as csvfile:
|
with open(globalVars.script_path+'/csv/'+typ+'.csv') as csvfile:
|
||||||
# DictReader expected structure described in first line of csv-file
|
# DictReader expected structure described in first line of csv-file
|
||||||
reader = csv.DictReader(csvfile)
|
reader = csv.DictReader(csvfile)
|
||||||
for row in reader:
|
for row in reader:
|
||||||
|
|
@ -70,17 +70,17 @@ def loadDescriptionLists():
|
||||||
try:
|
try:
|
||||||
logging.debug("loading description lists")
|
logging.debug("loading description lists")
|
||||||
|
|
||||||
if globals.config.getint("FMS", "idDescribed"):
|
if globalVars.config.getint("FMS", "idDescribed"):
|
||||||
logging.debug("- load FMS description list")
|
logging.debug("- load FMS description list")
|
||||||
global fmsDescribtionList
|
global fmsDescribtionList
|
||||||
fmsDescribtionList = loadCSV("fms", "fms")
|
fmsDescribtionList = loadCSV("fms", "fms")
|
||||||
|
|
||||||
if globals.config.getint("ZVEI", "idDescribed"):
|
if globalVars.config.getint("ZVEI", "idDescribed"):
|
||||||
logging.debug("- load ZVEI description list")
|
logging.debug("- load ZVEI description list")
|
||||||
global zveiDescribtionList
|
global zveiDescribtionList
|
||||||
zveiDescribtionList = loadCSV("zvei", "zvei")
|
zveiDescribtionList = loadCSV("zvei", "zvei")
|
||||||
|
|
||||||
if globals.config.getint("POC", "idDescribed"):
|
if globalVars.config.getint("POC", "idDescribed"):
|
||||||
logging.debug("- load pocsag description list")
|
logging.debug("- load pocsag description list")
|
||||||
global ricDescribtionList
|
global ricDescribtionList
|
||||||
ricDescribtionList = loadCSV("poc", "ric")
|
ricDescribtionList = loadCSV("poc", "ric")
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@ def checkID(typ, id, msg=""):
|
||||||
(xID, xTimestamp, xMsg) = doubleList[i]
|
(xID, xTimestamp, xMsg) = doubleList[i]
|
||||||
# given ID found?
|
# given ID found?
|
||||||
# return False if the first entry in double_ignore_time is found, we will not check for younger ones...
|
# return False if the first entry in double_ignore_time is found, we will not check for younger ones...
|
||||||
if id == xID and timestamp < xTimestamp + globals.config.getint("BOSWatch", "doubleFilter_ignore_time"):
|
if id == xID and timestamp < xTimestamp + globalVars.config.getint("BOSWatch", "doubleFilter_ignore_time"):
|
||||||
logging.debug("-- previous id %s is within doubleFilter_ignore_time (%ss)", xID, globals.config.getint("BOSWatch", "doubleFilter_ignore_time"))
|
logging.debug("-- previous id %s is within doubleFilter_ignore_time (%ss)", xID, globalVars.config.getint("BOSWatch", "doubleFilter_ignore_time"))
|
||||||
# if wanted, we have to check the msg additional
|
# if wanted, we have to check the msg additional
|
||||||
if "POC" in typ and globals.config.getint("BOSWatch", "doubleFilter_check_msg"):
|
if "POC" in typ and globalVars.config.getint("BOSWatch", "doubleFilter_check_msg"):
|
||||||
logging.debug("-- compare msg:")
|
logging.debug("-- compare msg:")
|
||||||
logging.debug("---- current msg: (%s)", msg.strip())
|
logging.debug("---- current msg: (%s)", msg.strip())
|
||||||
logging.debug("---- previous msg: (%s)", xMsg)
|
logging.debug("---- previous msg: (%s)", xMsg)
|
||||||
|
|
@ -69,6 +69,6 @@ def newEntry(id, msg = ""):
|
||||||
logging.debug("Added %s to doubleList", id)
|
logging.debug("Added %s to doubleList", id)
|
||||||
|
|
||||||
# now check if list has more than n entries:
|
# now check if list has more than n entries:
|
||||||
if len(doubleList) > globals.config.getint("BOSWatch", "doubleFilter_ignore_entries"):
|
if len(doubleList) > globalVars.config.getint("BOSWatch", "doubleFilter_ignore_entries"):
|
||||||
# we have to kill the oldest one
|
# we have to kill the oldest one
|
||||||
doubleList.pop(0)
|
doubleList.pop(0)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ def checkConfig(section=""):
|
||||||
if section is not "": # read only data if section is given
|
if section is not "": # read only data if section is given
|
||||||
logging.debug("read [%s] from config file", section)
|
logging.debug("read [%s] from config file", section)
|
||||||
|
|
||||||
for key,val in globals.config.items(section):
|
for key,val in globalVars.config.items(section):
|
||||||
if ("password" in key) or ("apikey" in key):
|
if ("password" in key) or ("apikey" in key):
|
||||||
val = "***"
|
val = "***"
|
||||||
logging.debug(" - %s = %s", key, val)
|
logging.debug(" - %s = %s", key, val)
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,10 @@ from includes import globalVars # Global variables
|
||||||
|
|
||||||
def loadPlugins():
|
def loadPlugins():
|
||||||
"""
|
"""
|
||||||
Load all plugins into globals.pluginList
|
Load all plugins into globalVars.pluginList
|
||||||
|
|
||||||
@return: nothing
|
@return: nothing
|
||||||
@exception: Exception if insert into globals.pluginList failed
|
@exception: Exception if insert into globalVars.pluginList failed
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
logging.debug("loading plugins")
|
logging.debug("loading plugins")
|
||||||
|
|
@ -41,8 +41,8 @@ def loadPlugins():
|
||||||
# Try to call the .onLoad() routine for all active plugins
|
# Try to call the .onLoad() routine for all active plugins
|
||||||
logging.debug("call %s.onLoad()", i["name"])
|
logging.debug("call %s.onLoad()", i["name"])
|
||||||
plugin.onLoad()
|
plugin.onLoad()
|
||||||
# Add it to globals.pluginList
|
# Add it to globalVars.pluginList
|
||||||
globals.pluginList[i["name"]] = plugin
|
globalVars.pluginList[i["name"]] = plugin
|
||||||
except:
|
except:
|
||||||
# call next plugin, if one has thrown an exception
|
# call next plugin, if one has thrown an exception
|
||||||
logging.error("error calling %s.onLoad()", i["name"])
|
logging.error("error calling %s.onLoad()", i["name"])
|
||||||
|
|
@ -63,7 +63,7 @@ def getPlugins():
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
logging.debug("Search in plugin folder")
|
logging.debug("Search in plugin folder")
|
||||||
PluginFolder = globals.script_path+"/plugins"
|
PluginFolder = globalVars.script_path+"/plugins"
|
||||||
plugins = []
|
plugins = []
|
||||||
# Go to all Folders in the Plugin-Dir
|
# Go to all Folders in the Plugin-Dir
|
||||||
for i in os.listdir(PluginFolder):
|
for i in os.listdir(PluginFolder):
|
||||||
|
|
@ -75,7 +75,7 @@ def getPlugins():
|
||||||
|
|
||||||
# is the plugin enabled in the config-file?
|
# is the plugin enabled in the config-file?
|
||||||
try:
|
try:
|
||||||
if globals.config.getint("Plugins", i):
|
if globalVars.config.getint("Plugins", i):
|
||||||
info = imp.find_module(i, [location])
|
info = imp.find_module(i, [location])
|
||||||
plugins.append({"name": i, "info": info})
|
plugins.append({"name": i, "info": info})
|
||||||
logging.debug("Plugin [ENABLED ] %s", i)
|
logging.debug("Plugin [ENABLED ] %s", i)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ def loadFilters():
|
||||||
try:
|
try:
|
||||||
logging.debug("loading filters")
|
logging.debug("loading filters")
|
||||||
# For each entry in config.ini [Filters] section
|
# For each entry in config.ini [Filters] section
|
||||||
for key,val in globals.config.items("Filters"):
|
for key,val in globalVars.config.items("Filters"):
|
||||||
logging.debug(" - %s = %s", key, val)
|
logging.debug(" - %s = %s", key, val)
|
||||||
filter = val.split(";")
|
filter = val.split(";")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ def printHeader(args):
|
||||||
print " German BOS Information Script "
|
print " German BOS Information Script "
|
||||||
print " by Bastian Schroll, Jens Herrmann "
|
print " by Bastian Schroll, Jens Herrmann "
|
||||||
print ""
|
print ""
|
||||||
print "SW Version: "+globals.versionNr
|
print "SW Version: "+globalVars.versionNr
|
||||||
print "Build Date: "+globals.buildDate
|
print "Build Date: "+globalVars.buildDate
|
||||||
print ""
|
print ""
|
||||||
|
|
||||||
print "Frequency: "+args.freq
|
print "Frequency: "+args.freq
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ def bosMonRequest(httprequest, params, headers):
|
||||||
#
|
#
|
||||||
# BosMon/HTTP-Request
|
# BosMon/HTTP-Request
|
||||||
#
|
#
|
||||||
httprequest.request("POST", "/telegramin/"+globals.config.get("BosMon", "bosmon_channel")+"/input.xml", params, headers)
|
httprequest.request("POST", "/telegramin/"+globalVars.config.get("BosMon", "bosmon_channel")+"/input.xml", params, headers)
|
||||||
except:
|
except:
|
||||||
logging.error("request to BosMon failed")
|
logging.error("request to BosMon failed")
|
||||||
logging.debug("request to BosMon failed", exc_info=True)
|
logging.debug("request to BosMon failed", exc_info=True)
|
||||||
|
|
@ -110,12 +110,12 @@ def run(typ,freq,data):
|
||||||
headers['Content-type'] = "application/x-www-form-urlencoded"
|
headers['Content-type'] = "application/x-www-form-urlencoded"
|
||||||
headers['Accept'] = "text/plain"
|
headers['Accept'] = "text/plain"
|
||||||
# if an user is set in the config.ini we will use HTTP-Authorization
|
# if an user is set in the config.ini we will use HTTP-Authorization
|
||||||
if globals.config.get("BosMon", "bosmon_user"):
|
if globalVars.config.get("BosMon", "bosmon_user"):
|
||||||
# generate b64encoded autorization-token for HTTP-request
|
# generate b64encoded autorization-token for HTTP-request
|
||||||
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(globals.config.get("BosMon", "bosmon_user"), globals.config.get("BosMon", "bosmon_password"))))
|
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(globalVars.config.get("BosMon", "bosmon_user"), globalVars.config.get("BosMon", "bosmon_password"))))
|
||||||
logging.debug("connect to BosMon")
|
logging.debug("connect to BosMon")
|
||||||
# open connection to BosMon-Server
|
# open connection to BosMon-Server
|
||||||
httprequest = httplib.HTTPConnection(globals.config.get("BosMon", "bosmon_server"), globals.config.get("BosMon", "bosmon_port"), timeout=5)
|
httprequest = httplib.HTTPConnection(globalVars.config.get("BosMon", "bosmon_server"), globalVars.config.get("BosMon", "bosmon_port"), timeout=5)
|
||||||
# debug-level to shell (0=no debug|1)
|
# debug-level to shell (0=no debug|1)
|
||||||
httprequest.set_debuglevel(0)
|
httprequest.set_debuglevel(0)
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
|
|
@ -71,18 +71,18 @@ def run(typ,freq,data):
|
||||||
#
|
#
|
||||||
logging.debug("send FFAgent %s", typ)
|
logging.debug("send FFAgent %s", typ)
|
||||||
|
|
||||||
if globals.config.get("FFAgent", "live") == "1":
|
if globalVars.config.get("FFAgent", "live") == "1":
|
||||||
url = "https://api.service.ff-agent.com/v1/WebService/triggerAlarm"
|
url = "https://api.service.ff-agent.com/v1/WebService/triggerAlarm"
|
||||||
else:
|
else:
|
||||||
url = "https://free.api.service.ff-agent.com/v1/WebService/triggerAlarm"
|
url = "https://free.api.service.ff-agent.com/v1/WebService/triggerAlarm"
|
||||||
|
|
||||||
serverCertFile = globals.config.get("FFAgent", "serverCertFile")
|
serverCertFile = globalVars.config.get("FFAgent", "serverCertFile")
|
||||||
clientCertFile = globals.config.get("FFAgent", "clientCertFile")
|
clientCertFile = globalVars.config.get("FFAgent", "clientCertFile")
|
||||||
clientCertPass = globals.config.get("FFAgent", "clientCertPass")
|
clientCertPass = globalVars.config.get("FFAgent", "clientCertPass")
|
||||||
webApiToken = globals.config.get("FFAgent", "webApiToken")
|
webApiToken = globalVars.config.get("FFAgent", "webApiToken")
|
||||||
webApiKey = globals.config.get("FFAgent", "webApiKey")
|
webApiKey = globalVars.config.get("FFAgent", "webApiKey")
|
||||||
accessToken = globals.config.get("FFAgent", "accessToken")
|
accessToken = globalVars.config.get("FFAgent", "accessToken")
|
||||||
selectiveCallCode = globals.config.get("FFAgent", "selectiveCallCode")
|
selectiveCallCode = globalVars.config.get("FFAgent", "selectiveCallCode")
|
||||||
|
|
||||||
# data["description"]
|
# data["description"]
|
||||||
msg_split = data["msg"].split(';')
|
msg_split = data["msg"].split(';')
|
||||||
|
|
@ -105,7 +105,7 @@ def run(typ,freq,data):
|
||||||
"alarmMessage" : ""
|
"alarmMessage" : ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if globals.config.get("FFAgent", "test") == "1":
|
if globalVars.config.get("FFAgent", "test") == "1":
|
||||||
alarmData = {
|
alarmData = {
|
||||||
"alarmDate" : "",
|
"alarmDate" : "",
|
||||||
"keyword" : "Test",
|
"keyword" : "Test",
|
||||||
|
|
@ -135,7 +135,7 @@ def run(typ,freq,data):
|
||||||
"hmac": hmac.new(webApiKey, webApiToken + selectiveCallCode + accessToken + alarmData, digestmod=hashlib.sha256).hexdigest()
|
"hmac": hmac.new(webApiKey, webApiToken + selectiveCallCode + accessToken + alarmData, digestmod=hashlib.sha256).hexdigest()
|
||||||
}
|
}
|
||||||
|
|
||||||
if globals.config.get("FFAgent", "live") == "1":
|
if globalVars.config.get("FFAgent", "live") == "1":
|
||||||
r = requests.post(url, data=alarmData, headers=headers, verify=serverCertFile, cert=(clientCertFile, clientCertPass))
|
r = requests.post(url, data=alarmData, headers=headers, verify=serverCertFile, cert=(clientCertFile, clientCertPass))
|
||||||
else:
|
else:
|
||||||
r = requests.post(url, data=alarmData, headers=alarmHeaders, verify=serverCertFile)
|
r = requests.post(url, data=alarmData, headers=alarmHeaders, verify=serverCertFile)
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ def isSignal(poc_id):
|
||||||
@exception: none
|
@exception: none
|
||||||
"""
|
"""
|
||||||
# If RIC is Signal return True, else False
|
# If RIC is Signal return True, else False
|
||||||
if globals.config.get("MySQL", "signal_ric"):
|
if globalVars.config.get("MySQL", "signal_ric"):
|
||||||
if poc_id in globals.config.get("MySQL", "signal_ric"):
|
if poc_id in globalVars.config.get("MySQL", "signal_ric"):
|
||||||
logging.info("RIC %s is signal", poc_id)
|
logging.info("RIC %s is signal", poc_id)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|
@ -91,7 +91,7 @@ def run(typ,freq,data):
|
||||||
# Connect to MySQL
|
# Connect to MySQL
|
||||||
#
|
#
|
||||||
logging.debug("connect to MySQL")
|
logging.debug("connect to MySQL")
|
||||||
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"), charset='utf8')
|
connection = mysql.connector.connect(host = globalVars.config.get("MySQL","dbserver"), user = globalVars.config.get("MySQL","dbuser"), passwd = globalVars.config.get("MySQL","dbpassword"), db = globalVars.config.get("MySQL","database"), charset='utf8')
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
except:
|
except:
|
||||||
logging.error("cannot connect to MySQL")
|
logging.error("cannot connect to MySQL")
|
||||||
|
|
@ -104,18 +104,18 @@ def run(typ,freq,data):
|
||||||
logging.debug("Insert %s", typ)
|
logging.debug("Insert %s", typ)
|
||||||
|
|
||||||
if typ == "FMS":
|
if typ == "FMS":
|
||||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableFMS")+" (time, fms, status, direction, directionText, tsi, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["fms"], data["status"], data["direction"], data["directionText"], data["tsi"], data["description"]))
|
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableFMS")+" (time, fms, status, direction, directionText, tsi, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["fms"], data["status"], data["direction"], data["directionText"], data["tsi"], data["description"]))
|
||||||
|
|
||||||
elif typ == "ZVEI":
|
elif typ == "ZVEI":
|
||||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableZVEI")+" (time, zvei, description) VALUES (FROM_UNIXTIME(%s),%s,%s)", (data["timestamp"], data["zvei"], data["description"]))
|
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableZVEI")+" (time, zvei, description) VALUES (FROM_UNIXTIME(%s),%s,%s)", (data["timestamp"], data["zvei"], data["description"]))
|
||||||
|
|
||||||
elif typ == "POC":
|
elif typ == "POC":
|
||||||
if isSignal(data["ric"]):
|
if isSignal(data["ric"]):
|
||||||
cursor.execute("UPDATE "+globals.config.get("MySQL","tableSIG")+" SET time = NOW() WHERE ric = "+data["ric"])
|
cursor.execute("UPDATE "+globalVars.config.get("MySQL","tableSIG")+" SET time = NOW() WHERE ric = "+data["ric"])
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableSIG")+" (time,ric) VALUES (NOW(),"+data["ric"]+")")
|
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableSIG")+" (time,ric) VALUES (NOW(),"+data["ric"]+")")
|
||||||
else:
|
else:
|
||||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tablePOC")+" (time, ric, function, functionChar, msg, bitrate, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["ric"], data["function"], data["functionChar"], data["msg"], data["bitrate"], data["description"]))
|
cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tablePOC")+" (time, ric, function, functionChar, msg, bitrate, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["ric"], data["function"], data["functionChar"], data["msg"], data["bitrate"], data["description"]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.warning("Invalid Typ: %s", typ)
|
logging.warning("Invalid Typ: %s", typ)
|
||||||
|
|
|
||||||
|
|
@ -67,27 +67,27 @@ def run(typ,freq,data):
|
||||||
logging.debug("send Pushover %s", typ)
|
logging.debug("send Pushover %s", typ)
|
||||||
|
|
||||||
if data["function"] == '1':
|
if data["function"] == '1':
|
||||||
priority = globals.config.get("Pushover", "SubA")
|
priority = globalVars.config.get("Pushover", "SubA")
|
||||||
elif data["function"] == '2':
|
elif data["function"] == '2':
|
||||||
priority = globals.config.get("Pushover", "SubB")
|
priority = globalVars.config.get("Pushover", "SubB")
|
||||||
elif data["function"] == '3':
|
elif data["function"] == '3':
|
||||||
priority = globals.config.get("Pushover", "SubC")
|
priority = globalVars.config.get("Pushover", "SubC")
|
||||||
elif data["function"] == '4':
|
elif data["function"] == '4':
|
||||||
priority = globals.config.get("Pushover", "SubD")
|
priority = globalVars.config.get("Pushover", "SubD")
|
||||||
else:
|
else:
|
||||||
priority = 0
|
priority = 0
|
||||||
|
|
||||||
conn = httplib.HTTPSConnection("api.pushover.net:443")
|
conn = httplib.HTTPSConnection("api.pushover.net:443")
|
||||||
conn.request("POST", "/1/messages.json",
|
conn.request("POST", "/1/messages.json",
|
||||||
urllib.urlencode({
|
urllib.urlencode({
|
||||||
"token": globals.config.get("Pushover", "api_key"),
|
"token": globalVars.config.get("Pushover", "api_key"),
|
||||||
"user": globals.config.get("Pushover", "user_key"),
|
"user": globalVars.config.get("Pushover", "user_key"),
|
||||||
"message": "<b>"+data["description"]+"</b><br>"+data["msg"].replace(";", "<br>"),
|
"message": "<b>"+data["description"]+"</b><br>"+data["msg"].replace(";", "<br>"),
|
||||||
"html": globals.config.get("Pushover", "html"),
|
"html": globalVars.config.get("Pushover", "html"),
|
||||||
"title": globals.config.get("Pushover", "title"),
|
"title": globalVars.config.get("Pushover", "title"),
|
||||||
"priority": priority,
|
"priority": priority,
|
||||||
"retry": globals.config.get("Pushover", "retry"),
|
"retry": globalVars.config.get("Pushover", "retry"),
|
||||||
"expire": globals.config.get("Pushover", "expire")
|
"expire": globalVars.config.get("Pushover", "expire")
|
||||||
}),{"Content-type": "application/x-www-form-urlencoded"})
|
}),{"Content-type": "application/x-www-form-urlencoded"})
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
|
|
@ -64,20 +64,20 @@ test2 = 123456
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 3.2 Read data from config.ini
|
#### 3.2 Read data from config.ini
|
||||||
To read yout configuration data you must import the `globals.py` where the global config-object is located:
|
To read yout configuration data you must import the `globalVars.py` where the global config-object is located:
|
||||||
```python
|
```python
|
||||||
from includes import globalVars # Global variables
|
from includes import globalVars # Global variables
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can get your configuration data with:
|
Now you can get your configuration data with:
|
||||||
```python
|
```python
|
||||||
VALUE = globals.config.get("SECTION", "OPTION") #Gets any value
|
VALUE = globalVars.config.get("SECTION", "OPTION") #Gets any value
|
||||||
```
|
```
|
||||||
or better, use this:
|
or better, use this:
|
||||||
```python
|
```python
|
||||||
VALUE = globals.config.getint("SECTION", "OPTION") #Value must be an Integer
|
VALUE = globalVars.config.getint("SECTION", "OPTION") #Value must be an Integer
|
||||||
VALUE = globals.config.getfloat("SECTION", "OPTION") #Value must be an Float
|
VALUE = globalVars.config.getfloat("SECTION", "OPTION") #Value must be an Float
|
||||||
VALUE = globals.config.getboolean("SECTION", "OPTION") #Value must be an Boolean
|
VALUE = globalVars.config.getboolean("SECTION", "OPTION") #Value must be an Boolean
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,18 +89,18 @@ def run(typ,freq,data):
|
||||||
logging.debug("Plugin SMS enabled")
|
logging.debug("Plugin SMS enabled")
|
||||||
|
|
||||||
# get number of cases and build a RIC-Array
|
# get number of cases and build a RIC-Array
|
||||||
i = globals.config.get("SMS","quantity")
|
i = globalVars.config.get("SMS","quantity")
|
||||||
aRic = []
|
aRic = []
|
||||||
|
|
||||||
# build the array
|
# build the array
|
||||||
for x in range (1, int(i) + 1):
|
for x in range (1, int(i) + 1):
|
||||||
# check the number of subrics
|
# check the number of subrics
|
||||||
subric = globals.config.get("SMS","subric" + str(x))
|
subric = globalVars.config.get("SMS","subric" + str(x))
|
||||||
if len(subric) > 1: # we have more than one subric
|
if len(subric) > 1: # we have more than one subric
|
||||||
subric_list = subric.split(",")
|
subric_list = subric.split(",")
|
||||||
for y in range (0, len(subric_list)):
|
for y in range (0, len(subric_list)):
|
||||||
sric = subric_list[y].replace(' ','')
|
sric = subric_list[y].replace(' ','')
|
||||||
full_ric = globals.config.get("SMS","ric" + str(x)) + sric
|
full_ric = globalVars.config.get("SMS","ric" + str(x)) + sric
|
||||||
case = x
|
case = x
|
||||||
tmp = []
|
tmp = []
|
||||||
tmp.append(full_ric)
|
tmp.append(full_ric)
|
||||||
|
|
@ -109,7 +109,7 @@ def run(typ,freq,data):
|
||||||
else:
|
else:
|
||||||
#get ric AND subric at once with ONE subric
|
#get ric AND subric at once with ONE subric
|
||||||
tmp = []
|
tmp = []
|
||||||
tmp.append(globals.config.get("SMS","ric" + str(x)) + subric)
|
tmp.append(globalVars.config.get("SMS","ric" + str(x)) + subric)
|
||||||
tmp.append(x)
|
tmp.append(x)
|
||||||
aRic.append(tmp) # 2D-Array...
|
aRic.append(tmp) # 2D-Array...
|
||||||
|
|
||||||
|
|
@ -130,8 +130,8 @@ def run(typ,freq,data):
|
||||||
case = aRic[index[0]][1]
|
case = aRic[index[0]][1]
|
||||||
logging.debug("Enabling case %s", case)
|
logging.debug("Enabling case %s", case)
|
||||||
|
|
||||||
text = globals.config.get("SMS","text" + str(case))
|
text = globalVars.config.get("SMS","text" + str(case))
|
||||||
number = globals.config.get("SMS","phonenumber" + str(case))
|
number = globalVars.config.get("SMS","phonenumber" + str(case))
|
||||||
|
|
||||||
#just for debug
|
#just for debug
|
||||||
logging.debug("Aktivierter Text: %s", text)
|
logging.debug("Aktivierter Text: %s", text)
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,11 @@ def run(typ,freq,data):
|
||||||
conn = httplib.HTTPSConnection("gateway.sms77.de:443")
|
conn = httplib.HTTPSConnection("gateway.sms77.de:443")
|
||||||
conn.request("POST", "",
|
conn.request("POST", "",
|
||||||
urllib.urlencode({
|
urllib.urlencode({
|
||||||
"u": globals.config.get("Sms77", "user"),
|
"u": globalVars.config.get("Sms77", "user"),
|
||||||
"p": globals.config.get("Sms77", "password"),
|
"p": globalVars.config.get("Sms77", "password"),
|
||||||
"to": globals.config.get("Sms77", "to"),
|
"to": globalVars.config.get("Sms77", "to"),
|
||||||
"from": globals.config.get("Sms77", "from"),
|
"from": globalVars.config.get("Sms77", "from"),
|
||||||
"type": globals.config.get("Sms77", "type"),
|
"type": globalVars.config.get("Sms77", "type"),
|
||||||
"text": data["description"]+"<br>"+data["msg"].replace(";", "<br>")
|
"text": data["description"]+"<br>"+data["msg"].replace(";", "<br>")
|
||||||
}),{"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
|
}),{"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,10 @@ def onLoad():
|
||||||
global GoogleAPIKey
|
global GoogleAPIKey
|
||||||
|
|
||||||
configHandler.checkConfig("Telegram")
|
configHandler.checkConfig("Telegram")
|
||||||
BOTTokenAPIKey = globals.config.get("Telegram","BOTTokenAPIKey")
|
BOTTokenAPIKey = globalVars.config.get("Telegram","BOTTokenAPIKey")
|
||||||
BOTChatIDAPIKey = globals.config.get("Telegram","BOTChatIDAPIKey")
|
BOTChatIDAPIKey = globalVars.config.get("Telegram","BOTChatIDAPIKey")
|
||||||
RICforLocationAPIKey = globals.config.get("Telegram","RICforLocationAPIKey")
|
RICforLocationAPIKey = globalVars.config.get("Telegram","RICforLocationAPIKey")
|
||||||
GoogleAPIKey = globals.config.get("Telegram","GoogleAPIKey")
|
GoogleAPIKey = globalVars.config.get("Telegram","GoogleAPIKey")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,13 +59,13 @@ def doSendmail(server, subject, mailtext):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
msg = MIMEText(mailtext, 'plain', 'UTF-8')
|
msg = MIMEText(mailtext, 'plain', 'UTF-8')
|
||||||
msg['From'] = globals.config.get("eMail", "from")
|
msg['From'] = globalVars.config.get("eMail", "from")
|
||||||
msg['To'] = globals.config.get("eMail", "to")
|
msg['To'] = globalVars.config.get("eMail", "to")
|
||||||
msg['Subject'] = subject
|
msg['Subject'] = subject
|
||||||
msg['Date'] = formatdate()
|
msg['Date'] = formatdate()
|
||||||
msg['Message-Id'] = make_msgid()
|
msg['Message-Id'] = make_msgid()
|
||||||
msg['Priority'] = globals.config.get("eMail", "priority")
|
msg['Priority'] = globalVars.config.get("eMail", "priority")
|
||||||
server.sendmail(globals.config.get("eMail", "from"), globals.config.get("eMail", "to").split(), msg.as_string())
|
server.sendmail(globalVars.config.get("eMail", "from"), globalVars.config.get("eMail", "to").split(), msg.as_string())
|
||||||
except:
|
except:
|
||||||
logging.error("send eMail failed")
|
logging.error("send eMail failed")
|
||||||
logging.debug("send eMail failed", exc_info=True)
|
logging.debug("send eMail failed", exc_info=True)
|
||||||
|
|
@ -103,17 +103,17 @@ def run(typ,freq,data):
|
||||||
#
|
#
|
||||||
# connect to SMTP-Server
|
# connect to SMTP-Server
|
||||||
#
|
#
|
||||||
server = smtplib.SMTP(globals.config.get("eMail", "smtp_server"), globals.config.get("eMail", "smtp_port"))
|
server = smtplib.SMTP(globalVars.config.get("eMail", "smtp_server"), globalVars.config.get("eMail", "smtp_port"))
|
||||||
# debug-level to shell (0=no debug|1)
|
# debug-level to shell (0=no debug|1)
|
||||||
server.set_debuglevel(0)
|
server.set_debuglevel(0)
|
||||||
|
|
||||||
# if tls is enabled, starttls
|
# if tls is enabled, starttls
|
||||||
if globals.config.get("eMail", "tls"):
|
if globalVars.config.get("eMail", "tls"):
|
||||||
server.starttls()
|
server.starttls()
|
||||||
|
|
||||||
# if user is given, login
|
# if user is given, login
|
||||||
if globals.config.get("eMail", "user"):
|
if globalVars.config.get("eMail", "user"):
|
||||||
server.login(globals.config.get("eMail", "user"), globals.config.get("eMail", "password"))
|
server.login(globalVars.config.get("eMail", "user"), globalVars.config.get("eMail", "password"))
|
||||||
|
|
||||||
except:
|
except:
|
||||||
logging.error("cannot connect to eMail")
|
logging.error("cannot connect to eMail")
|
||||||
|
|
@ -127,12 +127,12 @@ def run(typ,freq,data):
|
||||||
logging.debug("Start FMS to eMail")
|
logging.debug("Start FMS to eMail")
|
||||||
try:
|
try:
|
||||||
# read subject-structure from config.ini
|
# read subject-structure from config.ini
|
||||||
subject = globals.config.get("eMail", "fms_subject")
|
subject = globalVars.config.get("eMail", "fms_subject")
|
||||||
# replace wildcards with helper function
|
# replace wildcards with helper function
|
||||||
subject = wildcardHandler.replaceWildcards(subject, data)
|
subject = wildcardHandler.replaceWildcards(subject, data)
|
||||||
|
|
||||||
# read mailtext-structure from config.ini
|
# read mailtext-structure from config.ini
|
||||||
mailtext = globals.config.get("eMail", "fms_message")
|
mailtext = globalVars.config.get("eMail", "fms_message")
|
||||||
# replace wildcards with helper function
|
# replace wildcards with helper function
|
||||||
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
||||||
|
|
||||||
|
|
@ -147,12 +147,12 @@ def run(typ,freq,data):
|
||||||
logging.debug("Start ZVEI to eMail")
|
logging.debug("Start ZVEI to eMail")
|
||||||
try:
|
try:
|
||||||
# read subject-structure from config.ini
|
# read subject-structure from config.ini
|
||||||
subject = globals.config.get("eMail", "zvei_subject")
|
subject = globalVars.config.get("eMail", "zvei_subject")
|
||||||
# replace wildcards with helper function
|
# replace wildcards with helper function
|
||||||
subject = wildcardHandler.replaceWildcards(subject, data)
|
subject = wildcardHandler.replaceWildcards(subject, data)
|
||||||
|
|
||||||
# read mailtext-structure from config.ini
|
# read mailtext-structure from config.ini
|
||||||
mailtext = globals.config.get("eMail", "zvei_message")
|
mailtext = globalVars.config.get("eMail", "zvei_message")
|
||||||
# replace wildcards with helper function
|
# replace wildcards with helper function
|
||||||
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
||||||
|
|
||||||
|
|
@ -167,12 +167,12 @@ def run(typ,freq,data):
|
||||||
logging.debug("Start POC to eMail")
|
logging.debug("Start POC to eMail")
|
||||||
try:
|
try:
|
||||||
# read subject-structure from config.ini
|
# read subject-structure from config.ini
|
||||||
subject = globals.config.get("eMail", "poc_subject")
|
subject = globalVars.config.get("eMail", "poc_subject")
|
||||||
# replace wildcards with helper function
|
# replace wildcards with helper function
|
||||||
subject = wildcardHandler.replaceWildcards(subject, data)
|
subject = wildcardHandler.replaceWildcards(subject, data)
|
||||||
|
|
||||||
# read mailtext-structure from config.ini
|
# read mailtext-structure from config.ini
|
||||||
mailtext = globals.config.get("eMail", "poc_message")
|
mailtext = globalVars.config.get("eMail", "poc_message")
|
||||||
# replace wildcards with helper function
|
# replace wildcards with helper function
|
||||||
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ def run(typ,freq,data):
|
||||||
# connect to firEmergency
|
# connect to firEmergency
|
||||||
#
|
#
|
||||||
firSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
firSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
firSocket.connect((globals.config.get("firEmergency", "firserver"), globals.config.getint("firEmergency", "firport")))
|
firSocket.connect((globalVars.config.get("firEmergency", "firserver"), globalVars.config.getint("firEmergency", "firport")))
|
||||||
except:
|
except:
|
||||||
logging.error("cannot connect to firEmergency")
|
logging.error("cannot connect to firEmergency")
|
||||||
logging.debug("cannot connect to firEmergency", exc_info=True)
|
logging.debug("cannot connect to firEmergency", exc_info=True)
|
||||||
|
|
|
||||||
|
|
@ -66,13 +66,13 @@ def run(typ,freq,data):
|
||||||
# Create URL
|
# Create URL
|
||||||
#
|
#
|
||||||
if typ == "FMS":
|
if typ == "FMS":
|
||||||
url = globals.config.get("httpRequest", "fms_url") #Get URL
|
url = globalVars.config.get("httpRequest", "fms_url") #Get URL
|
||||||
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
||||||
elif typ == "ZVEI":
|
elif typ == "ZVEI":
|
||||||
url = globals.config.get("httpRequest", "zvei_url") #Get URL
|
url = globalVars.config.get("httpRequest", "zvei_url") #Get URL
|
||||||
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
||||||
elif typ == "POC":
|
elif typ == "POC":
|
||||||
url = globals.config.get("httpRequest", "poc_url") #Get URL
|
url = globalVars.config.get("httpRequest", "poc_url") #Get URL
|
||||||
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -68,15 +68,15 @@ def run(typ,freq,data):
|
||||||
#
|
#
|
||||||
# SOCK_DGRAM is the socket type to use for UDP sockets
|
# SOCK_DGRAM is the socket type to use for UDP sockets
|
||||||
# SOCK_STREAM is the socket type to use for TCP sockets
|
# SOCK_STREAM is the socket type to use for TCP sockets
|
||||||
if globals.config.get("jsonSocket", "protocol") == "TCP":
|
if globalVars.config.get("jsonSocket", "protocol") == "TCP":
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect((globals.config.get("jsonSocket", "server"), globals.config.getint("jsonSocket", "port")))
|
sock.connect((globalVars.config.get("jsonSocket", "server"), globalVars.config.getint("jsonSocket", "port")))
|
||||||
else:
|
else:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
logging.error("cannot initialize %s-socket", globals.config.get("jsonSocket", "protocol"))
|
logging.error("cannot initialize %s-socket", globalVars.config.get("jsonSocket", "protocol"))
|
||||||
logging.debug("cannot initialize %s-socket", globals.config.get("jsonSocket", "protocol"), exc_info=True)
|
logging.debug("cannot initialize %s-socket", globalVars.config.get("jsonSocket", "protocol"), exc_info=True)
|
||||||
# Without connection, plugin couldn't work
|
# Without connection, plugin couldn't work
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -84,22 +84,22 @@ def run(typ,freq,data):
|
||||||
# toDo is equals for all types, so only check if typ is supported
|
# toDo is equals for all types, so only check if typ is supported
|
||||||
supportedTypes = ["FMS", "ZVEI", "POC"]
|
supportedTypes = ["FMS", "ZVEI", "POC"]
|
||||||
if typ in supportedTypes:
|
if typ in supportedTypes:
|
||||||
logging.debug("Start %s to %s", typ, globals.config.get("jsonSocket", "protocol"))
|
logging.debug("Start %s to %s", typ, globalVars.config.get("jsonSocket", "protocol"))
|
||||||
try:
|
try:
|
||||||
# dump data to json-string
|
# dump data to json-string
|
||||||
sendData = json.dumps(data)
|
sendData = json.dumps(data)
|
||||||
# send data
|
# send data
|
||||||
sock.sendto(sendData, (globals.config.get("jsonSocket", "server"), globals.config.getint("jsonSocket", "port")))
|
sock.sendto(sendData, (globalVars.config.get("jsonSocket", "server"), globalVars.config.getint("jsonSocket", "port")))
|
||||||
except:
|
except:
|
||||||
logging.error("%s to %s failed", typ, globals.config.get("jsonSocket", "protocol"))
|
logging.error("%s to %s failed", typ, globalVars.config.get("jsonSocket", "protocol"))
|
||||||
logging.debug("%s to %s failed", typ, globals.config.get("jsonSocket", "protocol"), exc_info=True)
|
logging.debug("%s to %s failed", typ, globalVars.config.get("jsonSocket", "protocol"), exc_info=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.warning("Invalid Typ: %s", typ)
|
logging.warning("Invalid Typ: %s", typ)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
logging.debug("close %s-Connection", globals.config.get("jsonSocket", "protocol"))
|
logging.debug("close %s-Connection", globalVars.config.get("jsonSocket", "protocol"))
|
||||||
try:
|
try:
|
||||||
sock.close()
|
sock.close()
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
|
|
@ -93,17 +93,17 @@ def onLoad():
|
||||||
|
|
||||||
# load config:
|
# load config:
|
||||||
configHandler.checkConfig("notifyMyAndroid")
|
configHandler.checkConfig("notifyMyAndroid")
|
||||||
application = stringConverter.convertToUnicode(globals.config.get("notifyMyAndroid","appName"))
|
application = stringConverter.convertToUnicode(globalVars.config.get("notifyMyAndroid","appName"))
|
||||||
usecsv = globals.config.getboolean("notifyMyAndroid","usecsv")
|
usecsv = globalVars.config.getboolean("notifyMyAndroid","usecsv")
|
||||||
|
|
||||||
# if no csv should use, we take the APIKey directly
|
# if no csv should use, we take the APIKey directly
|
||||||
if usecsv == False:
|
if usecsv == False:
|
||||||
APIKey = globals.config.get("notifyMyAndroid","APIKey")
|
APIKey = globalVars.config.get("notifyMyAndroid","APIKey")
|
||||||
else:
|
else:
|
||||||
# import the csv-file
|
# import the csv-file
|
||||||
try:
|
try:
|
||||||
logging.debug("-- loading nma.csv")
|
logging.debug("-- loading nma.csv")
|
||||||
with open(globals.script_path+'/csv/nma.csv') as csvfile:
|
with open(globalVars.script_path+'/csv/nma.csv') as csvfile:
|
||||||
# DictReader expected structure described in first line of csv-file
|
# DictReader expected structure described in first line of csv-file
|
||||||
reader = csv.DictReader(csvfile)
|
reader = csv.DictReader(csvfile)
|
||||||
for row in reader:
|
for row in reader:
|
||||||
|
|
@ -216,7 +216,7 @@ def run(typ,freq,data):
|
||||||
|
|
||||||
# if not using csv-import, all is simple...
|
# if not using csv-import, all is simple...
|
||||||
if usecsv == False:
|
if usecsv == False:
|
||||||
response = nma.pushWithAPIKey(APIKey, application, event, msg, priority=globals.config.getint("notifyMyAndroid","priority"))
|
response = nma.pushWithAPIKey(APIKey, application, event, msg, priority=globalVars.config.getint("notifyMyAndroid","priority"))
|
||||||
checkResponse(response, APIKey)
|
checkResponse(response, APIKey)
|
||||||
else:
|
else:
|
||||||
if "FMS" in typ:
|
if "FMS" in typ:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue