From: Andrew Lorimer Date: Tue, 6 Nov 2018 05:52:13 +0000 (+1100) Subject: logrotate at exit is now optional X-Git-Url: https://git.lorimer.id.au/logparse.git/diff_plain/3a1add64bcad08083d5cfecda10dafce3803cf58?ds=inline;hp=d58799b436a48423d2fee526f1b3fd16827e4f08 logrotate at exit is now optional --- 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))