Пример #1
0
            def on_event(event, match=None, mapping=mapping):

                # Check if conditions is defined
                conditions = mapping.get("conditions", [])
                if "condition" in mapping:
                    conditions.append(mapping["condition"])
                for index, condition in enumerate(conditions, 1):
                    if keyword_resolve(condition, keywords={"event": event, "match": match, "context": context}):
                        log.info("Event meets condition #{:} '{:}': {:}".format(index, condition, event))
                    else:
                        return

                # Process all action messages
                actions = mapping.get("actions", [])
                if "action" in mapping:
                    actions.append(mapping["action"])
                for index, message in enumerate(actions, 1):

                    # Check if keyword resolving is enabled
                    if mapping.get("keyword_resolve", False):
                        resolved_message = keyword_resolve(copy.deepcopy(message), keywords={"event": event, "match": match, "context": context})
                        log.debug("Keyword resolved message: {:}".format(resolved_message))

                    # TODO: Figure out if we can improve performance by processing each message in a dedicated worker thread or process?

                        res = edmp.process(resolved_message)
                    else:
                        res = edmp.process(message)

                    if index < len(actions) and mapping.get("chain_conditionally", False):
                        if not res or isinstance(res, dict) and not res.get("result", True):
                            if log.isEnabledFor(logging.DEBUG):
                                log.debug("Breaking action chain after message #{:} '{:}' because of result '{:}'".format(index, message, result))

                            break
Пример #2
0
            def on_event(event, match=None, mapping=mapping):

                # Check condition if defined
                condition = mapping.get("condition", None)
                if condition:
                    if keyword_resolve(condition, keywords={"event": event, "match": match, "context": context}):
                        log.info("Event meets condition '{:}': {:}".format(condition, event))
                    else:
                        return

                # Process all action messages
                for message in mapping["actions"]:

                    # Check if keyword resolving is enabled
                    if mapping.get("keyword_resolve", False):
                        resolved_message = keyword_resolve(copy.deepcopy(message), keywords={"event": event, "match": match, "context": context})
                        log.debug("Keyword resolved message: {:}".format(resolved_message))

                        edmp.process(resolved_message)
                    else:
                        edmp.process(message)
Пример #3
0
def module_direct_handler(name, *args, **kwargs):
    """
    Calls a Salt execution module directy from current process.
    """

    # Resolve keyword arguments if available
    if kwargs.pop("_keyword_resolve", False):
        kwargs = keyword_resolve(kwargs,
                                 keywords={
                                     "context": context,
                                     "options": __opts__
                                 })
        if log.isEnabledFor(logging.DEBUG):
            log.debug("Keyword resolved arguments: {:}".format(kwargs))

    return __salt__[name](*args, **kwargs)
Пример #4
0
def module_handler(name, *args, **kwargs):
    """
    Calls a Salt execution module from within the minion process.
    """

    # Resolve keyword arguments if available
    if kwargs.pop("_keyword_resolve", False):
        kwargs = keyword_resolve(kwargs,
                                 keywords={
                                     "context": context,
                                     "options": __opts__
                                 })
        if log.isEnabledFor(logging.DEBUG):
            log.debug("Keyword resolved arguments: {:}".format(kwargs))

    return __salt__["minionutil.run_job"](name, *args, **kwargs)