mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2025-12-06 07:42:03 +01:00
commit
e2b4ef82c9
|
|
@ -16,7 +16,7 @@ template = 1
|
|||
bosmon_server = 192.168.0.1
|
||||
bosmon_port = 80
|
||||
#channel-name of typ "Web-Telegramm"
|
||||
bosmon_channel = channelname
|
||||
#Use this, when you have security enabled
|
||||
bosmon_user = user
|
||||
bosmon_password = password
|
||||
bosmon_channel = pocsag
|
||||
#Use this, when BosMon has restricted access
|
||||
bosmon_user =
|
||||
bosmon_password =
|
||||
|
|
|
|||
17
plugin_test/plugin_test.py
Normal file → Executable file
17
plugin_test/plugin_test.py
Normal file → Executable file
|
|
@ -1,9 +1,13 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
import globals # Global variables
|
||||
import time
|
||||
import pluginloader
|
||||
|
||||
import os #for absolute path: os.path.dirname(os.path.abspath(__file__))
|
||||
import ConfigParser #for parse the config file
|
||||
|
||||
#create new logger
|
||||
import logging
|
||||
logger = logging.getLogger()
|
||||
|
|
@ -34,8 +38,17 @@ logger.addHandler(ch)
|
|||
#exception - error handler in try:exc: into the message
|
||||
#critical - critical error, program exit
|
||||
|
||||
#ConfigParser
|
||||
logging.info("reading config file")
|
||||
try:
|
||||
script_path = os.path.dirname(os.path.abspath(__file__))
|
||||
globals.config = ConfigParser.ConfigParser()
|
||||
globals.config.read(script_path+"/config/config.ini")
|
||||
except:
|
||||
logging.error("cannot read config file","error")
|
||||
|
||||
data = {"zvei":"12345"}
|
||||
#data = {"zvei":"12345"}
|
||||
data = {"ric":"1234567", "function":"1", "msg":"Hello World!"}
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
|
@ -43,4 +56,4 @@ while True:
|
|||
for i in pluginloader.getPlugins():
|
||||
logging.debug("Load Plugin: " + i["name"])
|
||||
plugin = pluginloader.loadPlugin(i)
|
||||
plugin.run("zvei","80000000",data)
|
||||
plugin.run("POC","80000000",data)
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
import logging # Global logger
|
||||
import globals # Global variables
|
||||
import imp
|
||||
import os
|
||||
|
||||
|
|
@ -12,10 +14,20 @@ def getPlugins():
|
|||
possibleplugins = os.listdir(PluginFolder)
|
||||
for i in possibleplugins:
|
||||
location = os.path.join(PluginFolder, i)
|
||||
# plugins have to be a subdir with MainModule, if not skip
|
||||
if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location):
|
||||
continue
|
||||
info = imp.find_module(MainModule, [location])
|
||||
plugins.append({"name": i, "info": info})
|
||||
logging.debug("found plugin: "+i)
|
||||
# is the plugin enabled in the config-file?
|
||||
try:
|
||||
usePlugin = int(globals.config.get("Module", i))
|
||||
except: #no entry for plugin found in config-file, skip
|
||||
continue
|
||||
logging.debug("use Plugin: "+str(usePlugin))
|
||||
if usePlugin:
|
||||
info = imp.find_module(MainModule, [location])
|
||||
plugins.append({"name": i, "info": info})
|
||||
logging.debug("append Plugin: "+i)
|
||||
return plugins
|
||||
|
||||
def loadPlugin(plugin):
|
||||
|
|
|
|||
|
|
@ -1,10 +1,60 @@
|
|||
import logging
|
||||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
import logging # Global logger
|
||||
import globals # Global variables
|
||||
|
||||
import httplib #for the HTTP request
|
||||
import urllib #for the HTTP request with parameters
|
||||
import base64 #for the HTTP request with User/Password
|
||||
|
||||
def run(typ,frequenz,daten):
|
||||
logging.debug("Throw Template Plugin")
|
||||
try:
|
||||
logging.info("ZVEI: %s wurde empfangen!", daten[0])
|
||||
logging.debug("try 5/0")
|
||||
test = 5/0
|
||||
except:
|
||||
logging.exception("Error in Template Plugin")
|
||||
logging.debug("BosMon Plugin called")
|
||||
logging.debug(" - typ: " +typ)
|
||||
try:
|
||||
#get BosMon-Config
|
||||
bosmon_server = globals.config.get("BosMon", "bosmon_server")
|
||||
bosmon_port = globals.config.get("BosMon", "bosmon_port")
|
||||
bosmon_user = globals.config.get("BosMon", "bosmon_user")
|
||||
bosmon_password = globals.config.get("BosMon", "bosmon_password")
|
||||
bosmon_channel = globals.config.get("BosMon", "bosmon_channel")
|
||||
logging.debug(" - Server: " +bosmon_server)
|
||||
logging.debug(" - Port: " +bosmon_port)
|
||||
logging.debug(" - User: " +bosmon_user)
|
||||
logging.debug(" - Channel: " +bosmon_channel)
|
||||
|
||||
if typ == "FMS":
|
||||
logging.warning("FMS not implemented in BosMon plugin")
|
||||
|
||||
elif typ == "ZVEI":
|
||||
logging.warning("ZVEI not implemented in BosMon plugin")
|
||||
|
||||
elif typ == "POC":
|
||||
logging.debug("Start POC to BosMon")
|
||||
try:
|
||||
#Defined data structure:
|
||||
# daten["ric"]
|
||||
# daten["function"]
|
||||
# daten["msg"]
|
||||
#BosMon-Telegramin expected "a-d" as RIC-sub/function
|
||||
daten["function"] = daten["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d")
|
||||
params = urllib.urlencode({'type':'pocsag', 'address':daten["ric"], 'flags':'0', 'function':daten["function"], 'message':daten["msg"]})
|
||||
logging.debug(" - Params:" +params)
|
||||
headers = {}
|
||||
headers['Content-type'] = "application/x-www-form-urlencoded"
|
||||
headers['Accept'] = "text/plain"
|
||||
if bosmon_user:
|
||||
headers['Authorization'] = "Basic {0}".format(base64.b64encode("{0}:{1}".format(bosmon_user, bosmon_password)))
|
||||
httprequest = httplib.HTTPConnection(bosmon_server, bosmon_port)
|
||||
httprequest.request("POST", "/telegramin/"+bosmon_channel+"/input.xml", params, headers)
|
||||
httpresponse = httprequest.getresponse()
|
||||
if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error
|
||||
logging.debug("BosMon response: "+str(httpresponse.status)+" - "+str(httpresponse.reason))
|
||||
else:
|
||||
logging.warning("BosMon response: "+str(httpresponse.status)+" - "+str(httpresponse.reason))
|
||||
except:
|
||||
logging.warning("POC to BosMon failed")
|
||||
else:
|
||||
logging.warning("typ '"+typ+"' undefined in BosMon plugin")
|
||||
except:
|
||||
logging.exception("Error in BosMon Plugin")
|
||||
|
|
@ -15,5 +15,12 @@ FMS:
|
|||
|
||||
POCSAG:
|
||||
- ric
|
||||
- sub_ric
|
||||
- text
|
||||
- function
|
||||
- msg
|
||||
|
||||
Es stehen folgende globale Objecte zur Verfügung:
|
||||
1.) import logging # Global logger
|
||||
logging - Object
|
||||
|
||||
2.) import globals # Global variables
|
||||
config - Object (typ: ConfigParser, stellt config.ini bereit)
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
import logging
|
||||
#!/usr/bin/python
|
||||
# -*- coding: cp1252 -*-
|
||||
|
||||
import logging # Global logger
|
||||
import globals # Global variables
|
||||
|
||||
def run(typ,freq,data):
|
||||
logging.debug("Strat Plugin: template")
|
||||
|
|
|
|||
Loading…
Reference in a new issue