From 89373a495c5a942929612bfac56d1b265d3225b9 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Wed, 8 May 2024 12:53:14 -0300 Subject: [PATCH 1/9] Update imposter --- .../cluster/configuration/com_cluster.json | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docker/imposter/cluster/configuration/com_cluster.json b/docker/imposter/cluster/configuration/com_cluster.json index 4072ebafe8..a5716a1cac 100644 --- a/docker/imposter/cluster/configuration/com_cluster.json +++ b/docker/imposter/cluster/configuration/com_cluster.json @@ -10,7 +10,21 @@ "port": 1516, "bind_addr": "0.0.0.0", "nodes": ["0.0.0.0"], - "hidden": "no" + "hidden": "no", + "haproxy_helper": { + "haproxy_disabled": "no", + "haproxy_address": "wazuh-proxy", + "haproxy_user": "haproxy", + "haproxy_port": 5555, + "haproxy_protocol": "http", + "haproxy_backend": "wazuh_cluster", + "frequency": 60, + "agent_chunk_size": 10, + "agent_reconnection_time": 10, + "agent_reconnection_stability_time": 60, + "imbalance_tolerance": 0.1, + "remove_disconnected_node_after": 1 + } } ], "total_affected_items": 1, From b6e194715a995bff5055acc471ecc2e22f15ffa0 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Wed, 8 May 2024 12:53:44 -0300 Subject: [PATCH 2/9] Add HAProxy settings to cluster configuration page --- .../configuration/cluster/cluster.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js index b299763d89..cd18dbfc7d 100644 --- a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js +++ b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js @@ -38,6 +38,30 @@ const mainSettings = [ { field: 'hidden', label: 'Hide cluster information in alerts' }, ]; +const haproxySettings = [ + { field: 'haproxy_helper.haproxy_disabled', label: 'Disabled' }, + { field: 'haproxy_helper.haproxy_address', label: 'Address' }, + { field: 'haproxy_helper.haproxy_user', label: 'User' }, + { field: 'haproxy_helper.haproxy_port', label: 'Port' }, + { field: 'haproxy_helper.haproxy_protocol', label: 'Protocol' }, + { field: 'haproxy_helper.haproxy_backend', label: 'Backend' }, + { field: 'haproxy_helper.frequency', label: 'Frequency' }, + { field: 'haproxy_helper.agent_chunk_size', label: 'Agent chunk size' }, + { + field: 'haproxy_helper.agent_reconnection_time', + label: 'Agent reconnection time', + }, + { + field: 'haproxy_helper.agent_reconnection_stability_time', + label: 'Agent reconnection stability time', + }, + { field: 'haproxy_helper.imbalance_tolerance', label: 'Imbalance tolerance' }, + { + field: 'haproxy_helper.remove_disconnected_node_after', + label: 'Remove disconnected node after', + }, +]; + const helpLinks = [ { text: 'Configuring a cluster', @@ -82,6 +106,11 @@ class WzCluster extends Component { config={mainSettingsConfig} items={mainSettings} /> + )} From d732eb7c2ed5fd28f17e4d523a6c4ecbb2c74313 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Wed, 8 May 2024 18:04:59 -0300 Subject: [PATCH 3/9] Add HAProxy password, resolver and excluded nodes field to cluster configuration page --- .../management/configuration/cluster/cluster.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js index cd18dbfc7d..e15ce42f06 100644 --- a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js +++ b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js @@ -42,6 +42,7 @@ const haproxySettings = [ { field: 'haproxy_helper.haproxy_disabled', label: 'Disabled' }, { field: 'haproxy_helper.haproxy_address', label: 'Address' }, { field: 'haproxy_helper.haproxy_user', label: 'User' }, + { field: 'haproxy_helper.haproxy_password', label: 'Password' }, { field: 'haproxy_helper.haproxy_port', label: 'Port' }, { field: 'haproxy_helper.haproxy_protocol', label: 'Protocol' }, { field: 'haproxy_helper.haproxy_backend', label: 'Backend' }, @@ -60,6 +61,8 @@ const haproxySettings = [ field: 'haproxy_helper.remove_disconnected_node_after', label: 'Remove disconnected node after', }, + { field: 'haproxy_helper.haproxy_resolver', label: 'Resolver' }, + { field: 'haproxy_helper.excluded_nodes', label: 'Excluded nodes' }, ]; const helpLinks = [ @@ -82,9 +85,14 @@ class WzCluster extends Component { let mainSettingsConfig = { ...currentConfig['com-cluster'], disabled: - currentConfig['com-cluster'].disabled === 'yes' - ? 'disabled' - : 'enabled', + currentConfig['com-cluster'].disabled === true ? 'disabled' : 'enabled', + haproxy_helper: { + ...currentConfig['com-cluster'].haproxy_helper, + haproxy_disabled: + currentConfig['com-cluster'].haproxy_helper.haproxy_disabled === true + ? 'disabled' + : 'enabled', + }, }; return ( From 12bdf78223ecf742c9f9d9efd7bd76859aa679cf Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Thu, 9 May 2024 11:09:05 -0300 Subject: [PATCH 4/9] Update imposter --- .../cluster/configuration/com_cluster.json | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docker/imposter/cluster/configuration/com_cluster.json b/docker/imposter/cluster/configuration/com_cluster.json index a5716a1cac..dc7915acaf 100644 --- a/docker/imposter/cluster/configuration/com_cluster.json +++ b/docker/imposter/cluster/configuration/com_cluster.json @@ -12,18 +12,21 @@ "nodes": ["0.0.0.0"], "hidden": "no", "haproxy_helper": { - "haproxy_disabled": "no", + "haproxy_disabled": false, "haproxy_address": "wazuh-proxy", "haproxy_user": "haproxy", - "haproxy_port": 5555, - "haproxy_protocol": "http", - "haproxy_backend": "wazuh_cluster", + "haproxy_password": "haproxy", "frequency": 60, - "agent_chunk_size": 10, - "agent_reconnection_time": 10, "agent_reconnection_stability_time": 60, + "agent_chunk_size": 300, + "haproxy_protocol": "http", + "haproxy_backend": "wazuh_cluster", + "agent_reconnection_time": 5, + "haproxy_port": 5555, + "haproxy_resolver": null, "imbalance_tolerance": 0.1, - "remove_disconnected_node_after": 1 + "remove_disconnected_node_after": 240, + "excluded_nodes": [] } } ], From cebdc282ccaf07670f9cc9146ad16e7b2cac56d0 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Thu, 9 May 2024 11:11:53 -0300 Subject: [PATCH 5/9] Add conditional to the rendering of the haproxy helper settings --- .../configuration/cluster/cluster.js | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js index e15ce42f06..b2392b972c 100644 --- a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js +++ b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js @@ -86,14 +86,21 @@ class WzCluster extends Component { ...currentConfig['com-cluster'], disabled: currentConfig['com-cluster'].disabled === true ? 'disabled' : 'enabled', - haproxy_helper: { - ...currentConfig['com-cluster'].haproxy_helper, - haproxy_disabled: - currentConfig['com-cluster'].haproxy_helper.haproxy_disabled === true - ? 'disabled' - : 'enabled', - }, }; + + if (currentConfig['com-cluster'].haproxy_helper) { + mainSettingsConfig = { + ...mainSettingsConfig, + haproxy_helper: { + ...currentConfig['com-cluster'].haproxy_helper, + haproxy_disabled: + currentConfig['com-cluster'].haproxy_helper.haproxy_disabled === + true + ? 'disabled' + : 'enabled', + }, + }; + } return ( {currentConfig['com-cluster'] && @@ -114,11 +121,13 @@ class WzCluster extends Component { config={mainSettingsConfig} items={mainSettings} /> - + {mainSettingsConfig.haproxy_helper && ( + + )} )} From 62a8ac234f4df9f41f9d583ca82b0fdc3045f059 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Thu, 9 May 2024 11:35:59 -0300 Subject: [PATCH 6/9] feat: Update HAProxy label in cluster configuration page --- .../components/management/configuration/cluster/cluster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js index b2392b972c..717933598f 100644 --- a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js +++ b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js @@ -39,7 +39,7 @@ const mainSettings = [ ]; const haproxySettings = [ - { field: 'haproxy_helper.haproxy_disabled', label: 'Disabled' }, + { field: 'haproxy_helper.haproxy_disabled', label: 'HAProxy status' }, { field: 'haproxy_helper.haproxy_address', label: 'Address' }, { field: 'haproxy_helper.haproxy_user', label: 'User' }, { field: 'haproxy_helper.haproxy_password', label: 'Password' }, From 87c872fbd7e4633520ba297976262185aad7c646 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Thu, 9 May 2024 17:59:21 -0300 Subject: [PATCH 7/9] Add test --- .../__snapshots__/cluster.test.js.snap | 1402 +++++++++++++++++ .../configuration/cluster/cluster.js | 2 +- .../configuration/cluster/cluster.test.js | 92 ++ 3 files changed, 1495 insertions(+), 1 deletion(-) create mode 100644 plugins/main/public/controllers/management/components/management/configuration/cluster/__snapshots__/cluster.test.js.snap create mode 100644 plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.test.js diff --git a/plugins/main/public/controllers/management/components/management/configuration/cluster/__snapshots__/cluster.test.js.snap b/plugins/main/public/controllers/management/components/management/configuration/cluster/__snapshots__/cluster.test.js.snap new file mode 100644 index 0000000000..ee05312cc0 --- /dev/null +++ b/plugins/main/public/controllers/management/components/management/configuration/cluster/__snapshots__/cluster.test.js.snap @@ -0,0 +1,1402 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Cluster settings should render the cluster settings 1`] = ` +
+
+
+

+ Main settings +

+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+

+

+
+
+
+
+
+
+
+
+
+
+
+ Cluster status +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Cluster name +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Node name +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Node type +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Master node IP address +
+
+
+
    +
  • +
    +
    + +
    +
    +
  • +
+
+
+
+
+
+
+ Port to listen to cluster communications +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ IP address to listen to cluster communications +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Hide cluster information in alerts +
+
+
+
+
+ +
+
+
+
+
+
+
+
+`; + +exports[`Cluster settings should render the cluster settings with HAProxy helper 1`] = ` +
+
+
+

+ Main settings +

+
+
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+

+

+
+
+
+
+
+
+
+
+
+
+
+ Cluster status +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Cluster name +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Node name +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Node type +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Master node IP address +
+
+
+
    +
  • +
    +
    + +
    +
    +
  • +
+
+
+
+
+
+
+ Port to listen to cluster communications +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ IP address to listen to cluster communications +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Hide cluster information in alerts +
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+

+ HAProxy settings +

+
+
+
+
+
+
+
+
+
+
+
+
+
+ HAProxy status +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Address +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ User +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Password +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Port +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Protocol +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Backend +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Frequency +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Agent chunk size +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Agent reconnection time +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Agent reconnection stability time +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Imbalance tolerance +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Remove disconnected node after +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ Excluded nodes +
+
+
+
+
+ +
+
+
+
+
+
+
+
+`; + +exports[`Cluster settings should render the error message when the cluster setting is a string 1`] = ` +
+
+
+
+
+ + + Configuration not available + +
+
+ +
+
+
+ + There was a problem while fetching the configuration for this section. It may be a server problem or the configuration doesn't exist. + +
+
+

+ Click on the + + icon for help. Check the documentation links to learn more about how to configure it. +

+
+
+
+
+
+
+`; diff --git a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js index 717933598f..0fb82d94b3 100644 --- a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js +++ b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js @@ -76,7 +76,7 @@ const helpLinks = [ }, ]; -class WzCluster extends Component { +export class WzCluster extends Component { constructor(props) { super(props); } diff --git a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.test.js b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.test.js new file mode 100644 index 0000000000..26fb86512f --- /dev/null +++ b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.test.js @@ -0,0 +1,92 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { WzCluster } from './cluster'; + +const basicClusterSettings = { + 'com-cluster': { + disabled: false, + name: 'wazuh1', + node_name: 'master', + node_type: 'master', + key: 'test1234', + port: 1516, + bind_addr: '0.0.0.0', + nodes: ['0.0.0.0'], + hidden: 'no', + }, +}; + +const clusterSettingsWithHaproxyHelper = { + 'com-cluster': { + disabled: false, + name: 'wazuh1', + node_name: 'master', + node_type: 'master', + key: 'test1234', + port: 1516, + bind_addr: '0.0.0.0', + nodes: ['0.0.0.0'], + hidden: 'no', + haproxy_helper: { + haproxy_disabled: false, + haproxy_address: 'wazuh-proxy', + haproxy_user: 'haproxy', + haproxy_password: 'haproxy', + frequency: 60, + agent_reconnection_stability_time: 60, + agent_chunk_size: 300, + haproxy_protocol: 'http', + haproxy_backend: 'wazuh_cluster', + agent_reconnection_time: 5, + haproxy_port: 5555, + haproxy_resolver: null, + imbalance_tolerance: 0.1, + remove_disconnected_node_after: 240, + excluded_nodes: [], + }, + }, +}; + +describe('Cluster settings', () => { + it('should render the cluster settings', () => { + const { container, getByText, queryByText, getByTestId } = render( + , + ); + + expect(container).toMatchSnapshot(); + + expect(getByText('Cluster status')).toBeInTheDocument(); + expect(getByTestId('cluster-status').value).toBe('enabled'); + expect(queryByText('HAProxy settings')).toBeFalsy(); + }); + + it('should render the cluster settings with HAProxy helper', () => { + const { container, getByText, getByTestId } = render( + , + ); + + expect(container).toMatchSnapshot(); + + expect(getByText('Cluster status')).toBeInTheDocument(); + expect(getByTestId('cluster-status').value).toBe('enabled'); + expect(getByText('HAProxy settings')).toBeInTheDocument(); + expect(getByTestId('haproxy-status').value).toBe('enabled'); + expect(getByTestId('user').value).toBe( + clusterSettingsWithHaproxyHelper['com-cluster'].haproxy_helper + .haproxy_user, + ); + }); + + it('should render the error message when the cluster setting is a string', () => { + const { container, getByText, queryByText } = render( + , + ); + + expect(container).toMatchSnapshot(); + + expect(getByText('Configuration not available')).toBeInTheDocument(); + expect(queryByText('Cluster status')).toBeFalsy(); + expect(queryByText('HAProxy settings')).toBeFalsy(); + }); +}); From 2d7c43938a90b4fe102348fa036da015e608639e Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Tue, 14 May 2024 12:37:23 -0300 Subject: [PATCH 8/9] feat: Add renderValueOrNoValue function to cluster.js --- .../management/configuration/cluster/cluster.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js index 0fb82d94b3..823cf48f0c 100644 --- a/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js +++ b/plugins/main/public/controllers/management/components/management/configuration/cluster/cluster.js @@ -17,7 +17,7 @@ import WzConfigurationSettingsGroup from '../util-components/configuration-setti import WzConfigurationSettingsHeader from '../util-components/configuration-settings-header'; import WzNoConfig from '../util-components/no-config'; import withWzConfig from '../util-hocs/wz-config'; -import { isString } from '../utils/utils'; +import { isString, renderValueOrNoValue } from '../utils/utils'; import { connect } from 'react-redux'; import { compose } from 'redux'; @@ -62,7 +62,11 @@ const haproxySettings = [ label: 'Remove disconnected node after', }, { field: 'haproxy_helper.haproxy_resolver', label: 'Resolver' }, - { field: 'haproxy_helper.excluded_nodes', label: 'Excluded nodes' }, + { + field: 'haproxy_helper.excluded_nodes', + label: 'Excluded nodes', + render: renderValueOrNoValue, + }, ]; const helpLinks = [ From 757eaba8e3ee28486ab94ef420a19ff41cc1a7d7 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano Date: Tue, 14 May 2024 12:53:30 -0300 Subject: [PATCH 9/9] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8abef82d09..788df565c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Added macOS log collector tab [#6545](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6545) - Add ability to disable the edition of configuration through API endpoints and UI [#6557](https://github.com/wazuh/wazuh-dashboard-plugins/issues/6557) - Added journald log collector tab [#6572](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6572) +- Added HAProxy helper settings to cluster configuration [#6653](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6653) ### Changed