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