Esempio n. 1
0
def _process_actions(data):
    from logstapo.actions import Action

    auto_actions = set()
    actions = {}
    for name, actiondata in data.items():
        actiondata = dict(actiondata)
        try:
            type_ = actiondata.pop("type")
        except KeyError:
            raise ConfigError("invalid action definition ({}): no type specified".format(name))
        if actiondata.pop("auto", True):
            auto_actions.add(name)
        try:
            actions[name] = Action.from_config(type_, actiondata)
        except ConfigError as exc:
            raise ConfigError("invalid action definition ({}): {}".format(name, exc)) from exc
    return actions, auto_actions
Esempio n. 2
0
def _process_actions(data):
    from logstapo.actions import Action
    auto_actions = set()
    actions = {}
    for name, actiondata in data.items():
        actiondata = dict(actiondata)
        try:
            type_ = actiondata.pop('type')
        except KeyError:
            raise ConfigError(
                'invalid action definition ({}): no type specified'.format(
                    name))
        if actiondata.pop('auto', True):
            auto_actions.add(name)
        try:
            actions[name] = Action.from_config(type_, actiondata)
        except ConfigError as exc:
            raise ConfigError('invalid action definition ({}): {}'.format(
                name, exc)) from exc
    return actions, auto_actions
Esempio n. 3
0
def test_action_from_config(mocker):
    actions = mocker.patch('logstapo.actions.ACTIONS', {'smtp': MagicMock(spec=Action)})
    Action.from_config('smtp', {'foo': 'bar'})
    actions['smtp'].assert_called_once_with({'foo': 'bar'})
    with pytest.raises(ConfigError):
        Action.from_config('test', {})