logparse / config.pyon commit bugfixing & add smbd_journald (1e68934)
   1"""
   2This modules contains default config values and basic wrapper for ConfigParser.
   3New config options should be added to the dictionary below, along with 
   4appropriate defaults. Runtime configuration is done through the config file at
   5/etc/logparse/logparse.conf (default) or the path specified in the "--config"
   6argument. The file uses the INI syntax, with general options being declared in
   7the [logparse] section and parser-specific options declared in their own
   8sections.
   9
  10This module provides the following methods:
  11    - `loadconf()`: set up ConfigParser and process config file
  12"""
  13
  14from configparser import ConfigParser
  15from pkg_resources import Requirement, resource_filename
  16
  17import logparse
  18import logging
  19logger = logging.getLogger(__name__)
  20
  21global prefs
  22prefs = None
  23
  24defaults = {
  25        'logparse': {
  26            'output': '',
  27            'overwrite': False,
  28            'title': logparse.__name__,
  29            'maxlist': 10,
  30            'maxcmd': 6,
  31            'resolve-domains': 'fqdn',
  32            'rotate': False,
  33            'verbose': False, 
  34            'quiet': False,
  35            'hostname-path': '/etc/hostname',
  36            'parsers': '',
  37            'ignore-parsers': ''
  38        },
  39        'html': {
  40            'header':  '/etc/logparse/header.html',
  41            'css': '/etc/logparse/main.css',
  42            'embed-styles': False,
  43            'css-relpath': True
  44        },
  45        'plain': {
  46            'plain': False,
  47            'linewidth': 80
  48        },
  49        'logs': {
  50            'auth': '/var/log/auth.log',
  51            'cron': '/var/log/cron.log',
  52            'cpuinfo': '/proc/cpuinfo',
  53            'meminfo': '/proc/meminfo',
  54            'uptime': '/proc/uptime',
  55            'sys': '/var/log/syslog',
  56            'smbd': '/var/log/samba',
  57            'zfs': '/var/log/zpool.log',
  58            'alloc': '/var/log/du.log',
  59            'postfix': '/var/log/mail.log',
  60            'httpd-access': '/var/log/apache2/access.log',
  61            'httpd-error': '/var/log/apache2/error.log'
  62        },
  63        'mail': {
  64            'to': '',
  65            'from': '',
  66            'subject': 'logparse from $hostname',
  67            'mailbin': '/usr/bin/mail'
  68        },
  69        'temperatures': {
  70            'drives': ['/dev/sda'],
  71            'host': '127.0.0.1',
  72            'separator': '|',
  73            'timeout': 10,
  74            'port': 7634,
  75            'show-model': False, 
  76        },
  77        'sshd': {
  78            'sshd-resolve-domains': ''
  79        },
  80        'smbd': {
  81            'shares': '^((?!IPC\$).)*$',
  82            'users': '.*',
  83            'smbd-resolve-domains': ''
  84        },
  85        'httpd': {
  86            'httpd-resolve-domains': ''
  87        },
  88        'du': {
  89            'paths': ['/', '/etc', '/home'],
  90            'force-write': False
  91        }
  92}
  93
  94
  95def loadconf(configpaths):
  96    """
  97    Initial setup for a ConfigParser object. `configpaths` should be a list of
  98    configuration files to load (typically only one). To use the generated
  99    ConfigParser, use `import logparse.config` and then `config.prefs.get(..)`.
 100    The prefs object is returned after creation as a convenience but this method
 101    should only be called once per runtime.
 102    """
 103    prefs= ConfigParser()
 104    prefs.read_dict(defaults)
 105    try:
 106        success = prefs.read(configpaths)
 107        logger.debug("Loaded {0} config file(s): {1}".format(str(len(success)), str(success)))
 108    except Exception as e:
 109        logger.warning("Error processing config: " + str(e))
 110    return prefs