logparse / parsers / cron.pyon commit add journald communication capability (7351cf6)
   1#
   2#   cron.py
   3#
   4#   List the logged (executed) cron jobs and their commands (uses syslog file)
   5#
   6#   NOTE: This file is now deprecated in favour of the newer journald mechanism
   7#   used in cron-journald.py. This parser is still functional but is slower and
   8#   has less features. Please switch over if possible.
   9#
  10
  11import re
  12
  13from ..formatting import *
  14from ..util import readlog, resolve
  15from .. import config
  16from .. import util
  17
  18import logging
  19logger = logging.getLogger(__name__)
  20
  21def parse_log():
  22
  23    logger.warning("NOTE: This cron parser is now deprecated. Please use cron-journald if possible.")
  24
  25    logger.debug("Starting cron section")
  26    section = Section("cron")
  27
  28    matches = re.findall('.*CMD\s*\(\s*(?!.*cd)(.*)\)', readlog(config.prefs['logs']['cron']))
  29    num = len(matches)
  30    commands = []
  31    for match in matches:
  32        commands.append(str(match))
  33    # commands.append([str(match)for match in matches])
  34    #logger.debug("found cron command " + str(commands))
  35    logger.info("Found " + str(num) + " cron jobs")
  36    jobs_data = Data(str(num) + " cron jobs run")
  37    section.append_data(jobs_data)
  38
  39    if (num > 0):
  40        logger.debug("Analysing cron commands")
  41        cmd_data = Data("Top cron commands")
  42        cmd_data.items = ("`{0}`".format(x) for x in commands)
  43        cmd_data.orderbyfreq()
  44        cmd_data.truncl(config.prefs['maxcmd'])
  45        section.append_data(cmd_data)
  46
  47    logger.info("Finished cron section")
  48    return section