n8n-nodes-arubacentral
Version:
n8n community node for Aruba Central API integration with comprehensive monitoring, configuration, and management capabilities
204 lines (203 loc) • 8.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWirelessClients = getWirelessClients;
exports.getWiredClients = getWiredClients;
exports.getUnifiedClients = getUnifiedClients;
const apiRequest_1 = require("../../../../helpers/apiRequest");
const logger_1 = require("../../../../helpers/logger");
const errorHandler_1 = require("../../../../helpers/errorHandler");
const client_types_1 = require("../client.types");
/**
* Valid client types for unified client operations
*/
const CLIENT_TYPES = {
WIRELESS: 'WIRELESS',
WIRED: 'WIRED',
};
/**
* Valid client statuses for unified client operations
*/
const CLIENT_STATUSES = {
CONNECTED: 'CONNECTED',
FAILED_TO_CONNECT: 'FAILED_TO_CONNECT',
};
/**
* Validates that only one of the mutually exclusive parameters is provided
*/
function validateMutuallyExclusiveParams(params, exclusiveParams) {
const providedParams = exclusiveParams.filter((param) => params[param] && params[param].toString().trim());
if (providedParams.length > 1) {
return `You can only specify one of: ${exclusiveParams.join(', ')}. Found: ${providedParams.join(', ')}`;
}
return null;
}
/**
* Validates client type and status combination
*/
function validateClientTypeAndStatus(clientType, clientStatus) {
if (clientStatus === CLIENT_STATUSES.FAILED_TO_CONNECT && clientType !== CLIENT_TYPES.WIRELESS) {
return 'Failed to connect status is not supported for wired clients';
}
return null;
}
/**
* Builds query parameters object from UI inputs, filtering out empty values
*/
function buildQueryParameters(params) {
const queryParams = {};
for (const [key, value] of Object.entries(params)) {
if (value !== undefined && value !== null) {
// Handle string values
if (typeof value === 'string') {
const trimmed = value.trim();
if (trimmed) {
queryParams[key] = trimmed;
}
}
// Handle boolean values
else if (typeof value === 'boolean') {
queryParams[key] = value;
}
// Handle number values
else if (typeof value === 'number' && value >= 0) {
queryParams[key] = value;
}
}
}
return queryParams;
}
/**
* Get a list of Connected wireless clients from Aruba Central
*
* @param this The n8n execution context
* @returns Formatted list of wireless clients
*/
async function getWirelessClients() {
var _a;
try {
logger_1.logger.debug('monitoring:client:getWirelessClients', 'Getting wireless clients');
// Get parameters from UI
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Build query parameters using utility function
const queryParameters = buildQueryParameters(additionalFields);
logger_1.logger.debug('monitoring:client:getWirelessClients', 'Query parameters:', queryParameters);
// Make API request to get wireless clients
const response = await apiRequest_1.apiRequest.call(this, 'GET', '/monitoring/v1/clients/wireless', {}, queryParameters);
logger_1.logger.debug('monitoring:client:getWirelessClients', `Got ${((_a = response.clients) === null || _a === void 0 ? void 0 : _a.length) || 0} wireless clients`);
// Validate and return the response
if ((0, client_types_1.validateClientResponse)(response)) {
return [{ json: response }];
}
else {
logger_1.logger.warn('monitoring:client:getWirelessClients', 'Response validation failed', response);
return [{ json: response }];
}
}
catch (error) {
return errorHandler_1.handleApiError.call(this, error, 'Failed to get wireless clients');
}
}
/**
* Get a list of Connected wired clients from Aruba Central
*
* @param this The n8n execution context
* @returns Formatted list of wired clients
*/
async function getWiredClients() {
var _a;
try {
logger_1.logger.debug('monitoring:client:getWiredClients', 'Getting wired clients');
// Get parameters from UI
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Build query parameters using utility function
const queryParameters = buildQueryParameters(additionalFields);
logger_1.logger.debug('monitoring:client:getWiredClients', 'Query parameters:', queryParameters);
// Make API request to get wired clients
const response = await apiRequest_1.apiRequest.call(this, 'GET', '/monitoring/v1/clients/wired', {}, queryParameters);
logger_1.logger.debug('monitoring:client:getWiredClients', `Got ${((_a = response.clients) === null || _a === void 0 ? void 0 : _a.length) || 0} wired clients`);
// Validate and return the response
if ((0, client_types_1.validateClientResponse)(response)) {
return [{ json: response }];
}
else {
logger_1.logger.warn('monitoring:client:getWiredClients', 'Response validation failed', response);
return [{ json: response }];
}
}
catch (error) {
return errorHandler_1.handleApiError.call(this, error, 'Failed to get wired clients');
}
}
/**
* Get a list of unified clients from Aruba Central
* This is a unified form of the wired and wireless client APIs
*
* @param this The n8n execution context
* @returns Formatted list of unified clients
*/
async function getUnifiedClients() {
var _a, _b, _c;
try {
logger_1.logger.debug('monitoring:client:getUnifiedClients', 'Getting unified clients');
// Get required parameters
const clientType = this.getNodeParameter('client_type', 0);
const clientStatus = this.getNodeParameter('client_status', 0);
const timerange = this.getNodeParameter('timerange', 0);
// Validate client type and status combination
const statusError = validateClientTypeAndStatus(clientType, clientStatus);
if (statusError) {
throw new Error(statusError);
}
// Get optional parameters from UI
const additionalFields = this.getNodeParameter('additionalFields', 0, {});
// Validate mutually exclusive parameters
const exclusiveError = validateMutuallyExclusiveParams(additionalFields, [
'group',
'swarm_id',
'cluster_id',
'network',
'site',
'label',
]);
if (exclusiveError) {
throw new Error(exclusiveError);
}
// Validate wireless-only parameters
if (clientType !== CLIENT_TYPES.WIRELESS) {
if ((_a = additionalFields.band) === null || _a === void 0 ? void 0 : _a.trim()) {
throw new Error('Band filter is only supported for wireless clients');
}
if (additionalFields.show_signal_db !== undefined) {
throw new Error('Show signal DB is only supported for wireless clients');
}
}
// Validate wired-only parameters
if (clientType !== CLIENT_TYPES.WIRED) {
if ((_b = additionalFields.stack_id) === null || _b === void 0 ? void 0 : _b.trim()) {
throw new Error('Stack ID filter is only supported for wired clients');
}
}
// Build query parameters using utility function
const queryParameters = buildQueryParameters({
client_type: clientType,
client_status: clientStatus,
timerange: timerange,
...additionalFields,
});
logger_1.logger.debug('monitoring:client:getUnifiedClients', `Getting ${clientType.toLowerCase()} clients with status ${clientStatus}`, queryParameters);
// Make API request to get unified clients
const response = await apiRequest_1.apiRequest.call(this, 'GET', '/monitoring/v2/clients', {}, queryParameters);
logger_1.logger.debug('monitoring:client:getUnifiedClients', `Got ${((_c = response.clients) === null || _c === void 0 ? void 0 : _c.length) || 0} unified ${clientType.toLowerCase()} clients with status ${clientStatus}`);
// Validate and return the response
if ((0, client_types_1.validateClientResponse)(response)) {
return [{ json: response }];
}
else {
logger_1.logger.warn('monitoring:client:getUnifiedClients', 'Response validation failed', response);
return [{ json: response }];
}
}
catch (error) {
return errorHandler_1.handleApiError.call(this, error, 'Failed to get unified clients');
}
}