logrotate at exit is now optional
authorAndrew Lorimer <andrew@lorimer.id.au>
Tue, 6 Nov 2018 05:52:13 +0000 (16:52 +1100)
committerAndrew Lorimer <andrew@lorimer.id.au>
Tue, 6 Nov 2018 05:52:13 +0000 (16:52 +1100)
logparse.py
index 23a8ddae888d23186027c47b24d0b77693a802f1..3a82e96781a51ba1b19f826cd8ddbd9aebe798f3 100755 (executable)
@@ -29,6 +29,7 @@ config = {
         'from': '',
         'subject': 'logparse from $hostname$'
     },
+    'rotate': 1,
     'hddtemp': {
         'drives': ['/dev/sda'],
         'port': 7634
@@ -83,7 +84,7 @@ parser.add_argument('-t','--to', help='mail recipient (\"to\" address)',required
 to = parser.parse_args().to
 
 def __main__():
-    logger.info("Beginning log analysis at " + str(timenow))
+    logger.info("Beginning log analysis at " + str(datenow) + ' ' + str(timenow))
     if (to == None):
         logger.info("no recipient address provided, outputting to stdout")
     else:
@@ -768,5 +769,15 @@ def loadconf(configfile):
 try:
     __main__()
 finally:
-    subprocess.call("/usr/sbin/logrotate -f /etc/logrotate.conf", shell=True)
-    logger.info("rotated logfiles")
+    # rotate logs using systemd logrotate
+    if (config['rotate'] == 1):
+        subprocess.call("/usr/sbin/logrotate -f /etc/logrotate.conf", shell=True)
+        logger.info("rotated logfiles")
+    else:
+        logger.info("user doesn't want to rotate logs")
+        logger.debug("Here is the output of `logrotate -d /etc/logrotate.conf` (simulated):")
+        sim = subprocess.check_output("/usr/sbin/logrotate -d /etc/logrotate.conf", shell=True)
+        logger.debug(sim)
+    timenow = time.strftime("%H:%M:%S")
+    datenow = time.strftime("%x")
+    logger.info("finished parsing logs at " + str(datenow) + ' ' + str(timenow))