From: Andrew Lorimer Date: Sun, 26 Aug 2018 10:27:34 +0000 (+1000) Subject: config files, mail updates X-Git-Url: https://git.lorimer.id.au/logparse.git/diff_plain/f96a0f29c49c06e78933187370fdb776bb196a80 config files, mail updates --- diff --git a/logparse.py b/logparse.py index 0ec21b5..4035e0c 100755 --- a/logparse.py +++ b/logparse.py @@ -5,6 +5,9 @@ from sys import stdin from collections import namedtuple, defaultdict from shutil import copyfile import yaml +import ast +import logging.handlers +import types reload(sys) sys.setdefaultencoding('utf-8') @@ -69,6 +72,10 @@ DEG = " °C".encode('unicode_escape') # 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') @@ -105,7 +112,7 @@ def __main__(): 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") @@ -728,8 +735,10 @@ def loadconf(configfile): 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']) diff --git a/logparse.yaml b/logparse.yaml old mode 100644 new mode 100755