Hi, I'm writing a script to monitor rsyslog (second level check).
Overview: We have Monit for monitoring rsyslog, however we need a script to do a second level checks. I'm looking for a script which will check if rsyslog is being updated, also log rotation is happening. Incase of the new file created by logrotate, script should monitor the latest file. Also monitor last modified time and tail of the log. Filename Ex. 20140826_debug_log (datechanges with log rotate) In case of any issues such as file not being updated within the interval of 5 min, alert with disk status. I have written a script, however I'm not able to get the date substraction math right, getting the following error (Searched google and other resources too). *Traceback (most recent call last):* * File "./rsyslog_check.py", line 22, in <module>* * difft=cur_time-mt* *TypeError: unsupported operand type(s) for -: 'str' and 'str'* Request your help. Also point any good documentation where I can get quick reference. ########################## #! /usr/bin/python # import libraries import os import sys import datetime import time import smtplib import Queue import threading import subprocess # Defining main variables tfile='/local/rsyslog/20140727_msg_debug.log' dt = datetime.datetime.now().strftime("%Y%m%d") file = "_msg_debug.log" filename = "%s%s" % (dt,file) filepath = '/local/rsyslog/'+filename ct = time.ctime(os.path.getctime(tfile)) mt = time.ctime(os.path.getctime(tfile)) cur_time = time.ctime() difft=int(cur_time-mt) tdelta=datetime.timedelta(minute=5) # Main if os.path.isfile(filepath) == True: print "%s exists \n" % (tfile) print "This file was created at %s UTC \n" % (ct) * if difft > tdelta:* * print "File is not modified, last modified at %s UTC" % (mt)* * else:* * print "File is being modified"* *else:* * os.path.isfile(filepath)* # Tailing the file tailq = Queue.Queue(maxsize=10) # buffer at most 100 lines def tail_forever(filepath): p = subprocess.Popen(["tail", tfile], stdout=subprocess.PIPE) while 1: line = p.stdout.readline() tailq.put(line) if not line: break threading.Thread(target=tail_forever, args=(tfile,)).start() print "\n # Tailing Log file %s" % (tfile) print "\n ***********************************" print tailq.get() # blocks print tailq.get_nowait() # throws Queue.Empty if there are no lines to read exit() -Thanks, Anirudh Tamsekar
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor