Skip to content

Instantly share code, notes, and snippets.

@athoune
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athoune/8738873 to your computer and use it in GitHub Desktop.
Save athoune/8738873 to your computer and use it in GitHub Desktop.
Checking logrotate coverage
#!/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
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