(self, device, host, port, community)
Collect Netscaler SNMP stats from device
Collect Netscaler SNMP stats from device
Collect Netscaler SNMP stats from device
def collect_snmp(self, device, host, port, community):
        """
        Collect Netscaler SNMP stats from device
        """
        # Log
        self.log.info("Collecting Netscaler statistics from: %s", device)

        # Set timestamp
        timestamp = time.time()

        # Collect Netscaler System OIDs
        for k, v in self.NETSCALER_SYSTEM_GUAGES.items():
            # Get Metric Name and Value
            metricName = '.'.join([k])
            metricValue = int(self.get(v, host, port, community)[v])
            # Get Metric Path
            metricPath = '.'.join(['devices', device, 'system', metricName])
            # Create Metric
            metric = Metric(metricPath, metricValue, timestamp, 0)
            # Publish Metric
            self.publish_metric(metric)

        # Collect Netscaler System Counter OIDs
        for k, v in self.NETSCALER_SYSTEM_COUNTERS.items():
            # Get Metric Name and Value
            metricName = '.'.join([k])
            # Get Metric Path
            metricPath = '.'.join(['devices', device, 'system', metricName])
            # Get Metric Value
            metricValue = self.derivative(metricPath, long(
                self.get(v, host, port, community)[v]), self.MAX_VALUE)
            # Create Metric
            metric = Metric(metricPath, metricValue, timestamp, 0)
            # Publish Metric
            self.publish_metric(metric)

        # Collect Netscaler Services
        serviceNames = [v.strip("\'") for v in self.walk(
            self.NETSCALER_SERVICE_NAMES, host, port, community).values()]

        for serviceName in serviceNames:
            # Get Service Name in OID form
            serviceNameOid = self.get_string_index_oid(serviceName)

            # Get Service Type
            serviceTypeOid = ".".join([self.NETSCALER_SERVICE_TYPE,
                                       self._convert_from_oid(serviceNameOid)])
            serviceType = int(self.get(serviceTypeOid,
                                       host,
                                       port,
                                       community)[serviceTypeOid].strip("\'"))

            # Filter excluded service types
            if serviceType in map(lambda v: int(v),
                                  self.config.get('exclude_service_type')):
                continue

            # Get Service State
            serviceStateOid = ".".join([self.NETSCALER_SERVICE_STATE,
                                        self._convert_from_oid(serviceNameOid)])
            serviceState = int(self.get(serviceStateOid,
                                        host,
                                        port,
                                        community)[serviceStateOid].strip("\'"))

            # Filter excluded service states
            if serviceState in map(lambda v: int(v),
                                   self.config.get('exclude_service_state')):
                continue

            for k, v in self.NETSCALER_SERVICE_GUAGES.items():
                serviceGuageOid = ".".join(
                    [v, self._convert_from_oid(serviceNameOid)])
                # Get Metric Name
                metricName = '.'.join([re.sub(r'\.|\\', '_', serviceName), k])
                # Get Metric Value
                metricValue = int(self.get(serviceGuageOid,
                                           host,
                                           port,
                                           community
                                           )[serviceGuageOid].strip("\'"))
                # Get Metric Path
                metricPath = '.'.join(['devices',
                                       device,
                                       'service',
                                       metricName])
                # Create Metric
                metric = Metric(metricPath, metricValue, timestamp, 0)
                # Publish Metric
                self.publish_metric(metric)

        # Collect Netscaler Vservers
        vserverNames = [v.strip("\'") for v in self.walk(
            self.NETSCALER_VSERVER_NAMES, host, port, community).values()]

        for vserverName in vserverNames:
            # Get Vserver Name in OID form
            vserverNameOid = self.get_string_index_oid(vserverName)

            # Get Vserver Type
            vserverTypeOid = ".".join([self.NETSCALER_VSERVER_TYPE,
                                       self._convert_from_oid(vserverNameOid)])
            vserverType = int(self.get(vserverTypeOid,
                                       host,
                                       port,
                                       community)[vserverTypeOid].strip("\'"))

            # filter excluded vserver types
            if vserverType in map(lambda v: int(v),
                                  self.config.get('exclude_vserver_type')):
                continue

            # Get Service State
            vserverStateOid = ".".join([self.NETSCALER_VSERVER_STATE,
                                        self._convert_from_oid(vserverNameOid)])
            vserverState = int(self.get(vserverStateOid,
                                        host,
                                        port,
                                        community)[vserverStateOid].strip("\'"))

            # Filter excluded vserver state
            if vserverState in map(lambda v: int(v),
                                   self.config.get('exclude_vserver_state')):
                continue

            for k, v in self.NETSCALER_VSERVER_GUAGES.items():
                vserverGuageOid = ".".join(
                    [v, self._convert_from_oid(vserverNameOid)])
                # Get Metric Name
                metricName = '.'.join([re.sub(r'\.|\\', '_', vserverName), k])
                # Get Metric Value
                metricValue = int(self.get(vserverGuageOid,
                                           host,
                                           port,
                                           community
                                           )[vserverGuageOid].strip("\'"))
                # Get Metric Path
                metricPath = '.'.join(['devices',
                                       device,
                                       'vserver',
                                       metricName])
                # Create Metric
                metric = Metric(metricPath, metricValue, timestamp, 0)
                # Publish Metric
                self.publish_metric(metric)
def collect_snmp ( self , device , host , port , community ) : # Log self . log . info ( "Collecting Netscaler statistics from: %s" , device ) # Set timestamp timestamp = time . time ( ) # Collect Netscaler System OIDs for k , v in self . NETSCALER_SYSTEM_GUAGES . items ( ) : # Get Metric Name and Value metricName = '.' . join ( [ k ] ) metricValue = int ( self . get ( v , host , port , community ) [ v ] ) # Get Metric Path metricPath = '.' . join ( [ 'devices' , device , 'system' , metricName ] ) # Create Metric metric = Metric ( metricPath , metricValue , timestamp , 0 ) # Publish Metric self . publish_metric ( metric ) # Collect Netscaler System Counter OIDs for k , v in self . NETSCALER_SYSTEM_COUNTERS . items ( ) : # Get Metric Name and Value metricName = '.' . join ( [ k ] ) # Get Metric Path metricPath = '.' . join ( [ 'devices' , device , 'system' , metricName ] ) # Get Metric Value metricValue = self . derivative ( metricPath , long ( self . get ( v , host , port , community ) [ v ] ) , self . MAX_VALUE ) # Create Metric metric = Metric ( metricPath , metricValue , timestamp , 0 ) # Publish Metric self . publish_metric ( metric ) # Collect Netscaler Services serviceNames = [ v . strip ( "\'" ) for v in self . walk ( self . NETSCALER_SERVICE_NAMES , host , port , community ) . values ( ) ] for serviceName in serviceNames : # Get Service Name in OID form serviceNameOid = self . get_string_index_oid ( serviceName ) # Get Service Type serviceTypeOid = "." . join ( [ self . NETSCALER_SERVICE_TYPE , self . _convert_from_oid ( serviceNameOid ) ] ) serviceType = int ( self . get ( serviceTypeOid , host , port , community ) [ serviceTypeOid ] . strip ( "\'" ) ) # Filter excluded service types if serviceType in map ( lambda v : int ( v ) , self . config . get ( 'exclude_service_type' ) ) : continue # Get Service State serviceStateOid = "." . join ( [ self . NETSCALER_SERVICE_STATE , self . _convert_from_oid ( serviceNameOid ) ] ) serviceState = int ( self . get ( serviceStateOid , host , port , community ) [ serviceStateOid ] . strip ( "\'" ) ) # Filter excluded service states if serviceState in map ( lambda v : int ( v ) , self . config . get ( 'exclude_service_state' ) ) : continue for k , v in self . NETSCALER_SERVICE_GUAGES . items ( ) : serviceGuageOid = "." . join ( [ v , self . _convert_from_oid ( serviceNameOid ) ] ) # Get Metric Name metricName = '.' . join ( [ re . sub ( r'\.|\\' , '_' , serviceName ) , k ] ) # Get Metric Value metricValue = int ( self . get ( serviceGuageOid , host , port , community ) [ serviceGuageOid ] . strip ( "\'" ) ) # Get Metric Path metricPath = '.' . join ( [ 'devices' , device , 'service' , metricName ] ) # Create Metric metric = Metric ( metricPath , metricValue , timestamp , 0 ) # Publish Metric self . publish_metric ( metric ) # Collect Netscaler Vservers vserverNames = [ v . strip ( "\'" ) for v in self . walk ( self . NETSCALER_VSERVER_NAMES , host , port , community ) . values ( ) ] for vserverName in vserverNames : # Get Vserver Name in OID form vserverNameOid = self . get_string_index_oid ( vserverName ) # Get Vserver Type vserverTypeOid = "." . join ( [ self . NETSCALER_VSERVER_TYPE , self . _convert_from_oid ( vserverNameOid ) ] ) vserverType = int ( self . get ( vserverTypeOid , host , port , community ) [ vserverTypeOid ] . strip ( "\'" ) ) # filter excluded vserver types if vserverType in map ( lambda v : int ( v ) , self . config . get ( 'exclude_vserver_type' ) ) : continue # Get Service State vserverStateOid = "." . join ( [ self . NETSCALER_VSERVER_STATE , self . _convert_from_oid ( vserverNameOid ) ] ) vserverState = int ( self . get ( vserverStateOid , host , port , community ) [ vserverStateOid ] . strip ( "\'" ) ) # Filter excluded vserver state if vserverState in map ( lambda v : int ( v ) , self . config . get ( 'exclude_vserver_state' ) ) : continue for k , v in self . NETSCALER_VSERVER_GUAGES . items ( ) : vserverGuageOid = "." . join ( [ v , self . _convert_from_oid ( vserverNameOid ) ] ) # Get Metric Name metricName = '.' . join ( [ re . sub ( r'\.|\\' , '_' , vserverName ) , k ] ) # Get Metric Value metricValue = int ( self . get ( vserverGuageOid , host , port , community ) [ vserverGuageOid ] . strip ( "\'" ) ) # Get Metric Path metricPath = '.' . join ( [ 'devices' , device , 'vserver' , metricName ] ) # Create Metric metric = Metric ( metricPath , metricValue , timestamp , 0 ) # Publish Metric self . publish_metric ( metric )