UNPKG

n8n-nodes-arubacentral

Version:

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

56 lines (55 loc) 2.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTopNSwitches = getTopNSwitches; const apiRequest_1 = require("../../../../helpers/apiRequest"); const logger_1 = require("../../../../helpers/logger"); const errorHandler_1 = require("../../../../helpers/errorHandler"); /** * Get Top N Switches * * GET /monitoring/v1/switches/bandwidth_usage/topn * * @param this The n8n execution context * @returns Formatted API response */ async function getTopNSwitches() { try { // Get filter type and corresponding value const filterType = this.getNodeParameter('filterType', 0); // Get other parameters const count = this.getNodeParameter('count', 0); const fromTimestamp = this.getNodeParameter('from_timestamp', 0, ''); const toTimestamp = this.getNodeParameter('to_timestamp', 0, ''); // Construct query parameters const qs = { count, }; // Add filter parameter if not "none" if (filterType !== 'none') { const filterValue = this.getNodeParameter(filterType, 0, ''); if (filterValue) { qs[filterType] = filterValue; } } // Add time range parameters if (fromTimestamp) { const fromDate = new Date(fromTimestamp); qs.from_timestamp = Math.floor(fromDate.getTime() / 1000); } if (toTimestamp) { const toDate = new Date(toTimestamp); qs.to_timestamp = Math.floor(toDate.getTime() / 1000); } logger_1.logger.debug('monitoring:switch:getTopNSwitches', `Getting top ${count} switches with filter ${filterType !== 'none' ? filterType + '=' + qs[filterType] : 'none'}`); // Make API request const endpoint = '/monitoring/v1/switches/bandwidth_usage/topn'; const responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, qs); logger_1.logger.debug('monitoring:switch:getTopNSwitches', 'Successfully retrieved top N switches'); // Return formatted response return [{ json: responseData }]; } catch (error) { logger_1.logger.error('monitoring:switch:getTopNSwitches:error', { message: error.message }); return errorHandler_1.handleApiError.call(this, error, 'Failed to get top N switches'); } }