'from': '',
'subject': 'logparse from $hostname$'
},
- 'rotate': 1,
+ 'rotate': 'y',
'hddtemp': {
'drives': ['/dev/sda'],
'port': 7634
# Get arguments
parser = argparse.ArgumentParser(description='grab logs of some common services and send them by email')
parser.add_argument('-t','--to', help='mail recipient (\"to\" address)',required=False)
-to = parser.parse_args().to
def __main__():
logger.info("Beginning log analysis at " + str(datenow) + ' ' + str(timenow))
- if (to == None):
+ loadconf(scriptdir + "/logparse.yaml")
+
+ if (config['mail']['to'] == None):
logger.info("no recipient address provided, outputting to stdout")
else:
- logger.info("email will be sent to " + to)
+ logger.info("email will be sent to " + config['mail']['to'])
- loadconf(scriptdir + "/logparse.yaml")
+ global pathfilter
+ global pathpattern
+ pathfilter = {"auth": config['logs']['auth'], "cron": config['logs']['cron'], "sys": config['logs']['sys'], "postfix": config['logs']['postfix'], "smb": config['logs']['smb'], "zfs": config['logs']['zfs'], "alloc": config['logs']['alloc'], "httpd": config['logs']['httpd'], "header": config['header']}
+ pathfilter = dict((re.escape(k), v) for k, v in pathfilter.iteritems())
+ pathpattern = re.compile("|".join(pathfilter.keys()))
+
+ global varfilter
+ global varpattern
+ varfilter = {"$title$": config['title'], "$date$": datenow, "$time$": timenow, "$hostname$": hostname(), "$version$": VERSION, "$css$": os.path.relpath(config['css'], os.path.dirname(config['output']))}
+ varfilter = dict((re.escape(k), v) for k, v in varfilter.iteritems())
+ varpattern = re.compile("|".join(varfilter.keys()))
global tempfile
tempfile = open(config['output'], 'w+')
closetag(tag, 1)
tempfile.close()
mailprep(config['output'], MAILPATH)
- if (to != None):
+ if (config['mail']['to'] != None):
logger.debug("sending email")
ms = subject(config['mail']['subject'])
- cmd = "/bin/cat " + MAILPATH + " | /usr/bin/mail --debug-level=10 -a 'Content-type: text/html' -s '" + ms + "' " + to
+ cmd = "/bin/cat " + MAILPATH + " | /usr/bin/mail --debug-level=10 -a 'Content-type: text/html' -s '" + ms + "' " + config['mail']['to']
logger.debug(cmd)
subprocess.call(cmd, shell=True)
logger.info("sent email")
#
#
#
-
+starttime = datetime.datetime.now()
timenow = time.strftime("%H:%M:%S")
datenow = time.strftime("%x")
-pathfilter = {"auth": config['logs']['auth'], "cron": config['logs']['cron'], "sys": config['logs']['sys'], "postfix": config['logs']['postfix'], "smb": config['logs']['smb'], "zfs": config['logs']['zfs'], "alloc": config['logs']['alloc'], "httpd": config['logs']['httpd'], "header": config['header']}
-pathfilter = dict((re.escape(k), v) for k, v in pathfilter.iteritems())
-pathpattern = re.compile("|".join(pathfilter.keys()))
-
-varfilter = {"$title$": config['title'], "$date$": datenow, "$time$": timenow, "$hostname$": hostname(), "$version$": VERSION, "$css$": config['css']}
-varfilter = dict((re.escape(k), v) for k, v in varfilter.iteritems())
-varpattern = re.compile("|".join(varfilter.keys()))
-
def loadconf(configfile):
try:
data = yaml.safe_load(open(configfile))
else:
config[value] = data[value]
config['dest'] = os.path.dirname(config['output'])
+ logger.debug(str(type(parser.parse_args().to)))
+ logger.debug(config['mail']['to'])
+ if parser.parse_args().to is not None: config['mail']['to'] = parser.parse_args().to
logger.debug(str(config))
except Exception as e:
logger.warning("error processing config: " + str(e))
__main__()
finally:
# rotate logs using systemd logrotate
- if (config['rotate'] == 1):
+ if (config['rotate'] == 'y'):
subprocess.call("/usr/sbin/logrotate -f /etc/logrotate.conf", shell=True)
logger.info("rotated logfiles")
else:
- logger.info("user doesn't want to rotate logs")
- logger.debug("Here is the output of `logrotate -d /etc/logrotate.conf` (simulated):")
- sim = subprocess.check_output("/usr/sbin/logrotate -d /etc/logrotate.conf", shell=True)
- logger.debug(sim)
+ logger.debug("user doesn't want to rotate logs")
+ if (config['rotate'] == 's'):
+ logger.debug("Here is the output of `logrotate -d /etc/logrotate.conf` (simulated):")
+ sim = subprocess.check_output("/usr/sbin/logrotate -d /etc/logrotate.conf", shell=True)
+ logger.debug(sim)
+
timenow = time.strftime("%H:%M:%S")
datenow = time.strftime("%x")
- logger.info("finished parsing logs at " + str(datenow) + ' ' + str(timenow))
+ logger.info("finished parsing logs at " + datetime.datetime.now().strftime("%x %H:%M:%S") + " (" + str(datetime.datetime.now() - starttime) + ")")