731732d3b9f70a85f11516d0187461557ba734de
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 logparse.formatting import *
14from logparse.util import readlog
15from logparse import config
16from logparse.load_parsers import Parser
17from logparse.load_parsers import Parser
18
19class Cron(Parser):
20
21 def __init__(self):
22 super().__init__()
23 self.name = "cron"
24 self.info = "List the logged (executed) cron jobs and their commands (uses static syslog file)"
25 self.deprecated = True
26
27 def parse_log(self):
28
29 logger.warning("NOTE: This cron parser is now deprecated. Please use cron-journald if possible.")
30
31 logger.debug("Starting cron section")
32 section = Section("cron")
33
34 matches = re.findall('.*CMD\s*\(\s*(?!.*cd)(.*)\)', readlog(config.prefs.get("logs", "cron")))
35 num = len(matches)
36 commands = []
37 for match in matches:
38 commands.append(str(match))
39 logger.info("Found " + str(num) + " cron jobs")
40 jobs_data = Data(str(num) + " cron jobs run")
41 section.append_data(jobs_data)
42
43 if (num > 0):
44 logger.debug("Analysing cron commands")
45 cmd_data = Data("Top cron commands")
46 cmd_data.items = ("`{0}`".format(x) for x in commands)
47 cmd_data.orderbyfreq()
48 cmd_data.truncl(config.prefs.getint("logparse", "maxcmd"))
49 section.append_data(cmd_data)
50
51 logger.info("Finished cron section")
52 return section