n8n-nodes-arubacentral
Version:
n8n community node for Aruba Central API integration with comprehensive monitoring, configuration, and management capabilities
56 lines (55 loc) • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCxSwitchPortsBandwidthUsage = getCxSwitchPortsBandwidthUsage;
const apiRequest_1 = require("../../../../helpers/apiRequest");
const logger_1 = require("../../../../helpers/logger");
const errorHandler_1 = require("../../../../helpers/errorHandler");
/**
* Get Ports Bandwidth Usage for CX Switch
*
* GET /monitoring/v1/cx_switches/{serial}/ports/bandwidth_usage
*
* @param this The n8n execution context
* @returns Formatted API response
*/
async function getCxSwitchPortsBandwidthUsage() {
try {
// Get parameters
const serial = this.getNodeParameter('serial', 0);
const fromTimestamp = this.getNodeParameter('from_timestamp', 0, '');
const toTimestamp = this.getNodeParameter('to_timestamp', 0, '');
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Construct query parameters
const qs = {};
// 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 show_uplink parameter if provided
if (additionalFields.show_uplink !== undefined) {
qs.show_uplink = additionalFields.show_uplink;
}
logger_1.logger.debug('monitoring:switch:getCxSwitchPortsBandwidthUsage', `Getting ports bandwidth usage for CX switch with serial: ${serial}`);
// Make API request
const endpoint = `/monitoring/v1/cx_switches/${encodeURIComponent(serial)}/ports/bandwidth_usage`;
const responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, qs);
logger_1.logger.debug('monitoring:switch:getCxSwitchPortsBandwidthUsage', 'Successfully retrieved CX switch ports bandwidth usage');
// Return formatted response
return [{ json: responseData }];
}
catch (error) {
logger_1.logger.error('monitoring:switch:getCxSwitchPortsBandwidthUsage:error', {
message: error.message,
});
return errorHandler_1.handleApiError.call(this, error, 'Failed to get CX switch ports bandwidth usage');
}
}