add journald communication capability
[logparse.git] / logparse / parsers / cron.py
index 01a6135f35c27015f4e175db5068e81a9dafeedd..4408ba20bd03516c0d8c37612c47b51933d72c6b 100644 (file)
@@ -1,23 +1,32 @@
 #
 #   cron.py
 #
-#   List the logged (executed) cron jobs and their commands
-#   TODO: also output a list of scheduled (future) jobs
+#   List the logged (executed) cron jobs and their commands (uses syslog file)
+#
+#   NOTE: This file is now deprecated in favour of the newer journald mechanism
+#   used in cron-journald.py. This parser is still functional but is slower and
+#   has less features. Please switch over if possible.
+#
 
 import re
 
 from ..formatting import *
 from ..util import readlog, resolve
 from .. import config
+from .. import util
 
 import logging
 logger = logging.getLogger(__name__)
 
 def parse_log():
+
+    logger.warning("NOTE: This cron parser is now deprecated. Please use cron-journald if possible.")
+
     logger.debug("Starting cron section")
     section = Section("cron")
+
     matches = re.findall('.*CMD\s*\(\s*(?!.*cd)(.*)\)', readlog(config.prefs['logs']['cron']))
-    num = sum(1 for line in matches)
+    num = len(matches)
     commands = []
     for match in matches:
         commands.append(str(match))
@@ -27,7 +36,7 @@ def parse_log():
     jobs_data = Data(str(num) + " cron jobs run")
     section.append_data(jobs_data)
 
-    if (len(matches) > 0):
+    if (num > 0):
         logger.debug("Analysing cron commands")
         cmd_data = Data("Top cron commands")
         cmd_data.items = ("`{0}`".format(x) for x in commands)