logparse / parsers / cron.pyon commit update parsers to new output model (94973e5)
   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    logger.debug("Starting cron section")
  18    section = Section("cron")
  19    matches = re.findall('.*CMD\s*\(\s*(?!.*cd)(.*)\)', readlog(config.prefs['logs']['cron']))
  20    num = sum(1 for line in matches)
  21    commands = []
  22    for match in matches:
  23        commands.append(str(match))
  24    # commands.append([str(match)for match in matches])
  25    #logger.debug("found cron command " + str(commands))
  26    logger.info("Found " + str(num) + " cron jobs")
  27    subtitle = str(num) + " cron jobs run"
  28    section.add_data(Data(subtitle))
  29    if (len(matches) > 0):
  30        commands = ("`{0}`".format(x) for x in commands)
  31        commands = orderbyfreq(list(commands))
  32        commands = truncl(commands, config.prefs['maxcmd'])
  33        section.add_data(Data("top cron commands", commands))
  34    logger.info("Finished cron section")
  35    return section