From ba576121b75bf26f96630a4946a4a511acf54f7e Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Thu, 30 Nov 2023 12:10:58 -0300 Subject: [PATCH 1/7] Improve Agents preview page load when there are no agents --- .../controllers/agent/agents-preview.js | 52 +++-- .../agent/components/agents-preview.js | 41 +--- .../templates/agents-prev/agents-prev.html | 2 +- .../templates/visualize/dashboards.html | 206 +++++++----------- 4 files changed, 126 insertions(+), 175 deletions(-) diff --git a/plugins/main/public/controllers/agent/agents-preview.js b/plugins/main/public/controllers/agent/agents-preview.js index 6fd90cce6e..fd5bfba2f1 100644 --- a/plugins/main/public/controllers/agent/agents-preview.js +++ b/plugins/main/public/controllers/agent/agents-preview.js @@ -25,7 +25,6 @@ import store from '../../redux/store'; import { UI_LOGGER_LEVELS } from '../../../common/constants'; import { UI_ERROR_SEVERITIES } from '../../react-services/error-orchestrator/types'; import { getErrorOrchestrator } from '../../react-services/common-services'; -import { webDocumentationLink } from '../../../common/services/web_documentation'; export class AgentsPreviewController { /** @@ -108,17 +107,12 @@ export class AgentsPreviewController { this.hasAgents = true; this.init = false; const instance = new DataFactory(WzRequest.apiReq, '/agents', false, false); + + //Load + await this.load(); + //Props this.tableAgentsProps = { - updateSummary: summary => { - this.summary = summary; - if (this.summary.total === 0) { - this.addNewAgent(true); - this.hasAgents = false; - } else { - this.hasAgents = true; - } - }, wzReq: (method, path, body) => WzRequest.apiReq(method, path, body), addingNewAgent: () => { this.addNewAgent(true); @@ -147,10 +141,9 @@ export class AgentsPreviewController { this.$scope.$applyAsync(); }, formatUIDate: date => formatUIDate(date), - summary: this.summary, + agentStatusSummary: this.agentStatusSummary, + agentsActiveCoverage: this.agentsActiveCoverage, }; - //Load - this.load(); } /** @@ -255,6 +248,8 @@ export class AgentsPreviewController { this.pattern = ( await getDataPlugin().indexPatterns.get(AppState.getCurrentPattern()) ).title; + + await this.fetchSummaryStatus(); } catch (error) { const options = { context: `${AgentsPreviewController.name}.load`, @@ -273,6 +268,37 @@ export class AgentsPreviewController { this.$scope.$applyAsync(); } + async fetchSummaryStatus() { + const { + data: { + data: { + connection: agentStatusSummary, + configuration: agentConfiguration, + }, + }, + } = await WzRequest.apiReq('GET', '/agents/summary/status', {}); + + this.agentStatusSummary = agentStatusSummary; + if (agentStatusSummary.total === 0) { + this.addNewAgent(true); + this.hasAgents = false; + } else { + this.hasAgents = true; + } + + const agentsActiveCoverage = ( + (agentStatusSummary.active / agentStatusSummary.total) * + 100 + ).toFixed(2); + + /* Calculate the agents active coverage. + Ensure the calculated value is not a NaN, otherwise set a 0. + */ + this.agentsActiveCoverage = isNaN(agentsActiveCoverage) + ? 0 + : agentsActiveCoverage; + } + addNewAgent(flag) { this.addingNewAgent = flag; } diff --git a/plugins/main/public/controllers/agent/components/agents-preview.js b/plugins/main/public/controllers/agent/components/agents-preview.js index ef052c0745..b9214c07eb 100644 --- a/plugins/main/public/controllers/agent/components/agents-preview.js +++ b/plugins/main/public/controllers/agent/components/agents-preview.js @@ -74,15 +74,9 @@ export const AgentsPreview = compose( loadingSummary: false, showAgentsEvolutionVisualization: true, agentTableFilters: [], - agentStatusSummary: { - active: '-', - disconnected: '-', - total: '-', - pending: '-', - never_connected: '-', - }, + agentStatusSummary: props.tableProps.agentStatusSummary, agentConfiguration: {}, - agentsActiveCoverage: 0, + agentsActiveCoverage: props.tableProps.agentsActiveCoverage, }; this.wazuhConfig = new WazuhConfig(); this.agentStatus = UI_ORDER_AGENT_STATUS.map(agentStatus => ({ @@ -126,36 +120,6 @@ export const AgentsPreview = compose( return prev; }, {}); }; - async fetchSummaryStatus() { - this.setState({ loadingSummary: true }); - const { - data: { - data: { - connection: agentStatusSummary, - configuration: agentConfiguration, - }, - }, - } = await WzRequest.apiReq('GET', '/agents/summary/status', {}); - - this.props.tableProps.updateSummary(agentStatusSummary); - - const agentsActiveCoverage = ( - (agentStatusSummary.active / agentStatusSummary.total) * - 100 - ).toFixed(2); - - this.setState({ - loadingSummary: false, - agentStatusSummary, - agentConfiguration, - /* Calculate the agents active coverage. - Ensure the calculated value is not a NaN, otherwise set a 0. - */ - agentsActiveCoverage: isNaN(agentsActiveCoverage) - ? 0 - : agentsActiveCoverage, - }); - } async fetchAgents() { this.setState({ loadingAgents: true }); @@ -177,7 +141,6 @@ export const AgentsPreview = compose( } async fetchAgentStatusDetailsData() { try { - this.fetchSummaryStatus(); this.fetchAgents(); } catch (error) { this.setState({ loadingAgents: false, loadingSummary: false }); diff --git a/plugins/main/public/templates/agents-prev/agents-prev.html b/plugins/main/public/templates/agents-prev/agents-prev.html index 573720fea4..41e885e8fe 100644 --- a/plugins/main/public/templates/agents-prev/agents-prev.html +++ b/plugins/main/public/templates/agents-prev/agents-prev.html @@ -65,7 +65,7 @@ props="ctrl.registerAgentsProps" > -
+
-
- -
-
-
- -
- - -
+
+ +
+ + +
-
- - - -
+
+ + + +
- - + + +
-
-
- - - - - - -
-
{{reportStatus}}
-
-
+
+ + + + + + +
+
{{reportStatus}}
+
- +
+ +
+ +
+ +
- -
-
- - - - - - - - - No agents were added to this manager: - - Deploy new agent -
-
- -
-
- -
-
- - -
-
- -
+
+ + +
+
+ name="StatsOverview" + style="padding-bottom: 0" + flex + props="octrl.agentsCount" + />
- +
+
From 23a3fde177e08457b1c4bbe140443f3d83070dc4 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Thu, 30 Nov 2023 12:28:04 -0300 Subject: [PATCH 2/7] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fec9196d7..7bbf24b498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to the Wazuh app project will be documented in this file. ### Added - Support for Wazuh 4.7.2 +- Improved Agents preview page load when there are no registered agents [#6185](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6185) ## Wazuh v4.7.1 - OpenSearch Dashboards 2.8.0 - Revision 01 From 22c58c0887e2258b28e86767278f7a92b8982059 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Thu, 30 Nov 2023 13:47:42 -0300 Subject: [PATCH 3/7] Update breadcrumb on RegisterAgent --- .../containers/register-agent/register-agent.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx b/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx index 8ae23213cd..c976cf35f6 100644 --- a/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx +++ b/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx @@ -23,13 +23,17 @@ import { getGroups } from '../../services/register-agent-services'; import { useForm } from '../../../../components/common/form/hooks'; import { FormConfiguration } from '../../../../components/common/form/types'; import { useSelector } from 'react-redux'; -import { withReduxProvider } from '../../../../components/common/hocs'; +import { + withGlobalBreadcrumb, + withReduxProvider, +} from '../../../../components/common/hocs'; import GroupInput from '../../components/group-input/group-input'; import { OsCard } from '../../components/os-selector/os-card/os-card'; import { validateServerAddress, validateAgentName, } from '../../utils/validations'; +import { compose } from 'redux'; interface IRegisterAgentProps { getWazuhVersion: () => Promise; @@ -38,7 +42,10 @@ interface IRegisterAgentProps { reload: () => void; } -export const RegisterAgent = withReduxProvider( +export const RegisterAgent = compose( + withReduxProvider, + withGlobalBreadcrumb([{ text: '' }, { text: 'Agents' }]), +)( ({ getWazuhVersion, hasAgents, From c71490300707c971c46adf29debe684a2a599122 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Mon, 4 Dec 2023 17:06:17 -0300 Subject: [PATCH 4/7] Fix Agent preview component --- .../controllers/agent/agents-preview.js | 52 ++--- .../agent/components/agents-preview.js | 118 +++++++--- .../register-agent/register-agent.tsx | 11 +- .../templates/agents-prev/agents-prev.html | 4 +- .../templates/visualize/dashboards.html | 206 +++++++++++------- 5 files changed, 229 insertions(+), 162 deletions(-) diff --git a/plugins/main/public/controllers/agent/agents-preview.js b/plugins/main/public/controllers/agent/agents-preview.js index fd5bfba2f1..6fd90cce6e 100644 --- a/plugins/main/public/controllers/agent/agents-preview.js +++ b/plugins/main/public/controllers/agent/agents-preview.js @@ -25,6 +25,7 @@ import store from '../../redux/store'; import { UI_LOGGER_LEVELS } from '../../../common/constants'; import { UI_ERROR_SEVERITIES } from '../../react-services/error-orchestrator/types'; import { getErrorOrchestrator } from '../../react-services/common-services'; +import { webDocumentationLink } from '../../../common/services/web_documentation'; export class AgentsPreviewController { /** @@ -107,12 +108,17 @@ export class AgentsPreviewController { this.hasAgents = true; this.init = false; const instance = new DataFactory(WzRequest.apiReq, '/agents', false, false); - - //Load - await this.load(); - //Props this.tableAgentsProps = { + updateSummary: summary => { + this.summary = summary; + if (this.summary.total === 0) { + this.addNewAgent(true); + this.hasAgents = false; + } else { + this.hasAgents = true; + } + }, wzReq: (method, path, body) => WzRequest.apiReq(method, path, body), addingNewAgent: () => { this.addNewAgent(true); @@ -141,9 +147,10 @@ export class AgentsPreviewController { this.$scope.$applyAsync(); }, formatUIDate: date => formatUIDate(date), - agentStatusSummary: this.agentStatusSummary, - agentsActiveCoverage: this.agentsActiveCoverage, + summary: this.summary, }; + //Load + this.load(); } /** @@ -248,8 +255,6 @@ export class AgentsPreviewController { this.pattern = ( await getDataPlugin().indexPatterns.get(AppState.getCurrentPattern()) ).title; - - await this.fetchSummaryStatus(); } catch (error) { const options = { context: `${AgentsPreviewController.name}.load`, @@ -268,37 +273,6 @@ export class AgentsPreviewController { this.$scope.$applyAsync(); } - async fetchSummaryStatus() { - const { - data: { - data: { - connection: agentStatusSummary, - configuration: agentConfiguration, - }, - }, - } = await WzRequest.apiReq('GET', '/agents/summary/status', {}); - - this.agentStatusSummary = agentStatusSummary; - if (agentStatusSummary.total === 0) { - this.addNewAgent(true); - this.hasAgents = false; - } else { - this.hasAgents = true; - } - - const agentsActiveCoverage = ( - (agentStatusSummary.active / agentStatusSummary.total) * - 100 - ).toFixed(2); - - /* Calculate the agents active coverage. - Ensure the calculated value is not a NaN, otherwise set a 0. - */ - this.agentsActiveCoverage = isNaN(agentsActiveCoverage) - ? 0 - : agentsActiveCoverage; - } - addNewAgent(flag) { this.addingNewAgent = flag; } diff --git a/plugins/main/public/controllers/agent/components/agents-preview.js b/plugins/main/public/controllers/agent/components/agents-preview.js index b9214c07eb..17ad2ed22f 100644 --- a/plugins/main/public/controllers/agent/components/agents-preview.js +++ b/plugins/main/public/controllers/agent/components/agents-preview.js @@ -23,6 +23,7 @@ import { EuiToolTip, EuiCard, EuiLink, + EuiProgress, } from '@elastic/eui'; import { AgentsTable } from './agents-table'; import { WzRequest } from '../../../react-services/wz-request'; @@ -71,12 +72,18 @@ export const AgentsPreview = compose( super(props); this.state = { loadingAgents: false, - loadingSummary: false, + loadingSummary: true, showAgentsEvolutionVisualization: true, agentTableFilters: [], - agentStatusSummary: props.tableProps.agentStatusSummary, + agentStatusSummary: { + active: '-', + disconnected: '-', + total: '-', + pending: '-', + never_connected: '-', + }, agentConfiguration: {}, - agentsActiveCoverage: props.tableProps.agentsActiveCoverage, + agentsActiveCoverage: 0, }; this.wazuhConfig = new WazuhConfig(); this.agentStatus = UI_ORDER_AGENT_STATUS.map(agentStatus => ({ @@ -88,7 +95,8 @@ export const AgentsPreview = compose( async componentDidMount() { this._isMount = true; - this.fetchAgentStatusDetailsData(); + this.fetchSummaryStatus(); + this.fetchAgentsStats(); if (this.wazuhConfig.getConfig()['wazuh.monitoring.enabled']) { this._isMount && this.setState({ @@ -121,38 +129,82 @@ export const AgentsPreview = compose( }, {}); }; - async fetchAgents() { - this.setState({ loadingAgents: true }); - const { - data: { + async fetchSummaryStatus() { + try { + this.setState({ loadingSummary: true }); + const { data: { - affected_items: [lastRegisteredAgent], + data: { + connection: agentStatusSummary, + configuration: agentConfiguration, + }, }, - }, - } = await WzRequest.apiReq('GET', '/agents', { - params: { limit: 1, sort: '-dateAdd', q: 'id!=000' }, - }); - const agentMostActive = await this.props.tableProps.getMostActive(); - this.setState({ - loadingAgents: false, - lastRegisteredAgent, - agentMostActive, - }); + } = await WzRequest.apiReq('GET', '/agents/summary/status', {}); + + this.props.tableProps.updateSummary(agentStatusSummary); + + const agentsActiveCoverage = ( + (agentStatusSummary.active / agentStatusSummary.total) * + 100 + ).toFixed(2); + + this.setState({ + loadingSummary: false, + agentStatusSummary, + agentConfiguration, + /* Calculate the agents active coverage. + Ensure the calculated value is not a NaN, otherwise set a 0. + */ + agentsActiveCoverage: isNaN(agentsActiveCoverage) + ? 0 + : agentsActiveCoverage, + }); + } catch (error) { + this.setState({ loadingSummary: false }); + const options = { + context: `${AgentsPreview.name}.fetchSummaryStatus`, + level: UI_LOGGER_LEVELS.ERROR, + severity: UI_ERROR_SEVERITIES.BUSINESS, + store: true, + error: { + error: error, + message: error.message || error, + title: `Could not get the agents summary`, + }, + }; + getErrorOrchestrator().handleError(options); + } } - async fetchAgentStatusDetailsData() { + + async fetchAgentsStats() { try { - this.fetchAgents(); + this.setState({ loadingAgents: true }); + const { + data: { + data: { + affected_items: [lastRegisteredAgent], + }, + }, + } = await WzRequest.apiReq('GET', '/agents', { + params: { limit: 1, sort: '-dateAdd', q: 'id!=000' }, + }); + const agentMostActive = await this.props.tableProps.getMostActive(); + this.setState({ + loadingAgents: false, + lastRegisteredAgent, + agentMostActive, + }); } catch (error) { - this.setState({ loadingAgents: false, loadingSummary: false }); + this.setState({ loadingAgents: false }); const options = { - context: `${AgentsPreview.name}.fetchAgentStatusDetailsData`, + context: `${AgentsPreview.name}.fetchAgentsStats`, level: UI_LOGGER_LEVELS.ERROR, severity: UI_ERROR_SEVERITIES.BUSINESS, store: true, error: { error: error, message: error.message || error, - title: `Could not get the agents summary`, + title: `Could not get the agents stats`, }, }; getErrorOrchestrator().handleError(options); @@ -182,6 +234,20 @@ export const AgentsPreview = compose( render() { const evolutionIsReady = this.props.resultState !== 'loading'; + if (this.state.loadingSummary) { + return ( +
+ +
+ ); + } + + //This condition is because the angular template and the controller have a small delay to show the register agent component when there are no agents + //This condition must be removed when the controller is removed + if (this.state.agentStatusSummary.total === 0) { + return <>; + } + return ( @@ -198,7 +264,6 @@ export const AgentsPreview = compose( ( formatUIDate(date)} - reload={() => this.fetchAgentStatusDetailsData()} /> diff --git a/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx b/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx index c976cf35f6..8ae23213cd 100644 --- a/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx +++ b/plugins/main/public/controllers/register-agent/containers/register-agent/register-agent.tsx @@ -23,17 +23,13 @@ import { getGroups } from '../../services/register-agent-services'; import { useForm } from '../../../../components/common/form/hooks'; import { FormConfiguration } from '../../../../components/common/form/types'; import { useSelector } from 'react-redux'; -import { - withGlobalBreadcrumb, - withReduxProvider, -} from '../../../../components/common/hocs'; +import { withReduxProvider } from '../../../../components/common/hocs'; import GroupInput from '../../components/group-input/group-input'; import { OsCard } from '../../components/os-selector/os-card/os-card'; import { validateServerAddress, validateAgentName, } from '../../utils/validations'; -import { compose } from 'redux'; interface IRegisterAgentProps { getWazuhVersion: () => Promise; @@ -42,10 +38,7 @@ interface IRegisterAgentProps { reload: () => void; } -export const RegisterAgent = compose( - withReduxProvider, - withGlobalBreadcrumb([{ text: '' }, { text: 'Agents' }]), -)( +export const RegisterAgent = withReduxProvider( ({ getWazuhVersion, hasAgents, diff --git a/plugins/main/public/templates/agents-prev/agents-prev.html b/plugins/main/public/templates/agents-prev/agents-prev.html index 41e885e8fe..a62bbe07ef 100644 --- a/plugins/main/public/templates/agents-prev/agents-prev.html +++ b/plugins/main/public/templates/agents-prev/agents-prev.html @@ -59,13 +59,13 @@ layout="column" layout-align="start space-around" > -
+
-
+
-
- -
- - -
+
+ +
+
+
+ +
+ + +
-
- - - -
+
+ + + +
- - -
+ +
-
- - - - - - -
-
{{reportStatus}}
-
+
+
+ + + + + + +
+
{{reportStatus}}
+
+
-
- -
- -
- -
+
-
- - -
-
+ +
+
+ + + + + + + + + No agents were added to this manager: + + Deploy new agent +
+
+ +
+
+ +
+
+ + +
+
+ +
+ name="OverviewWelcome" + props="octrl.welcomeCardsProps" + >
- +
-
From f4afa6e17fc22b9ace2151373f383052e7d920c6 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Tue, 5 Dec 2023 11:27:15 -0300 Subject: [PATCH 5/7] Refresh stats on refresh button --- .../main/public/controllers/agent/components/agents-preview.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/main/public/controllers/agent/components/agents-preview.js b/plugins/main/public/controllers/agent/components/agents-preview.js index 17ad2ed22f..d2a8c81943 100644 --- a/plugins/main/public/controllers/agent/components/agents-preview.js +++ b/plugins/main/public/controllers/agent/components/agents-preview.js @@ -422,6 +422,7 @@ export const AgentsPreview = compose( addingNewAgent={this.props.tableProps.addingNewAgent} downloadCsv={this.props.tableProps.downloadCsv} formatUIDate={date => formatUIDate(date)} + reload={() => this.fetchAgentsStats()} /> From 00e45aa0cfe7feb78441e69f218ce9db31c5bb24 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Tue, 5 Dec 2023 11:56:04 -0300 Subject: [PATCH 6/7] Fix agent preview component to allow refresh all data --- .../agent/components/agents-preview.js | 124 ++++++++---------- 1 file changed, 56 insertions(+), 68 deletions(-) diff --git a/plugins/main/public/controllers/agent/components/agents-preview.js b/plugins/main/public/controllers/agent/components/agents-preview.js index d2a8c81943..002278051a 100644 --- a/plugins/main/public/controllers/agent/components/agents-preview.js +++ b/plugins/main/public/controllers/agent/components/agents-preview.js @@ -72,7 +72,7 @@ export const AgentsPreview = compose( super(props); this.state = { loadingAgents: false, - loadingSummary: true, + loadingSummary: false, showAgentsEvolutionVisualization: true, agentTableFilters: [], agentStatusSummary: { @@ -95,8 +95,7 @@ export const AgentsPreview = compose( async componentDidMount() { this._isMount = true; - this.fetchSummaryStatus(); - this.fetchAgentsStats(); + this.fetchAgentStatusDetailsData(); if (this.wazuhConfig.getConfig()['wazuh.monitoring.enabled']) { this._isMount && this.setState({ @@ -128,83 +127,70 @@ export const AgentsPreview = compose( return prev; }, {}); }; - async fetchSummaryStatus() { - try { - this.setState({ loadingSummary: true }); - const { + this.setState({ loadingSummary: true }); + const { + data: { data: { - data: { - connection: agentStatusSummary, - configuration: agentConfiguration, - }, + connection: agentStatusSummary, + configuration: agentConfiguration, }, - } = await WzRequest.apiReq('GET', '/agents/summary/status', {}); + }, + } = await WzRequest.apiReq('GET', '/agents/summary/status', {}); - this.props.tableProps.updateSummary(agentStatusSummary); + this.props.tableProps.updateSummary(agentStatusSummary); - const agentsActiveCoverage = ( - (agentStatusSummary.active / agentStatusSummary.total) * - 100 - ).toFixed(2); + const agentsActiveCoverage = ( + (agentStatusSummary.active / agentStatusSummary.total) * + 100 + ).toFixed(2); - this.setState({ - loadingSummary: false, - agentStatusSummary, - agentConfiguration, - /* Calculate the agents active coverage. + this.setState({ + loadingSummary: false, + agentStatusSummary, + agentConfiguration, + /* Calculate the agents active coverage. Ensure the calculated value is not a NaN, otherwise set a 0. */ - agentsActiveCoverage: isNaN(agentsActiveCoverage) - ? 0 - : agentsActiveCoverage, - }); - } catch (error) { - this.setState({ loadingSummary: false }); - const options = { - context: `${AgentsPreview.name}.fetchSummaryStatus`, - level: UI_LOGGER_LEVELS.ERROR, - severity: UI_ERROR_SEVERITIES.BUSINESS, - store: true, - error: { - error: error, - message: error.message || error, - title: `Could not get the agents summary`, - }, - }; - getErrorOrchestrator().handleError(options); - } + agentsActiveCoverage: isNaN(agentsActiveCoverage) + ? 0 + : agentsActiveCoverage, + }); } - async fetchAgentsStats() { - try { - this.setState({ loadingAgents: true }); - const { + async fetchAgents() { + this.setState({ loadingAgents: true }); + const { + data: { data: { - data: { - affected_items: [lastRegisteredAgent], - }, + affected_items: [lastRegisteredAgent], }, - } = await WzRequest.apiReq('GET', '/agents', { - params: { limit: 1, sort: '-dateAdd', q: 'id!=000' }, - }); - const agentMostActive = await this.props.tableProps.getMostActive(); - this.setState({ - loadingAgents: false, - lastRegisteredAgent, - agentMostActive, - }); + }, + } = await WzRequest.apiReq('GET', '/agents', { + params: { limit: 1, sort: '-dateAdd', q: 'id!=000' }, + }); + const agentMostActive = await this.props.tableProps.getMostActive(); + this.setState({ + loadingAgents: false, + lastRegisteredAgent, + agentMostActive, + }); + } + async fetchAgentStatusDetailsData() { + try { + this.fetchSummaryStatus(); + this.fetchAgents(); } catch (error) { - this.setState({ loadingAgents: false }); + this.setState({ loadingAgents: false, loadingSummary: false }); const options = { - context: `${AgentsPreview.name}.fetchAgentsStats`, + context: `${AgentsPreview.name}.fetchAgentStatusDetailsData`, level: UI_LOGGER_LEVELS.ERROR, severity: UI_ERROR_SEVERITIES.BUSINESS, store: true, error: { error: error, message: error.message || error, - title: `Could not get the agents stats`, + title: `Could not get the agents summary`, }, }; getErrorOrchestrator().handleError(options); @@ -234,7 +220,12 @@ export const AgentsPreview = compose( render() { const evolutionIsReady = this.props.resultState !== 'loading'; - if (this.state.loadingSummary) { + //This condition is because the angular template and the controller have a small delay to show the register agent component when there are no agents + //This condition must be removed when the controller is removed + if ( + !this.state.agentStatusSummary.total || + this.state.agentStatusSummary.total === '-' + ) { return (
@@ -242,12 +233,6 @@ export const AgentsPreview = compose( ); } - //This condition is because the angular template and the controller have a small delay to show the register agent component when there are no agents - //This condition must be removed when the controller is removed - if (this.state.agentStatusSummary.total === 0) { - return <>; - } - return ( @@ -264,6 +249,7 @@ export const AgentsPreview = compose( ( formatUIDate(date)} - reload={() => this.fetchAgentsStats()} + reload={() => this.fetchAgentStatusDetailsData()} /> From b0d6586e3ef15c5d3125057e55f5a003cf657937 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Thu, 7 Dec 2023 10:30:45 -0300 Subject: [PATCH 7/7] Fix CHANGELOG and className prop --- CHANGELOG.md | 5 ++++- .../public/controllers/agent/components/agents-preview.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bbf24b498..e28398fb5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,10 @@ All notable changes to the Wazuh app project will be documented in this file. ### Added - Support for Wazuh 4.7.2 -- Improved Agents preview page load when there are no registered agents [#6185](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6185) + +### Fixed + +- Fixed Agents preview page load when there are no registered agents [#6185](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6185) ## Wazuh v4.7.1 - OpenSearch Dashboards 2.8.0 - Revision 01 diff --git a/plugins/main/public/controllers/agent/components/agents-preview.js b/plugins/main/public/controllers/agent/components/agents-preview.js index 002278051a..d9a7dbd0ba 100644 --- a/plugins/main/public/controllers/agent/components/agents-preview.js +++ b/plugins/main/public/controllers/agent/components/agents-preview.js @@ -227,7 +227,7 @@ export const AgentsPreview = compose( this.state.agentStatusSummary.total === '-' ) { return ( -
+
);