mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-05 06:25:10 +00:00
add data['timestamp'] #72
to make sure, that all Plugins use the same timestamp
This commit is contained in:
parent
28936d68ec
commit
e7b5bffdd3
8 changed files with 38 additions and 17 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue