diff --git a/boswatch.py b/boswatch.py index 160b83e..acd98eb 100755 --- a/boswatch.py +++ b/boswatch.py @@ -402,6 +402,10 @@ finally: finally: # Close Logging logging.debug("close Logging") + # Waiting for all Threads to write there logs + if globals.config.getboolean("BOSWatch","processAlarmAsync") == True: + logging.debug("waiting 3s for threads...") + time.sleep(3) logging.info("BOSWatch exit()") logging.shutdown() if nmaHandler: diff --git a/config/config.template.ini b/config/config.template.ini index b319042..4bf993b 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -23,6 +23,12 @@ backupCount = 7 #rtl_path = /usr/local/bin/ #multimon_path = /usr/local/bin/ +# if you are using many Plugins or Plugins with a long execution time +# you could execute them in an asynchronous manner +# It must be pointed out that enabling (0|1) this consume time, +# so don't use it for one rapid Plugin +processAlarmAsync = 0 + # Using RegEx-Filter (0|1) # Filter-configuration in section [Filters] useRegExFilter = 0 diff --git a/includes/MyTimedRotatingFileHandler.py b/includes/MyTimedRotatingFileHandler.py index 348d4d1..f33dd40 100644 --- a/includes/MyTimedRotatingFileHandler.py +++ b/includes/MyTimedRotatingFileHandler.py @@ -16,3 +16,8 @@ class MyTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler): def setBackupCount(self, backupCount): """Set/Change backupCount""" self.backupCount = backupCount + + def close(self): + """Make shure logfile will be flushed""" + self.flush() + super(self.__class__, self).close() diff --git a/includes/alarmHandler.py b/includes/alarmHandler.py index 6176a10..fba318d 100644 --- a/includes/alarmHandler.py +++ b/includes/alarmHandler.py @@ -11,14 +11,48 @@ Handler for the filter and plugins at an alarm """ import logging # Global logger +from threading import Thread from includes import globals # Global variables +## +# +# decide to run AlarmHandler sync or async +# +def processAlarmHandler(typ, freq, data): + """ + Function to decide if the alarm process will call sync + + @type typ: string (FMS|ZVEI|POC) + @param typ: Typ of the dataset + @type freq: string + @param freq: frequency of the SDR Stick + @type data: map of data (structure see interface.txt) + @param data: Contains the parameter + + @requires: active plugins in pluginList + @requires: Configuration has to be set in the config.ini + + @return: nothing + @exception: Exception if starting a Thread failed + """ + if globals.config.getboolean("BOSWatch","processAlarmAsync") == True: + logging.debug("starting processAlarm async") + try: + Thread(target=processAlarm, args=(typ, freq, data)).start() + except: + logging.error("Error in starting alarm processing async") + logging.debug("Error in starting alarm processing async", exc_info=True) + pass + else: + processAlarm(typ, freq, data) + + ## # # main function for central filtering and calling the plugins # -def processAlarm(typ,freq,data): +def processAlarm(typ, freq, data): """ Function to process filters and plugins at Alarm @@ -59,4 +93,6 @@ def processAlarm(typ,freq,data): pass logging.debug("[END ALARM]") except: - logging.exception("Error in alarm processing") + logging.error("Error in alarm processing") + logging.debug("Error in alarm processing", exc_info=True) + pass diff --git a/includes/decoders/fms.py b/includes/decoders/fms.py index 913119d..dd606bb 100644 --- a/includes/decoders/fms.py +++ b/includes/decoders/fms.py @@ -22,7 +22,7 @@ from includes import doubleFilter # double alarm filter # def decode(freq, decoded): """ - Export FMS Information from Multimon-NG RAW String and call alarmHandler.processAlarm() + Export FMS Information from Multimon-NG RAW String and call alarmHandler.processAlarmHandler() @type freq: string @param freq: frequency of the SDR Stick @@ -59,7 +59,7 @@ def decode(freq, decoded): # processing the alarm try: from includes import alarmHandler - alarmHandler.processAlarm("FMS", freq, data) + alarmHandler.processAlarmHandler("FMS", freq, data) except: logging.error("processing alarm failed") logging.debug("processing alarm failed", exc_info=True) diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index 20f393e..8b3d727 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -61,7 +61,7 @@ def isAllowed(poc_id): # def decode(freq, decoded): """ - Export POCSAG Information from Multimon-NG RAW String and call alarmHandler.processAlarm() + Export POCSAG Information from Multimon-NG RAW String and call alarmHandler.processAlarmHandler() @type freq: string @param freq: frequency of the SDR Stick @@ -117,7 +117,7 @@ def decode(freq, decoded): # processing the alarm try: from includes import alarmHandler - alarmHandler.processAlarm("POC", freq, data) + alarmHandler.processAlarmHandler("POC", freq, data) except: logging.error("processing alarm failed") logging.debug("processing alarm failed", exc_info=True) diff --git a/includes/decoders/zvei.py b/includes/decoders/zvei.py index 21848f5..a3181ad 100644 --- a/includes/decoders/zvei.py +++ b/includes/decoders/zvei.py @@ -44,7 +44,7 @@ def removeF(zvei): # def decode(freq, decoded): """ - Export ZVEI Information from Multimon-NG RAW String and call alarmHandler.processAlarm() + Export ZVEI Information from Multimon-NG RAW String and call alarmHandler.processAlarmHandler() @type freq: string @param freq: frequency of the SDR Stick @@ -71,7 +71,7 @@ def decode(freq, decoded): # processing the alarm try: from includes import alarmHandler - alarmHandler.processAlarm("ZVEI", freq, data) + alarmHandler.processAlarmHandler("ZVEI", freq, data) except: logging.error("processing alarm failed") logging.debug("processing alarm failed", exc_info=True)