From 3a1add64bcad08083d5cfecda10dafce3803cf58 Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Tue, 6 Nov 2018 16:52:13 +1100 Subject: [PATCH] logrotate at exit is now optional --- logparse.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/logparse.py b/logparse.py index 23a8dda..3a82e96 100755 --- a/logparse.py +++ b/logparse.py @@ -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)) -- 2.47.1