n8n-nodes-arubacentral
Version:
n8n community node for Aruba Central API integration with comprehensive monitoring, configuration, and management capabilities
64 lines (63 loc) • 2.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSwitchVlanInfo = getSwitchVlanInfo;
const apiRequest_1 = require("../../../../helpers/apiRequest");
const logger_1 = require("../../../../helpers/logger");
const errorHandler_1 = require("../../../../helpers/errorHandler");
const pagination_1 = require("../../../../helpers/pagination");
/**
* Get VLAN Info of the Switch
*
* GET /monitoring/v1/switches/{serial}/vlan
*
* @param this The n8n execution context
* @returns Formatted API response
*/
async function getSwitchVlanInfo() {
try {
// Get parameters
const serial = this.getNodeParameter('serial', 0);
const returnAll = this.getNodeParameter('returnAll', 0, false);
const limit = returnAll ? 0 : this.getNodeParameter('limit', 0, 50);
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Construct query parameters
const qs = {};
// Map all additional fields to query parameters
const paramMappings = {
name: 'name',
id: 'id',
tagged_port: 'tagged_port',
untagged_port: 'untagged_port',
is_jumbo_enabled: 'is_jumbo_enabled',
is_voice_enabled: 'is_voice_enabled',
is_igmp_enabled: 'is_igmp_enabled',
type: 'type',
primary_vlan_id: 'primary_vlan_id',
status: 'status',
sort: 'sort',
calculate_total: 'calculate_total',
};
// 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('monitoring:switch:getSwitchVlanInfo', `Getting VLAN info for switch with serial: ${serial}`);
// Handle pagination
if (!returnAll && limit > 0) {
qs.limit = limit;
return await pagination_1.handlePagination.call(this, `/monitoring/v1/switches/${encodeURIComponent(serial)}/vlan`, 'GET', {}, qs, { path: ['vlans'] }, returnAll, limit);
}
// Make API request
const endpoint = `/monitoring/v1/switches/${encodeURIComponent(serial)}/vlan`;
const responseData = await apiRequest_1.apiRequest.call(this, 'GET', endpoint, {}, qs);
logger_1.logger.debug('monitoring:switch:getSwitchVlanInfo', 'Successfully retrieved switch VLAN info');
// Return formatted response
return [{ json: responseData }];
}
catch (error) {
logger_1.logger.error('monitoring:switch:getSwitchVlanInfo:error', { message: error.message });
return errorHandler_1.handleApiError.call(this, error, 'Failed to get switch VLAN info');
}
}