logparse / parsers / cron.pyon commit finish initial plugin system, get email and other features working (d8d26ab)
   1#
   2#   cron.py
   3#
   4#   List the logged (executed) cron jobs and their commands
   5#   TODO: also output a list of scheduled (future) jobs
   6
   7import re
   8
   9from ..formatting import *
  10from ..util import readlog, resolve
  11from .. import config
  12
  13import logging
  14logger = logging.getLogger(__name__)
  15
  16def parse_log():
  17    output = ''
  18    logger.debug("Starting cron section")
  19    output += opentag('div', 1, 'cron', 'section')
  20    matches = re.findall('.*CMD\s*\(\s*(?!.*cd)(.*)\)', readlog(config.prefs['logs']['cron']))
  21    num = sum(1 for line in matches)
  22    commands = []
  23    for match in matches:
  24        commands.append(str(match))
  25    # commands.append([str(match)for match in matches])
  26    #logger.debug("found cron command " + str(commands))
  27    logger.info("Found " + str(num) + " cron jobs")
  28    subtitle = str(num) + " cron jobs run"
  29    output += writetitle("cron")
  30    output += writedata(subtitle)
  31    if (len(matches) > 0):
  32        commands = addtag(commands, 'code')
  33        commands = orderbyfreq(commands)
  34        commands = truncl(commands, config.prefs['maxcmd'])
  35        output += writedata("top cron commands", [c for c in commands])
  36    output += closetag('div', 1)
  37    logger.info("Finished cron section")
  38    return output