mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2025-12-06 07:42:03 +01:00
76 lines
1.8 KiB
Python
Executable file
76 lines
1.8 KiB
Python
Executable file
#!/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
|
|
|
|
import logging
|
|
|
|
#create new logger
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
#set log string format
|
|
formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %I:%M:%S')
|
|
|
|
#create a file loger
|
|
fh = logging.FileHandler('boswatch.log', 'w')
|
|
fh.setLevel(logging.DEBUG) #log level >= Debug
|
|
fh.setFormatter(formatter)
|
|
logger.addHandler(fh)
|
|
|
|
#create a display loger
|
|
ch = logging.StreamHandler()
|
|
ch.setLevel(logging.INFO) #log level >= info
|
|
ch.setFormatter(formatter)
|
|
logger.addHandler(ch)
|
|
|
|
#https://docs.python.org/2/howto/logging.html#logging-basic-tutorial
|
|
#log levels
|
|
#----------
|
|
#debug - debug messages only for log
|
|
#info - information for normal display
|
|
#warning
|
|
#error - normal error - program goes further
|
|
#exception - error with exception message in log
|
|
#critical - critical error, program exit
|
|
|
|
#configparser
|
|
try:
|
|
logging.debug("reading config file")
|
|
script_path = os.path.dirname(os.path.abspath(__file__))
|
|
globals.config = configparser.ConfigParser()
|
|
globals.config.read(script_path+"/config/config.ini")
|
|
except:
|
|
logging.exception("cannot read config file")
|
|
|
|
#data = {"zvei":"12345"}
|
|
data = {"ric":"1234567", "function":"1", "msg":"Hello World!"}
|
|
|
|
#read Plugins
|
|
pluginlist = []
|
|
for i in pluginloader.getPlugins():
|
|
plugin = pluginloader.loadPlugin(i)
|
|
print(plugin)
|
|
pluginlist.append(plugin)
|
|
|
|
print()
|
|
|
|
for i in pluginlist:
|
|
print(i)
|
|
|
|
exit()
|
|
while True:
|
|
try:
|
|
time.sleep(1)
|
|
logging.info("Alarm!")
|
|
for plugin in pluginList:
|
|
logging.info(plugin)
|
|
plugin.run("POC","80000000",data)
|
|
except:
|
|
logging.exception("Cannot Throw Modules")
|
|
exit() |