mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-04 14:07:25 +00:00
a little bit documentation
This commit is contained in:
parent
1ee27afbf0
commit
0a621b283a
10 changed files with 97 additions and 20 deletions
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue