Exemplo n.º 1
0
    def ReadActors(self, NamespaceNode, objNamespace):
        actorList = None
        # go through each collector and create a new Collector object, and add
        # to an array in the Namespace
        for actor in NamespaceNode.getElementsByTagName('Actor'):
            objActor = Actor.Actor()
            attributes = actor.attributes
            if None == attributes:
                Log.getLogger().error("Actor defined with no ID")
                return None

            else:
                Frequency = None
                if "ID" in attributes.keys():
                    objActor.ID = Alias.Alias(attributes["ID"].nodeValue)
                else:
                    Log.getLogger().error("Actor without ID attribute!")
                    return None

            try:
                #_Which = 'Executable' # this is the local script to run to
                #gather the info
                _Which = 'Executable'
                objActor.ExecutableName = Alias.Alias(
                    actor.getElementsByTagName(_Which)[0].firstChild.nodeValue)

                _Which = 'Param'
                for param in actor.getElementsByTagName(
                        _Which):  # Make an array of the params for the script
                    strParam = Alias.Alias(param.firstChild.nodeValue)
                    try:
                        key, value = strParam.split('=')
                        kwargs[key] = value
                        if None == objCollector._kwargs:
                            objCollector._kwargs = {}
                        objCollector._kwargs[key] = value
                    except Exception:
                        Param = CollectorParam.CheckForCollectorAsParam(
                            strParam, objNamespace)
                        objActor.Parameters.append(Param)

            except Exception as Ex:
                Log.getLogger().error(str(Ex))
                self.HandleInvalidXML(_Which)
                return None

            if None == actorList:
                actorList = []

            objNamespace.AddActor(objActor)

        return actorList
Exemplo n.º 2
0
    def __CreateCollectorObject(self, node, objNamespace, MinionID, IsInGroup):
        objCollector = None
        try:
            ScriptName = Alias.Alias(
                node.getElementsByTagName('Executable')
                [0].firstChild.nodeValue)
            objCollector = Collector.Collector(objNamespace, MinionID,
                                               IsInGroup)
            objCollector._ScriptName = ScriptName

            try:
                _Which = 'Param'
                for param in node.getElementsByTagName(
                        _Which):  # Make an array of the params for the script
                    strParam = Alias.Alias(param.firstChild.nodeValue)
                    try:
                        key, value = strParam.split('=')
                        kwargs[key] = value
                        if None == objCollector._kwargs:
                            objCollector._kwargs = {}
                        objCollector._kwargs[key] = value
                    except Exception:
                        Param = CollectorParam.CheckForCollectorAsParam(
                            strParam, objNamespace)
                        objCollector._Parameters.append(Param)

            except Exception:
                pass

            try:
                OperatorType = Alias.Alias(
                    node.getElementsByTagName('Operator')
                    [0].firstChild.nodeValue)

                if OperatorType.lower(
                ) != "userdefined":  # want to keep going if userdefined
                    return objCollector

            except Exception as Ex:
                return objCollector

        except Exception:  # OK, wasn't a traditional collector, let's see if it is an operator
            pass

        try:
            OperatorType = Alias.Alias(
                node.getElementsByTagName('Operator')[0].firstChild.nodeValue)
            if OperatorType.lower() == "addition":
                objCollector = Operator.Operator_Addition(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "average":
                objCollector = Operator.Operator_Average(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "makelist":
                objCollector = Operator.Operator_MakeList(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "duplicate":
                objCollector = Operator.Operator_Duplicate(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "compare_eq":
                objCollector = Operator.Operator_Compare_EQ(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "compare_ne":
                objCollector = Operator.Operator_Compare_NE(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "compare_gt":
                objCollector = Operator.Operator_Compare_GT(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "compare_ge":
                objCollector = Operator.Operator_Compare_GE(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "compare_lt":
                objCollector = Operator.Operator_Compare_LT(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "compare_le":
                objCollector = Operator.Operator_Compare_LE(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "greatest":
                objCollector = Operator.Operator_Greatest(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "least":
                objCollector = Operator.Operator_Least(objNamespace, MinionID,
                                                       IsInGroup)
            elif OperatorType.lower() == "maxvalue":
                objCollector = Operator.Operator_MaxValue(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "minvalue":
                objCollector = Operator.Operator_MinValue(
                    objNamespace, MinionID, IsInGroup)
            elif OperatorType.lower() == "userdefined":
                objCollector = Operator.Operator_UserDefined(
                    objNamespace, MinionID, IsInGroup, objCollector)

            else:
                self.HandleInvalidXML("Unknown Operator: " + OperatorType)
                return None
            try:

                retVal = self.__GetOperatorInputs(node, objCollector)
                if retVal == 0:
                    Log.getLogger().error("Operator Collector [" + MinionID +
                                          "] with no <Input>")
                    return None

                if retVal < 1:
                    return None

            except Exception as Ex:

                return None

            return objCollector

        except Exception as ex:  # OK, wasn't a traditional collector, let's see if it is an operator
            self.HandleInvalidXML("Executable | Operator")
            return None