mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-02-02 21:34:19 +01:00
add data['timestamp'] #72
to make sure, that all Plugins use the same timestamp
This commit is contained in:
parent
28936d68ec
commit
e7b5bffdd3
|
|
@ -11,7 +11,7 @@ Handler for the filter and plugins at an alarm
|
|||
"""
|
||||
|
||||
import logging # Global logger
|
||||
from threading import Thread
|
||||
import time # timestamp
|
||||
|
||||
from includes import globals # Global variables
|
||||
|
||||
|
|
@ -39,6 +39,7 @@ def processAlarmHandler(typ, freq, data):
|
|||
if globals.config.getboolean("BOSWatch","processAlarmAsync") == True:
|
||||
logging.debug("starting processAlarm async")
|
||||
try:
|
||||
from threading import Thread
|
||||
Thread(target=processAlarm, args=(typ, freq, data)).start()
|
||||
except:
|
||||
logging.error("Error in starting alarm processing async")
|
||||
|
|
@ -70,15 +71,17 @@ def processAlarm(typ, freq, data):
|
|||
"""
|
||||
try:
|
||||
logging.debug("[ ALARM ]")
|
||||
# timestamp, to make sure, that all plugins use the same time
|
||||
data['timestamp'] = int(time.time())
|
||||
# Go to all plugins in pluginList
|
||||
for pluginName, plugin in globals.pluginList.items():
|
||||
# if enabled use RegEx-filter
|
||||
if globals.config.getint("BOSWatch","useRegExFilter"):
|
||||
from includes import filter
|
||||
if filter.checkFilters(typ,data,pluginName,freq):
|
||||
if filter.checkFilters(typ, data, pluginName, freq):
|
||||
logging.debug("call Plugin: %s", pluginName)
|
||||
try:
|
||||
plugin.run(typ,freq,data)
|
||||
plugin.run(typ, freq, data)
|
||||
logging.debug("return from: %s", pluginName)
|
||||
except:
|
||||
# call next plugin, if one has thrown an exception
|
||||
|
|
@ -86,7 +89,7 @@ def processAlarm(typ, freq, data):
|
|||
else: # RegEX filter off - call plugin directly
|
||||
logging.debug("call Plugin: %s", pluginName)
|
||||
try:
|
||||
plugin.run(typ,freq,data)
|
||||
plugin.run(typ, freq, data)
|
||||
logging.debug("return from: %s", pluginName)
|
||||
except:
|
||||
# call next plugin, if one has thrown an exception
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ little Helper to get easy the curent date or time
|
|||
for direct use in plugins to save code
|
||||
|
||||
@author: Bastian Schroll
|
||||
@author: Jens Herrmann
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
|
@ -14,39 +15,55 @@ import logging
|
|||
import time
|
||||
|
||||
|
||||
def curtime(format="%d.%m.%Y %H:%M:%S"):
|
||||
def curtime(format="%d.%m.%Y %H:%M:%S", timestamp=""):
|
||||
"""
|
||||
Returns formated date and/or time
|
||||
see: https://docs.python.org/2/library/time.html#time.strftime
|
||||
|
||||
@type format: string
|
||||
@param format: Python time Format-String
|
||||
@type timestamp: floating point number
|
||||
@param timestamp: time in seconds since the epoch
|
||||
|
||||
@return: Formated Time and/or Date
|
||||
@exception: Exception if Error in format
|
||||
"""
|
||||
try:
|
||||
return time.strftime(format)
|
||||
if timestamp == "":
|
||||
return time.strftime(format)
|
||||
else:
|
||||
return time.strftime(format, time.gmtime(timestamp))
|
||||
except:
|
||||
logging.warning("error in time-format-string")
|
||||
logging.debug("error in time-format-string", exc_info=True)
|
||||
|
||||
|
||||
def getDateTime(timestamp=""):
|
||||
"""
|
||||
Returns the date and time
|
||||
|
||||
def getDate():
|
||||
@return: Formated date
|
||||
"""
|
||||
return curtime("%d.%m.%Y %H:%M:%S", timestamp)
|
||||
|
||||
|
||||
def getDate(timestamp=""):
|
||||
"""
|
||||
Returns the date
|
||||
|
||||
@return: Formated date
|
||||
"""
|
||||
return curtime("%d.%m.%Y")
|
||||
return curtime("%d.%m.%Y", timestamp)
|
||||
|
||||
def getTime():
|
||||
|
||||
def getTime(timestamp=""):
|
||||
"""
|
||||
Returns the time
|
||||
|
||||
@return: Formated time
|
||||
"""
|
||||
return curtime("%H:%M:%S")
|
||||
return curtime("%H:%M:%S", timestamp)
|
||||
|
||||
|
||||
def getTimestamp():
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ def replaceWildcards(text, data, lineBrakeAllowed=False):
|
|||
"""
|
||||
try:
|
||||
# replace date and time wildcards
|
||||
text = text.replace("%TIME%", timeHandler.getTime()).replace("%DATE%", timeHandler.getDate())
|
||||
text = text.replace("%TIME%", timeHandler.getTime(data["timestamp"])).replace("%DATE%", timeHandler.getDate(data["timestamp"]))
|
||||
|
||||
# replace some special chars
|
||||
if lineBrakeAllowed == True:
|
||||
|
|
|
|||
|
|
@ -84,13 +84,13 @@ def run(typ,freq,data):
|
|||
logging.debug("Insert %s", typ)
|
||||
|
||||
if typ == "FMS":
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableFMS")+" (time, fms, status, direction, directionText, tsi, description) VALUES (NOW(),%s,%s,%s,%s,%s,%s)", (data["fms"], data["status"], data["direction"], data["directionText"], data["tsi"], data["description"]))
|
||||
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"]))
|
||||
|
||||
elif typ == "ZVEI":
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableZVEI")+" (time, zvei, description) VALUES (NOW(),%s,%s)", (data["zvei"], data["description"]))
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tableZVEI")+" (time, zvei, description) VALUES (FROM_UNIXTIME(%s),%s,%s)", (data["timestamp"], data["zvei"], data["description"]))
|
||||
|
||||
elif typ == "POC":
|
||||
cursor.execute("INSERT INTO "+globals.config.get("MySQL","tablePOC")+" (time, ric, function, functionChar, msg, bitrate, description) VALUES (NOW(),%s,%s,%s,%s,%s,%s)", (data["ric"], data["function"], data["functionChar"], data["msg"], data["bitrate"], data["description"]))
|
||||
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"]))
|
||||
|
||||
else:
|
||||
logging.warning("Invalid Typ: %s", typ)
|
||||
|
|
|
|||
|
|
@ -173,6 +173,7 @@ In the data map are the folowing informations:
|
|||
**ZVEI:**
|
||||
- zvei
|
||||
- description
|
||||
- timestamp
|
||||
|
||||
**FMS:**
|
||||
- fms
|
||||
|
|
@ -181,6 +182,7 @@ In the data map are the folowing informations:
|
|||
- directionText
|
||||
- tsi
|
||||
- description
|
||||
- timestamp
|
||||
|
||||
**POCSAG:**
|
||||
- ric
|
||||
|
|
@ -189,3 +191,4 @@ In the data map are the folowing informations:
|
|||
- msg
|
||||
- bitrate
|
||||
- description
|
||||
- timestamp
|
||||
|
|
@ -11,7 +11,6 @@ eMail-Plugin to dispatch FMS-, ZVEI- and POCSAG - messages via eMail/SMTP
|
|||
|
||||
import logging # Global logger
|
||||
|
||||
import time
|
||||
import smtplib #for the SMTP client
|
||||
from email.mime.text import MIMEText # Import the email modules we'll need
|
||||
from email.utils import formatdate # need for confirm to RFC2822 standard
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ from urlparse import urlparse #for split the URL into url and path
|
|||
|
||||
from includes import globals # Global variables
|
||||
|
||||
from includes.helper import timeHandler
|
||||
from includes.helper import wildcardHandler
|
||||
from includes.helper import configHandler
|
||||
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ def run(typ,freq,data):
|
|||
# build event and msg
|
||||
# pyNMA expect strings are not in UTF-8
|
||||
event = stringConverter.convertToUnicode(data['description'])
|
||||
msg = timeHandler.curtime()
|
||||
msg = timeHandler.getDateTime(data['timestamp'])
|
||||
if ("POC" in typ) and (len(data['msg']) > 0):
|
||||
msg += "\n" + data['msg']
|
||||
msg = stringConverter.convertToUnicode(msg)
|
||||
|
|
|
|||
Loading…
Reference in a new issue