Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wazuh api usage magement/status #5528

Merged
merged 5 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Removed deprecated request and code in agent's view [#5451](https://github.com/wazuh/wazuh-kibana-app/pull/5451)
- Removed unnecessary dashboard queries caused by the deploy agent view. [#5453](https://github.com/wazuh/wazuh-kibana-app/pull/5453)
- Removed repeated and unnecessary requests in security section. [#5500](https://github.com/wazuh/wazuh-kibana-app/pull/5500)
- Removed unnecessary requests in `Management/Status` section. [#5528](https://github.com/wazuh/wazuh-kibana-app/pull/5528)

## Wazuh v4.4.3 - OpenSearch Dashboards 2.6.0 - Revision 01

Expand Down
84 changes: 84 additions & 0 deletions docker/imposter/overview/agents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"data": {
"nodes": [
{
"node_name": "worker1",
"count": 1
},
{
"node_name": "worker2",
"count": 1
},
{
"node_name": "master-node",
"count": 1
}
],
"groups": [
{
"name": "default",
"count": 6,
"mergedSum": "9a016508cea1e997ab8569f5cfab30f5",
"configSum": "ab73af41699f13fdd81903b5f23d8d00"
}
],
"agent_os": [
{
"os": {
"name": "Ubuntu",
"platform": "ubuntu",
"version": "20.04.02 LTS"
},
"count": 6
}
],
"agent_status": {
"connection": {
"active": 1,
"disconnected": 2,
"never_connected": 0,
"pending": 0,
"total": 3
},
"configuration": {
"synced": 3,
"total": 3,
"not_synced": 0
}
},
"agent_version": [
{
"version": "Wazuh v4.3.0",
"count": 6
}
],
"last_registered_agent": [
{
"os": {
"arch": "x86_64",
"codename": "Focal Fossa",
"major": 20,
"minor": 4,
"name": "Ubuntu",
"platform": "ubuntu",
"uname": "Linux |77000bae7bd0 |5.8.0-45-generic |#51~20.04.1-Ubuntu SMP Tue Feb 23 13:46:31 UTC 2021 |x86_64",
"version": "20.04.02 LTS"
},
"node_name": "worker1",
"lastKeepAlive": "2021-05-31T10:56:52Z",
"configSum": "ab73af41699f13fdd81903b5f23d8d00",
"status": "active",
"ip": "172.18.0.7",
"group": ["default"],
"name": "77000bae7bd0",
"registerIP": "any",
"dateAdd": "2021-05-31T09:49:28Z",
"manager": "wazuh-worker1",
"id": "004",
"mergedSum": "9a016508cea1e997ab8569f5cfab30f5",
"version": "Wazuh v4.3.0"
}
]
},
"error": 0
}
3 changes: 3 additions & 0 deletions docker/imposter/wazuh-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ resources:
# Get agents overview
- method: GET
path: /overview/agents
response:
statusCode: 200
staticFile: overview/agents.json

# ===================================================== #
# ROOTCHECK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import React, { Component, Fragment } from 'react';
// Eui components
import {
EuiFlexItem,
EuiButtonEmpty,
EuiSelect,
EuiOverlayMask,
EuiConfirmModal
Expand Down Expand Up @@ -68,7 +67,7 @@ class WzStatusActionButtons extends Component {
async restartCluster() {
this.setState({ isRestarting: true });
try {
const result = await this.statusHandler.restartCluster();
await this.statusHandler.restartCluster();
this.setState({ isRestarting: false });
this.showToast(
'success',
Expand Down Expand Up @@ -132,15 +131,19 @@ class WzStatusActionButtons extends Component {
this.props.updateLoadingStatus(true);
this.props.updateSelectedNode(node);

const [{connection: agentsCount}, agentsCountByManagerNodes] = (await Promise.all([
this.statusHandler.agentsSummary(),
this.statusHandler.clusterAgentsCount()
])).map(response => response?.data?.data);
const agentsCountByManagerNodes = await this.statusHandler.clusterAgentsCount();

const { connection: agentsCount } = agentsCountByManagerNodes?.data?.data?.agent_status;

const agentsActiveCoverage = (
(agentsCount.active / agentsCount.total) *
100
).toFixed(2);

this.props.updateStats({
agentsCountByManagerNodes: agentsCountByManagerNodes.nodes,
agentsCountByManagerNodes: agentsCountByManagerNodes?.data?.data?.nodes,
agentsCount,
agentsCoverage: agentsCount.total ? ((agentsCount.active / agentsCount.total) * 100).toFixed(2) : 0,
agentsCoverage: isNaN(agentsActiveCoverage) ? 0 : agentsActiveCoverage,
});

const daemons = await this.statusHandler.clusterNodeStatus(node);
Expand All @@ -150,8 +153,8 @@ class WzStatusActionButtons extends Component {
const nodeInfo = await this.statusHandler.clusterNodeInfo(node);
this.props.updateNodeInfo(nodeInfo.data.data.affected_items[0]);

const lastAgentRaw = await this.statusHandler.lastAgentRaw();
const [lastAgent] = lastAgentRaw.data.data.affected_items;
const [lastAgent] =
agentsCountByManagerNodes?.data?.data?.last_registered_agent;

this.props.updateAgentInfo(lastAgent);

Expand Down Expand Up @@ -214,7 +217,6 @@ class WzStatusActionButtons extends Component {
listNodes,
selectedNode,
clusterEnabled,
isRestarting
} = this.props.state;

let options = this.transforToOptions(listNodes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
EuiPage,
EuiSpacer,
EuiFlexGrid,
EuiButton,
} from '@elastic/eui';

import { connect } from 'react-redux';
Expand Down Expand Up @@ -94,18 +93,29 @@ export class WzStatusOverview extends Component {
this.props.updateLoadingStatus(true);


const [{connection: agentsCount, configuration}, clusterStatus, managerInfo, agentsCountByManagerNodes] = (await Promise.all([
this.statusHandler.agentsSummary(),
const [
clusterStatus,
agentsCountByManagerNodes
] = (await Promise.all([
this.statusHandler.clusterStatus(),
this.statusHandler.managerInfo(),
this.statusHandler.clusterAgentsCount()
])).map(response => response?.data?.data);
const { connection: agentsCount, configuration } = agentsCountByManagerNodes?.agent_status;

const agentsActiveCoverage = (
(agentsCount.active / agentsCount.total) *
100
).toFixed(2);
const agentsSyncedCoverage = (
(configuration.synced / configuration.total) *
100
).toFixed(2);

this.props.updateStats({
agentsCountByManagerNodes: agentsCountByManagerNodes.nodes,
agentsCount,
agentsSynced: configuration.total ? ((configuration.synced / configuration.total) * 100).toFixed(2) : 0,
agentsCoverage: agentsCount.total ? ((agentsCount.active / agentsCount.total) * 100).toFixed(2) : 0,
agentsSynced: isNaN(agentsSyncedCoverage) ? 0 : agentsSyncedCoverage,
agentsCoverage: isNaN(agentsActiveCoverage) ? 0 : agentsActiveCoverage,
});

this.props.updateClusterEnabled(clusterStatus && clusterStatus.enabled === 'yes');
Expand All @@ -131,15 +141,16 @@ export class WzStatusOverview extends Component {
3000
);
} else {
const managerInfo = await this.statusHandler.managerInfo();
const daemons = await this.statusHandler.managerStatus();
const listDaemons = this.objToArr(daemons.data.data.affected_items[0]);
const listDaemons = this.objToArr(daemons?.data?.data?.affected_items?.[0]);
const managerInfoData = managerInfo?.data?.data?.affected_items?.[0];
this.props.updateListDaemons(listDaemons);
this.props.updateSelectedNode(false);
this.props.updateNodeInfo((managerInfo.affected_items || [])[0] || {});
yenienserrano marked this conversation as resolved.
Show resolved Hide resolved
this.props.updateNodeInfo(managerInfoData);
}
}
const lastAgentRaw = await this.statusHandler.lastAgentRaw();
const [lastAgent] = lastAgentRaw.data.data.affected_items;
const [lastAgent] = agentsCountByManagerNodes?.last_registered_agent;

this.props.updateAgentInfo(lastAgent);
} catch (error) {
Expand Down