Last active
August 29, 2015 13:55
-
-
Save athoune/8738873 to your computer and use it in GitHub Desktop.
Checking logrotate coverage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from glob import glob | |
from fnmatch import fnmatch | |
from os import walk | |
from os.path import join | |
import re | |
DATE_OR_VERSION = re.compile('\.(\d{4}-\d{2}-\d{2})|(\d+)$') | |
def logrotate_patterns(): | |
comments = re.compile(r'\s*#.*$', re.MULTILINE) | |
blocks = re.compile(r'\{.*?\}', re.DOTALL) | |
pattern = re.compile(r'("/.*?")|(/.*?[\s$])') | |
for conf in glob('/etc/logrotate.d/*'): | |
txt = open(conf, 'r').read() | |
txt, _ = comments.subn('', txt) | |
txt, _ = blocks.subn('', txt) | |
for f in pattern.findall(txt): | |
yield f[1].strip() | |
patterns = list(logrotate_patterns()) | |
print "Patterns:", " ".join(patterns) | |
print "Logs not supervized by logrotate :" | |
for root, dirs, files in walk('/var/log'): | |
for name in files: | |
if name.endswith('.gz') or DATE_OR_VERSION.search(name) is not None: | |
continue | |
path = join(root, name) | |
drama = True | |
for pattern in patterns: | |
if fnmatch(path, pattern): | |
drama = False | |
break | |
if drama: | |
print "\t", path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment