BOSWatch/plugin_test.py

64 lines
1.7 KiB
Python
Raw Normal View History

2015-05-18 09:04:16 +02:00
#!/usr/bin/python
# -*- coding: cp1252 -*-
import globals # Global variables
2015-05-18 09:04:16 +02:00
import time
import pluginloader
import os #for absolute path: os.path.dirname(os.path.abspath(__file__))
2015-05-19 15:42:25 +02:00
import ConfigParser #for parse the config file
import logging
2015-05-18 21:49:03 +02:00
#create new logger
2015-05-18 12:28:18 +02:00
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
#set log string format
2015-05-19 14:30:03 +02:00
formatter = logging.Formatter('%(asctime)s - %(module)s [%(levelname)s] %(message)s', '%d.%m.%Y %H:%M:%S')
2015-05-18 12:28:18 +02:00
#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()
2015-05-18 22:10:23 +02:00
ch.setLevel(logging.INFO) #log level >= info
2015-05-18 12:28:18 +02:00
ch.setFormatter(formatter)
logger.addHandler(ch)
#https://docs.python.org/2/howto/logging.html#logging-basic-tutorial
#log levels
2015-05-18 12:28:18 +02:00
#----------
#debug - debug messages only for log
2015-05-18 22:10:23 +02:00
#info - information for normal display
#warning
#error - normal error - program goes further
2015-05-18 21:49:03 +02:00
#exception - error with exception message in log
2015-05-18 14:49:10 +02:00
#critical - critical error, program exit
2015-05-18 12:28:18 +02:00
2015-05-19 07:29:39 +02:00
#configparser
try:
2015-05-18 21:49:03 +02:00
logging.debug("reading config file")
script_path = os.path.dirname(os.path.abspath(__file__))
2015-05-19 15:42:25 +02:00
globals.config = ConfigParser.ConfigParser()
globals.config.read(script_path+"/config/config.ini")
except:
2015-05-18 21:49:03 +02:00
logging.exception("cannot read config file")
2015-05-18 12:28:18 +02:00
#data = {"zvei":"12345"}
data = {"ric":"1234567", "function":"1", "msg":"Hello World!"}
2015-05-18 12:28:18 +02:00
2015-05-18 09:04:16 +02:00
while True:
2015-05-19 07:29:39 +02:00
try:
time.sleep(1)
logging.info("Alarm!")
2015-05-19 09:36:17 +02:00
for i in pluginloader.getPlugins():
plugin = pluginloader.loadPlugin(i)
logging.debug(i["name"] + " Plugin called")
2015-05-19 07:29:39 +02:00
plugin.run("POC","80000000",data)
except:
logging.exception("Cannot Throw Modules")
exit()