ac8cc9f7a668437a89ae086e9fb1fa37ae04a734
1#
2# config.py
3#
4# Default config values and basic wrapper for PyYaml. New config options
5# should be added to the dictionary below, along with appropriate defaults.
6#
7
8import yaml
9import types
10import os
11from pkg_resources import Requirement, resource_filename
12
13import logparse
14import logging
15logger = logging.getLogger(__name__)
16
17def locate(filename):
18 logger.debug("Searching for {0}".format(filename))
19 loc = resource_filename(Requirement.parse(__package__), filename)
20 logger.debug("Found {0}".format(loc))
21 return loc
22
23prefs = {
24 'output': '/var/www/logparse/summary.html',
25 'header': '/etc/logparse/header.html',
26 'css': '/etc/logparse/main.css',
27 'title': logparse.__name__,
28 'maxlist': 10,
29 'maxcmd': 3,
30 'resolve-domains': 'fqdn',
31 'mail': {
32 'to': '',
33 'from': '',
34 'subject': 'logparse from $hostname$',
35 'mailbin': '/usr/bin/mail',
36 },
37 'rotate': 'n',
38 'verbose': 'n',
39 'hddtemp': {
40 'drives': ['/dev/sda'],
41 'host': 'localhost',
42 'separator': '|',
43 'timeout': 10,
44 'port': 7634,
45 'show-model': False,
46 },
47 'apache': {
48 'resolve-domains': '',
49 },
50 'sshd': {
51 'resolve-domains': '',
52 },
53 'smbd': {
54 'resolve-domains': '',
55 },
56 'httpd': {
57 'resolve-domains': '',
58 },
59 'du': {
60 'paths': ['/', '/etc', '/home'],
61 'force-write': 'n',
62 },
63 'hostname-path': '/etc/hostname',
64 'logs': {
65 'auth': '/var/log/auth.log',
66 'cron': '/var/log/cron.log',
67 'sys': '/var/log/syslog',
68 'smb': '/var/log/samba',
69 'zfs': '/var/log/zpool.log',
70 'alloc': '/var/log/du.log',
71 'postfix': '/var/log/mail.log',
72 'httpd': '/var/log/apache2'
73 }
74}
75
76def loadconf(argparser, configfile = "/etc/logparse/logparse.conf"):
77 logger.debug("getting config from {0}".format(configfile))
78 try:
79 data = yaml.safe_load(open(configfile))
80 for value in data:
81 if(isinstance(data[value], dict)):
82 for key in data[value].items():
83 prefs[value][key[0]] = key[1]
84 else:
85 prefs[value] = data[value]
86# config['dest'] = paths.dirname(config['output'])
87 if argparser.parse_args().to is not None:
88 prefs['mail']['to'] = argparser.parse_args().to
89 if not prefs['mail']['to']:
90 logger.info("no recipient address provided, outputting to stdout")
91 else:
92 logger.info("email will be sent to " + prefs['mail']['to'])
93 return prefs
94 except Exception as e:
95 logger.warning("error processing config: " + str(e))