-class Configuration(dict):
-
- def __init__(self, *arg, **kw):
- super(Configuration, self).__init__(*arg, **kw)
-
- def _str2bool(x):
- positives = ["yes", "true", "1", "y"]
- negatives = ["no", "false", "0", "n"]
- x = x.lower()
- if x in positives:
- return True
- elif x in negatives:
- return False
- else:
- raise ValueError("Unknown option %s" % x)
-
-defaults = Configuration({
- 'output': '',
- 'header': '/etc/logparse/header.html',
- 'css': '/etc/logparse/main.css',
- 'linewidth': 80,
- 'embed-styles': False,
- 'plain': False,
- 'overwrite': False,
- 'title': logparse.__name__,
- 'maxlist': 10,
- 'maxcmd': 6,
- 'resolve-domains': 'fqdn',
- 'mail': {
- 'to': '',
- 'from': '',
- 'subject': 'logparse from $hostname$',
- 'mailbin': '/usr/bin/mail',
- },
- 'rotate': False,
- 'verbose': False,
- 'quiet': False,
- 'hddtemp': {
- 'drives': ['/dev/sda'],
- 'host': '127.0.0.1',
- 'separator': '|',
- 'timeout': 10,
- 'port': 7634,
- 'show-model': False,
- },
- 'apache': {
- 'resolve-domains': '',
- },
- 'sshd': {
- 'resolve-domains': '',
- },
- 'smbd': {
- 'resolve-domains': '',
- },
- 'httpd': {
- 'resolve-domains': '',
- },
- 'du': {
- 'paths': ['/', '/etc', '/home'],
- 'force-write': False,
- },
- 'hostname-path': '/etc/hostname',
- 'parsers': {},
- 'ignore-parsers': {},
- 'logs': {
- 'auth': '/var/log/auth.log',
- 'cron': '/var/log/cron.log',
- 'cpuinfo': '/proc/cpuinfo',
- 'meminfo': '/proc/meminfo',
- 'sys': '/var/log/syslog',
- 'smb': '/var/log/samba',
- 'zfs': '/var/log/zpool.log',
- 'alloc': '/var/log/du.log',
- 'postfix': '/var/log/mail.log',
- 'httpd': '/var/log/apache2'
- }
-})
-
-def verify(raw_dict, defaults):
- for key, value in raw_dict.items():
- if key in defaults: # valid key
- logger.debug("Found valid key {0} with value {1}".format(key, value))
- if (isinstance(value, dict)):
- verify(value, defaults[key]) # recurse nested dictionaries
-
- else: # invalid key
- logger.warning("Invalid key {0} with value {1}".format(key, value))
-
-def loadconf(argparser, configfile = "/etc/logparse/logparse.conf"):
- logger.debug("Getting config from {0}".format(configfile))