(self, tags, network_ids, exclude_network_id_rules)
Collect stats for all reachable networks
Collect stats for all reachable networks
Collect stats for all reachable networks
def collect_networks_metrics(self, tags, network_ids, exclude_network_id_rules):
        """
        Collect stats for all reachable networks
        """
        networks = self.get_networks()
        filtered_networks = []
        if not network_ids:
            # Filter out excluded networks
            filtered_networks = [
                network
                for network in networks
                if not any([re.match(exclude_id, network.get('id')) for exclude_id in exclude_network_id_rules])
            ]
        else:
            for network in networks:
                if network.get('id') in network_ids:
                    filtered_networks.append(network)

        for network in filtered_networks:
            network_id = network.get('id')
            service_check_tags = ['network:{}'.format(network_id)] + tags

            network_name = network.get('name')
            if network_name:
                service_check_tags.append('network_name:{}'.format(network_name))

            tenant_id = network.get('tenant_id')
            if tenant_id:
                service_check_tags.append('tenant_id:{}'.format(tenant_id))

            if network.get('admin_state_up'):
                self.service_check(self.NETWORK_SC, AgentCheck.OK, tags=service_check_tags)
            else:
                self.service_check(self.NETWORK_SC, AgentCheck.CRITICAL, tags=service_check_tags)
def collect_networks_metrics ( self , tags , network_ids , exclude_network_id_rules ) : networks = self . get_networks ( ) filtered_networks = [ ] if not network_ids : # Filter out excluded networks filtered_networks = [ network for network in networks if not any ( [ re . match ( exclude_id , network . get ( 'id' ) ) for exclude_id in exclude_network_id_rules ] ) ] else : for network in networks : if network . get ( 'id' ) in network_ids : filtered_networks . append ( network ) for network in filtered_networks : network_id = network . get ( 'id' ) service_check_tags = [ 'network:{}' . format ( network_id ) ] + tags network_name = network . get ( 'name' ) if network_name : service_check_tags . append ( 'network_name:{}' . format ( network_name ) ) tenant_id = network . get ( 'tenant_id' ) if tenant_id : service_check_tags . append ( 'tenant_id:{}' . format ( tenant_id ) ) if network . get ( 'admin_state_up' ) : self . service_check ( self . NETWORK_SC , AgentCheck . OK , tags = service_check_tags ) else : self . service_check ( self . NETWORK_SC , AgentCheck . CRITICAL , tags = service_check_tags )