def __createCollector(self,ID,fromPlugin=False):
        objCollector = Collector.Collector(self._NamespaceObject,ID,self._InGroup)
        objCollector._OnDemand = self._OnDemand
        objCollector._PollingInterval = self._PollingInterval
        objCollector.IsDynamicallyCreated = True
        objCollector.Precision = self.Precision
        objCollector._SendOnlyOnDelta = self._SendOnlyOnDelta
        objCollector._Normalize = self._Normalize
        objCollector._NormalizeValue = self._NormalizeValue
        objCollector._DoNotSend = self._DoNotSend
        objCollector.DynamicCollectorParent=self
        objCollector.GetElapsedTimeSinceLast = objCollector.GetElapsedTimeForDynamicWidget #remap the fn called
        objCollector.SetLastCollectionTime = objCollector.SetLastCollectionTimeForDynamicWidget
        objCollector.SetProcessThreadID(self.GetProcessThreadID())
        if fromPlugin:
            objCollector.DynamicSuffix="" #=str(self)
        else:
            objCollector.DynamicSuffix=""

        if True == fromPlugin: # bit of a hack, only need this if from a plugin
            if len(self.__PrefixStr) > 0:
                objCollector._OverrideID = self.__PrefixStr + ID

            if len(self.__SuffixStr) > 0:
                objCollector._OverrideID = ID + self.__SuffixStr

        if float(self.ScaleValue) != 1.0:
            objCollector.SetScaleValue(self.ScaleValue)


        Log.getLogger().debug("Creating Dynamic Collector[" + str(DynamicCollector.__CollectorNumber) + "]: " + ID[:-len(objCollector.DynamicSuffix)])
        objCollector._DebugNum = DynamicCollector.__CollectorNumber
        DynamicCollector.__CollectorNumber += 1

        # go see if there are any modifies for this collector, and for fun, let's do a RegEx, cause that could be interesting
        for mod in self.__ModifyList:
            try:
                pattern = re.compile(mod[0].lower())
                matched = pattern.match(ID.lower())
            except Exception as Ex:
                Log.getLogger().error("Invalid RegEx patter for <ModifyCollector>: " + mod[0] + ": " + str(Ex))
                return None
            

            if matched:
                Log.getLogger().info("Applying Modifiers to DynamicCollector " + ID)
                # data format
                # [CollectorID,[Precision,Normalize,Scale,DoNotSend,
                # SendOnlyOnChange]]

                Precision = mod[1][0]
                Normalize = mod[1][1]
                SyncFile = mod[1][2]
                Scale = mod[1][3]
                DoNotSend = mod[1][4]
                SendOnlyOnChange = mod[1][5]

                objCollector._SyncFile = SyncFile

                if None != Precision:
                    objCollector.Precision = Precision

                if None != Normalize:
                    objCollector._NormalizeValue = Normalize
                    objCollector._Normalize = True

                if None != Scale:
                    objCollector.SetScaleValue(Scale)

                if None != DoNotSend:
                    objCollector._DoNotSend = DoNotSend

                if None != SendOnlyOnChange:
                    objCollector._SendOnlyOnDelta = SendOnlyOnChange

                # remove this node from the list, and get outta here
                if mod[0].lower() == ID.lower(): # was an exact match and not a RegEx match, so can nuke it
                    self.__ModifyList.remove(mod)
                
                break # if matched

        if None == self.__Group:
            self._NamespaceObject.AddCollector(objCollector,self._MinionID)
        else:
            self.__Group.AddCollector(objCollector,self._MinionID)
        
        return objCollector
Пример #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