2015-05-18 09:04:16 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: cp1252 -*-
|
|
|
|
|
|
2015-05-18 21:04:10 +02:00
|
|
|
import globals # Global variables
|
2015-05-18 09:04:16 +02:00
|
|
|
import time
|
|
|
|
|
import pluginloader
|
|
|
|
|
|
2015-05-18 21:04:10 +02:00
|
|
|
import os #for absolute path: os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
import ConfigParser #for parse the config file
|
|
|
|
|
|
2015-05-18 12:03:42 +02:00
|
|
|
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
|
|
|
|
|
formatter = logging.Formatter('%(asctime)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()
|
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)
|
2015-05-18 12:03:42 +02:00
|
|
|
|
|
|
|
|
#https://docs.python.org/2/howto/logging.html#logging-basic-tutorial
|
|
|
|
|
#log levels
|
2015-05-18 12:28:18 +02:00
|
|
|
#----------
|
2015-05-18 12:03:42 +02:00
|
|
|
#debug - debug messages only for log
|
2015-05-18 22:10:23 +02:00
|
|
|
#info - information for normal display
|
2015-05-18 12:03:42 +02:00
|
|
|
#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-18 21:04:10 +02:00
|
|
|
#ConfigParser
|
|
|
|
|
try:
|
2015-05-18 21:49:03 +02:00
|
|
|
logging.debug("reading config file")
|
2015-05-18 21:04:10 +02:00
|
|
|
script_path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
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
|
|
|
|
2015-05-18 21:04:10 +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-18 21:59:11 +02:00
|
|
|
time.sleep(1)
|
|
|
|
|
logging.info("Alarm!")
|
|
|
|
|
for i in pluginloader.getPlugins():
|
|
|
|
|
plugin = pluginloader.loadPlugin(i)
|
|
|
|
|
logging.debug(i["name"] + " Plugin called")
|
|
|
|
|
plugin.run("POC","80000000",data)
|