How to use the cma.graphnodeexpression.GraphNodeExpression.RegisterFun function in cma

To help you get started, we’ve selected a few cma examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def NOT(args, _context):
    "Function to Negate the Truth value of its single argument"
    try:
        val0 = args[0]
    except TypeError:
        val0 = args
    return None if val0 is None else not val0
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def is_upstartjob(args, context):
    """
    Returns "true" if any of its arguments names an upstart job, "false" otherwise
    If no arguments are given, it returns whether this system has upstart enabled.
    """

    from monitoring import MonitoringRule

    agentcache = MonitoringRule.compute_available_agents(context)

    if "upstart" not in agentcache or len(agentcache["upstart"]) == 0:
        return "false"

    for arg in args:
        value = GraphNodeExpression.evaluate(arg, context)
        if value in agentcache["upstart"]:
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def NOTIN(args, _context):
    "Function to return True if first argument is NOT in the list that follows"
    val0 = args[0]
    if val0 is None:
        return None
    if hasattr(val0, "__iter__") and not isinstance(val0, six.string_types):
        # Iterable
        for elem in val0:
            if elem in args[1:] or str(elem) in args[1:]:
                return False
        return True
    return val0 not in args[1:] and str(val0) not in args[1:]
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def bitwiseAND(args, context):
    """
    A function which evaluates the each expression and returns the bitwise AND of
    all the expressions given as arguments
    """
    if len(args) < 2:
        return None
    result = int(args[0])
    for arg in args:
        value = GraphNodeExpression.evaluate(arg, context)
        if value is None:
            return None
        result &= int(value)
    return result
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def PAMMODARGS(args, _context):
    """
    We pass the following arguments to PAMSELECTARGS:
        section - the section value to select from
        service - service type to search for
        module - the module to select arguments from
        argument - the arguments to select

    We return the arguments from the first occurence of the module that we find.
    """
    # print('PAMMODARGS(%s)' % (str(args)), file=sys.stderr)
    if len(args) != 4:
        print("WRONG NUMBER OF ARGUMENTS (%d) TO PAMMODARGS" % (len(args)), file=sys.stderr)
        return False
    section = args[0]
    reqservice = args[1]
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def argequals(args, context):
    """
    usage: argequals  name-to-search-for [list-to-search]

    A function which searches a list for an argument of the form name=value.
    The value '$argv' is the default name of the list to search.
    If there is a second argument, then that second argument is an expression
    expected to yield an iterable to search in for the name=value string instead of '$argv'
    """
    # print('ARGEQUALS(%s)' % (str(args)), file=sys.stderr)
    if len(args) > 2 or len(args) < 1:
        return None
    definename = args[0]
    argname = args[1] if len(args) >= 2 else "$argv"
    listtosearch = GraphNodeExpression.evaluate(argname, context)
    # print('SEARCHING in %s FOR %s in %s' % (argname, definename, listtosearch), file=sys.stderr)
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def match(args, _context):
    """Function to return True if first argument matches the second argument (a regex)
    - optional 3rd argument is RE flags"""
    lhs = str(args[0])
    rhs = args[1]
    if lhs is None or rhs is None:
        return None
    flags = args[2] if len(args) > 2 else None
    regex = _compile_and_cache_regex(rhs, flags)
    return regex.search(lhs) is not None
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def flagvalue(args, context):
    """
    usage: flagvalue flag-name [list-to-search]
    A function which searches a list for a -flag and returns
    the value of the string which is the next argument.
    The -flag is given by the argument in args, and the list 'argv'
    is assumed to be the list of arguments.
    If there are two arguments in args, then the first argument is the
    array value to search in for the -flag string instead of 'argv'
    The flag given must be the entire flag complete with - character.
    For example -X or --someflag.
    """
    if len(args) > 2 or len(args) < 1:
        return None
    flagname = args[0]
    argname = args[1] if len(args) >= 2 else "$argv"
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def OR(args, context):
    """
    A function which evaluates  each expression in turn, and returns the value
    of the first expression which is not None - or None
    """
    # print('OR(%s)' % (str(args)), file=sys.stderr)
    if len(args) < 1:
        return None
    anyfalse = False
    for arg in args:
        value = GraphNodeExpression.evaluate(arg, context)
        if value is not None:
            if value:
                return value
            else:
                anyfalse = True
github assimilation / assimilation-official / cma / graphnodeexpression.py View on Github external
@GraphNodeExpression.RegisterFun
def IGNORE(_ignoreargs, _ignorecontext):
    """Function to ignore its argument(s) and return True all the time.
    This is a special kind of no-op in that it is used to override
    and ignore an underlying rule. It is expected that its arguments
    will explain why it is being ignored in this rule set.
    """
    return True