config files, mail updates
authorAndrew Lorimer <andrew@charles.cortex>
Sun, 26 Aug 2018 10:27:34 +0000 (20:27 +1000)
committerAndrew Lorimer <andrew@charles.cortex>
Sun, 26 Aug 2018 10:27:34 +0000 (20:27 +1000)
logparse.py
logparse.yaml [changed mode: 0644->0755]
index 0ec21b5af90a13d2420917069a759916a0e8a22e..4035e0c6b7c1eb743198719ed9b48a65f7ff78b3 100755 (executable)
@@ -5,6 +5,9 @@ from sys import stdin
 from collections import namedtuple, defaultdict
 from shutil import copyfile
 import yaml
 from collections import namedtuple, defaultdict
 from shutil import copyfile
 import yaml
+import ast
+import logging.handlers
+import types
 
 reload(sys)
 sys.setdefaultencoding('utf-8')
 
 reload(sys)
 sys.setdefaultencoding('utf-8')
@@ -69,6 +72,10 @@ DEG = " &deg;C".encode('unicode_escape')
 # Set up logging
 logging.basicConfig(level=logging.DEBUG)
 logger = logging.getLogger('logparse')
 # 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')
 
 # 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'])
     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")
         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:
     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'])
             else:
                 config[value] = data[value]
         config['dest'] = os.path.dirname(config['output'])
old mode 100644 (file)
new mode 100755 (executable)