diff --git a/boswatch.py b/boswatch.py index 972f192..33dbc65 100755 --- a/boswatch.py +++ b/boswatch.py @@ -7,8 +7,8 @@ Python Script to receive and decode German BOS Information with rtl_fm and multi Through a simple plugin system, data can easily be transferred to other applications For more Information see the README.md -Autor: Bastian Schroll -Autor: Jens Hermann +@author: Bastian Schroll +@author: Jens Herrmann GitHUB: https://github.com/Schrolli91/BOSWatch """ @@ -25,7 +25,9 @@ import subprocess from includes import globals # Global variables ## +# # This Class extended the TimedRotatingFileHandler with the possibility to change the backupCount after initialization. +# ## class MyTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler): """Extended Version of TimedRotatingFileHandler""" diff --git a/config/config.template.ini b/config/config.template.ini index 99d9924..065650f 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -19,7 +19,7 @@ backupCount = 7 #Using RegEx-Filter (0|1) #Filter-configuration in section [Filters] -useRegExFilter = 1 +useRegExFilter = 0 [FMS] #time to ignore same alarm in a row (sek) @@ -118,7 +118,7 @@ fms_url = zvei_url = # %RIC% = Pocsag RIC -# %FUNC% = Pocsac fcuntion/Subric +# %FUNC% = Pocsac function/Subric # %MSG% = Message of the Pocsag telegram # %BITRATE% = Bitrate of the Pocsag telegram #poc_url = www.google.de?ric=%RIC%&subric=%FUNC%&msg=%MSG% diff --git a/includes/decoders/fms.py b/includes/decoders/fms.py index 7ad12fa..1f7dfa1 100644 --- a/includes/decoders/fms.py +++ b/includes/decoders/fms.py @@ -15,8 +15,11 @@ import re #Regex for validation from includes import globals # Global variables -#FMS Decoder Function -#validate -> check double alarm -> log +## +# +# FMS Decoder Function +# validate -> check double alarm -> log +# def decode(freq, decoded): """ Export FMS Information from Multimon-NG RAW String and call alarmHandler.processAlarm() diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index c879246..f4fd313 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -5,7 +5,7 @@ POCSAG Decoder @author: Bastian Schroll -@author: Jens Hermann +@author: Jens Herrmann @requires: Configuration has to be set in the config.ini """ @@ -16,7 +16,10 @@ import re #Regex for validation from includes import globals # Global variables +## +# # Simple Filter +# def isAllowed(poc_id): """ Simple Filter Functions (Allowed, Denied and Range) @@ -51,9 +54,11 @@ def isAllowed(poc_id): return False return True - -#POCSAG Decoder Function -#validate -> check double alarm -> log +## +# +# POCSAG Decoder Function +# validate -> check double alarm -> log +# def decode(freq, decoded): """ Export POCSAG Information from Multimon-NG RAW String and call alarmHandler.processAlarm() diff --git a/includes/decoders/zvei.py b/includes/decoders/zvei.py index 28f9255..1d87f12 100644 --- a/includes/decoders/zvei.py +++ b/includes/decoders/zvei.py @@ -15,8 +15,11 @@ import re #Regex for validation from includes import globals # Global variables -#ZVEI Decoder Function -#validate -> check double alarm -> log +## +# +# ZVEI Decoder Function +# validate -> check double alarm -> log +# def decode(freq, decoded): """ Export ZVEI Information from Multimon-NG RAW String and call alarmHandler.processAlarm() diff --git a/includes/globals.py b/includes/globals.py index 1169b29..b96e81b 100644 --- a/includes/globals.py +++ b/includes/globals.py @@ -4,7 +4,7 @@ """ Global variables -@author: Jens Hermann +@author: Jens Herrmann @author: Bastian Schroll """ diff --git a/includes/shellHeader.py b/includes/shellHeader.py index 7f5e468..b1bcb52 100644 --- a/includes/shellHeader.py +++ b/includes/shellHeader.py @@ -5,7 +5,7 @@ Shows the Header in Shell if quiet Mode is not active @author: Bastian Schroll -@author: Jens Hermann +@author: Jens Herrmann @requires: none """ diff --git a/plugins/BosMon/BosMon.py b/plugins/BosMon/BosMon.py index 3c20533..e91351a 100644 --- a/plugins/BosMon/BosMon.py +++ b/plugins/BosMon/BosMon.py @@ -25,7 +25,7 @@ from includes import globals # Global variables # def bosMonRequest(httprequest, params, headers): """ - Local function to dispatch the BosMon-Request + This local function dispatch the BosMon-Request @type httprequest: HTTPConnection @param httprequest: An HTTPConnection-Object that represents an open connection to a BosMon-Instance @@ -38,10 +38,16 @@ def bosMonRequest(httprequest, params, headers): @exception: Exception if httprequest.request failed """ try: + # + # BosMon/HTTP-Request + # httprequest.request("POST", "/telegramin/"+globals.config.get("BosMon", "bosmon_channel")+"/input.xml", params, headers) except: logging.exception("request to BosMon failed") else: + # + # check HTTP-Response + # httpresponse = httprequest.getresponse() if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error logging.debug("BosMon response: %s - %s", str(httpresponse.status), str(httpresponse.reason)) diff --git a/plugins/MySQL/MySQL.py b/plugins/MySQL/MySQL.py index be19b3e..887d314 100644 --- a/plugins/MySQL/MySQL.py +++ b/plugins/MySQL/MySQL.py @@ -1,6 +1,16 @@ #!/usr/bin/python # -*- coding: cp1252 -*- +""" +MySQL-Plugin to dispatch FMS-, ZVEI- and POCSAG - messages to a MySQL database + +@author: Jens Herrmann +@author: Bastian Schroll + +@requires: MySQL-Configuration has to be set in the config.ini +@requires: Created Database/Tables, see boswatch.sql +""" + import logging # Global logger import mysql @@ -9,7 +19,35 @@ import mysql.connector from includes import globals # Global variables +## +# +# Main function of MySQL-plugin +# will be called by the alarmHandler +# def run(typ,freq,data): + """ + This function is the implementation of the MySQL-Plugin. + It will store the data to an MySQL database + + The configuration for the MySQL-Connection is set in the config.ini. + For DB- and tablestructure see boswatch.sql + + @type typ: string (FMS|ZVEI|POC) + @param typ: Typ of the dataset for sending to BosMon + @type data: map of data (structure see interface.txt) + @param data: Contains the parameter for dispatch to BosMon. + @type freq: string + @keyword freq: frequency is not used in this plugin + + @requires: MySQL-Configuration has to be set in the config.ini + @requires: Created Database/Tables, see boswatch.sql + + @return: nothing + @exception: Exception if ConfigParser failed + @exception: Exception if connect to MySQL failed + @exception: Exception if executing the sql-statement is failed + """ + try: #ConfigParser logging.debug("reading config file") @@ -20,14 +58,19 @@ def run(typ,freq,data): logging.exception("cannot read config file") try: + # + # 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")) cursor = connection.cursor() except: logging.exception("cannot connect to MySQL") else: - try: + # + # Create and execute SQL-statement + # logging.debug("Insert %s", typ) if typ == "FMS": diff --git a/plugins/httpRequest/httpRequest.py b/plugins/httpRequest/httpRequest.py index b36f21a..da48450 100644 --- a/plugins/httpRequest/httpRequest.py +++ b/plugins/httpRequest/httpRequest.py @@ -16,6 +16,11 @@ from urlparse import urlparse #for split the URL into url and path from includes import globals # Global variables +## +# +# Main function of HTTP-plugin +# will be called by the alarmHandler +# def run(typ,freq,data): """ This function is the implementation of the httpRequest-Plugin. @@ -36,7 +41,9 @@ def run(typ,freq,data): @exception: Exception if http Response failed """ try: - #ConfigParser + # + # ConfigParser + # logging.debug("reading config file") try: for key,val in globals.config.items("httpRequest"): @@ -45,6 +52,9 @@ def run(typ,freq,data): logging.exception("cannot read config file") try: + # + # Create URL + # logging.debug("send %s HTTP request", typ) if typ == "FMS": @@ -61,15 +71,20 @@ def run(typ,freq,data): else: logging.warning("Invalid Typ: %s", typ) - url = urlparse(url)#split URL into path and querry + # + # HTTP-Request + # + url = urlparse(url) #split URL into path and querry httprequest = httplib.HTTPConnection(url[2]) #connect to URL Path httprequest.request("GET", url[5]) #send URL Querry per GET except: logging.exception("cannot send HTTP request") else: - - try: + try: + # + # check HTTP-Response + # httpresponse = httprequest.getresponse() if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error logging.debug("HTTP response: %s - %s" , str(httpresponse.status), str(httpresponse.reason))