n8n-nodes-arubacentral
Version:
n8n community node for Aruba Central API integration with comprehensive monitoring, configuration, and management capabilities
49 lines (41 loc) • 1.64 kB
text/typescript
import { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
import { apiRequest } from '../../../../helpers/apiRequest';
import { logger } from '../../../../helpers/logger';
import { handleApiError } from '../../../../helpers/errorHandler';
/**
* List AI Insights for a Switch
*
* GET /aiops/v2/insights/switch/{sw_serial}/list
*
* @param this The n8n execution context
* @returns Formatted API response
*/
export async function getInsightsSwitch(this: IExecuteFunctions): Promise<INodeExecutionData[]> {
try {
// Get parameters
const swSerial = this.getNodeParameter('sw_serial', 0) as string;
const fromDate = new Date(this.getNodeParameter('from', 0) as string);
const toDate = new Date(this.getNodeParameter('to', 0) as string);
// Convert dates to epoch milliseconds for API
const fromMs = fromDate.getTime();
const toMs = toDate.getTime();
logger.debug(
'aiops:insights:getInsightsSwitch',
`Getting insights for switch=${swSerial}, from=${fromMs}, to=${toMs}`,
);
// Construct query parameters
const qs = {
from: fromMs,
to: toMs,
};
// Make API request
const endpoint = `/aiops/v2/insights/switch/${encodeURIComponent(swSerial)}/list`;
const responseData = await apiRequest.call(this, 'GET', endpoint, {}, qs);
logger.debug('aiops:insights:getInsightsSwitch', 'Successfully retrieved insights for switch');
// Return formatted response
return [{ json: responseData }];
} catch (error) {
logger.error('aiops:insights:getInsightsSwitch:error', { message: error.message });
return handleApiError.call(this, error, 'Failed to list AI insights for switch');
}
}