config.py 1.17 KB
Newer Older
ale's avatar
ale committed
1
2
3
4
5
6
7
8
9
import glob
import logging
import os

from ai_diagnostics.probe import Probe, parameterize
from ai_diagnostics.probes.pannello import probe_pannello
from ai_diagnostics.probes.webmail import probe_webmail
from ai_diagnostics.probes.imap import probe_imap
from ai_diagnostics.probes.smtp import *
ale's avatar
ale committed
10
from ai_diagnostics.probes.webdav import probe_webdav
ale's avatar
ale committed
11
from ai_diagnostics.probes.xmpp import probe_xmpp
ale's avatar
ale committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


class Credentials(dict):

    def __str__(self):
        return self['username']


class ExternalMailAccount(dict):

    def __str__(self):
        return self['credentials']['username']


def _execfile(path):
    locals = {}
    with open(path, 'rb') as file:
        exec(compile(file.read(), path, 'exec'), globals(), locals)
    return locals


def load_config(directory):
    probes = []
    for path in glob.glob(os.path.join(directory, '*.py')):
        logging.info('loading configuration file %s', path)
        try:
            data = _execfile(path)
            probes.extend(data.get('PROBES', []))
        except Exception as e:
            logging.error('configuration error in %s: %s', path, e)
            continue
    logging.info('%d probes defined.', len(probes))
    return probes