UNPKG

n8n-nodes-arubacentral

Version:

n8n community node for Aruba Central API integration with comprehensive monitoring, configuration, and management capabilities

62 lines (61 loc) 2.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listSwitches = listSwitches; const apiRequest_1 = require("../../../../helpers/apiRequest"); const logger_1 = require("../../../../helpers/logger"); const errorHandler_1 = require("../../../../helpers/errorHandler"); const pagination_1 = require("../../../../helpers/pagination"); /** * List Switches * * GET /monitoring/v1/switches * * @param this The n8n execution context * @returns Formatted API response */ async function listSwitches() { try { const returnAll = this.getNodeParameter('returnAll', 0, false); const limit = returnAll ? 0 : this.getNodeParameter('limit', 0, 100); // Get additional fields const additionalFields = this.getNodeParameter('additionalFields', 0, {}); // Construct query parameters const qs = {}; // Map all additional fields to query parameters const paramMappings = { group: 'group', label: 'label', stack_id: 'stack_id', status: 'status', fields: 'fields', calculate_total: 'calculate_total', show_resource_details: 'show_resource_details', calculate_client_count: 'calculate_client_count', public_ip_address: 'public_ip_address', site: 'site', sort: 'sort', }; // Process all additional fields and map to query parameters for (const [key, apiParam] of Object.entries(paramMappings)) { if (additionalFields[key] !== undefined && additionalFields[key] !== '') { qs[apiParam] = additionalFields[key]; logger_1.logger.debug(`parameter:${key}`, `Setting ${apiParam} to ${additionalFields[key]}`); } } logger_1.logger.debug('monitoring:switch:listSwitches', `Getting switches with parameters: ${JSON.stringify(qs)}`); // Handle pagination if (!returnAll && limit > 0) { return await pagination_1.handlePagination.call(this, '/monitoring/v1/switches', 'GET', {}, qs, { path: ['switches'] }, returnAll, limit); } // Make API request const endpoint = '/monitoring/v1/switches'; const responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, qs); logger_1.logger.debug('monitoring:switch:listSwitches', 'Successfully retrieved switches list'); // Return formatted response return [{ json: responseData }]; } catch (error) { logger_1.logger.error('monitoring:switch:listSwitches:error', { message: error.message }); return errorHandler_1.handleApiError.call(this, error, 'Failed to list switches'); } }