UNPKG

n8n-nodes-arubacentral

Version:

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

69 lines (58 loc) 2.27 kB
import { IExecuteFunctions, INodeExecutionData, IDataObject } from 'n8n-workflow'; import { apiRequest } from '../../../../helpers/apiRequest'; import { logger } from '../../../../helpers/logger'; import { handleApiError } from '../../../../helpers/errorHandler'; /** * Get CX Switch Ports Errors * * GET /monitoring/v1/cx_switches/{serial}/ports/errors * * @param this The n8n execution context * @returns Formatted API response */ export async function getCxSwitchPortsErrors( this: IExecuteFunctions, ): Promise<INodeExecutionData[]> { try { // Get parameters const serial = this.getNodeParameter('serial', 0) as string; const fromTimestamp = this.getNodeParameter('from_timestamp', 0, '') as string; const toTimestamp = this.getNodeParameter('to_timestamp', 0, '') as string; const additionalFields = this.getNodeParameter('additionalFields', 0, {}) as IDataObject; // Construct query parameters const qs: IDataObject = {}; // 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); } // Add port parameter if provided if (additionalFields.port !== undefined && additionalFields.port !== '') { qs.port = additionalFields.port; } // Add error parameter if provided if (additionalFields.error !== undefined && additionalFields.error !== '') { qs.error = additionalFields.error; } logger.debug( 'monitoring:switch:getCxSwitchPortsErrors', `Getting ports errors for CX switch with serial: ${serial}`, ); // Make API request const endpoint = `/monitoring/v1/cx_switches/${encodeURIComponent(serial)}/ports/errors`; const responseData = await apiRequest.call(this, 'GET', endpoint, {}, qs); logger.debug( 'monitoring:switch:getCxSwitchPortsErrors', 'Successfully retrieved CX switch ports errors', ); // Return formatted response return [{ json: responseData }]; } catch (error) { logger.error('monitoring:switch:getCxSwitchPortsErrors:error', { message: error.message }); return handleApiError.call(this, error, 'Failed to get CX switch ports errors'); } }