from collections import namedtuple, defaultdict
from shutil import copyfile
import yaml
+import ast
+import logging.handlers
+import types
reload(sys)
sys.setdefaultencoding('utf-8')
# Set up logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('logparse')
+loghandler = logging.handlers.SysLogHandler(address = '/dev/log')
+loghandler.setFormatter(logging.Formatter(fmt='logparse.py[' + str(os.getpid()) + ']: %(message)s'))
+logger.addHandler(loghandler)
+
# Get arguments
parser = argparse.ArgumentParser(description='grab logs of some common services and send them by email')
if (to != None):
logger.debug("sending email")
ms = subject(config['mail']['subject'])
- cmd = "cat " + MAILPATH + " | mail --debug-level=10 -a 'Content-type: text/html' -s '" + ms + "' " + to
+ cmd = "cat " + MAILPATH + " | mail --debug-level=10 -a 'Content-type: text/html' -s '" + ms + "' " + to
logger.debug(cmd)
subprocess.call(cmd, shell=True)
logger.info("sent email")
try:
data = yaml.safe_load(open(configfile))
for value in data:
- if (type(value) == dict):
- config[value][key] = (data[value][key] for key in value)
+ logger.debug(data[value])
+ if(type(data[value]) == types.DictType):
+ for key in data[value].iteritems():
+ config[value][key[0]] = key[1]
else:
config[value] = data[value]
config['dest'] = os.path.dirname(config['output'])