Example #1
0
def _process_log_files(logdata):
    files = set(
        itertools.chain.from_iterable(ensure_collection(logdata.get(key, ""), set) for key in ("file", "files"))
    )
    if not files:
        raise ConfigError("no files specified")
    return files
Example #2
0
def _process_log_files(logdata):
    files = set(
        itertools.chain.from_iterable(
            ensure_collection(logdata.get(key, ''), set)
            for key in ('file', 'files')))
    if not files:
        raise ConfigError('no files specified')
    return files
Example #3
0
def _process_log_actions(logdata, name, auto_actions, available):
    if not any(x in logdata for x in ("action", "actions")):
        return auto_actions
    actions = set(
        itertools.chain.from_iterable(ensure_collection(logdata.get(key, ""), set) for key in ("action", "actions"))
    )
    invalid = next((x for x in actions if x not in available), None)
    if invalid is not None:
        raise ConfigError("invalid action specified: {}".format(invalid))
    return actions
Example #4
0
def _process_log_actions(logdata, name, auto_actions, available):
    if not any(x in logdata for x in ('action', 'actions')):
        return auto_actions
    actions = set(
        itertools.chain.from_iterable(
            ensure_collection(logdata.get(key, ''), set)
            for key in ('action', 'actions')))
    invalid = next((x for x in actions if x not in available), None)
    if invalid is not None:
        raise ConfigError('invalid action specified: {}'.format(invalid))
    return actions
Example #5
0
 def __init__(self, data):
     self.host = data.get('host', 'localhost')
     self.port = data.get('port', 0)
     self.ssl = data.get('ssl', False)
     self.starttls = data.get('starttls', False)
     self.username = data.get('username')
     self.password = data.get('password')
     self.sender = data.get('from') or self._get_sender()
     try:
         self.recipients = sorted(ensure_collection(data['to'], set))
     except KeyError:
         raise ConfigError('email recipient (to) missing')
     self.subject = data.get('subject', 'unusual system events')
     self.group_by_source = data.get('group', False)
     if self.ssl and self.starttls:
         raise ConfigError('ssl and starttls are mutually exclusive')
     if bool(self.username) != bool(self.password):
         raise ConfigError('username and password must both be set or unset')
Example #6
0
 def __init__(self, data):
     self.host = data.get('host', 'localhost')
     self.port = data.get('port', 0)
     self.ssl = data.get('ssl', False)
     self.starttls = data.get('starttls', False)
     self.username = data.get('username')
     self.password = data.get('password')
     self.sender = data.get('from') or self._get_sender()
     try:
         self.recipients = sorted(ensure_collection(data['to'], set))
     except KeyError:
         raise ConfigError('email recipient (to) missing')
     self.subject = data.get('subject', 'unusual system events')
     self.group_by_source = data.get('group', False)
     if self.ssl and self.starttls:
         raise ConfigError('ssl and starttls are mutually exclusive')
     if bool(self.username) != bool(self.password):
         raise ConfigError(
             'username and password must both be set or unset')
Example #7
0
def _process_log_regexps(logdata, name, available):
    regexps = ensure_collection(logdata.get('regex', name), tuple)
    invalid = next((x for x in regexps if x not in available), None)
    if invalid is not None:
        raise ConfigError('invalid regex specified: {}'.format(invalid))
    return regexps
Example #8
0
def _process_log_regexps(logdata, name, available):
    regexps = ensure_collection(logdata.get("regex", name), tuple)
    invalid = next((x for x in regexps if x not in available), None)
    if invalid is not None:
        raise ConfigError("invalid regex specified: {}".format(invalid))
    return regexps
Example #9
0
def test_ensure_collection(value, collection_type, result):
    assert util.ensure_collection(value, collection_type) == result