Skip to content

Commit

Permalink
Fix agents active coverage stat as NaN (#5490)
Browse files Browse the repository at this point in the history
* fix: agents active coverate stat as NaN

Ensure the values used to calculate have the expected types and
the total count is greater than 0.

* remove: unused openRegistrationDocs method

* changelog: add entry

* fix: check if agents active coverage is a NaN

* changelog: fix entry

---------

Co-authored-by: Álex Ruiz <alejandro.ruiz.becerra@wazuh.com>
  • Loading branch information
Desvelao and AlexRuiz7 authored Jun 27, 2023
1 parent 74927fb commit 53bf022
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 119 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to the Wazuh app project will be documented in this file.
### Fixed

- Fixed the rendering of tables that contains IPs and agent overview [#5471](https://github.com/wazuh/wazuh-kibana-app/pull/5471)
- Fixed the agents active coverage stat as NaN in Details panel of Agents section [#5490](https://github.com/wazuh/wazuh-kibana-app/pull/5490)

### Removed

Expand All @@ -29,6 +30,7 @@ All notable changes to the Wazuh app project will be documented in this file.

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


### Added

- Support for Wazuh 4.4.4
Expand Down
64 changes: 43 additions & 21 deletions public/controllers/agent/agents-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ export class AgentsPreviewController {
* @param {Object} errorHandler
* @param {Object} csvReq
*/
constructor($scope, $location, $route, errorHandler, csvReq, commonData, $window) {
constructor(
$scope,
$location,
$route,
errorHandler,
csvReq,
commonData,
$window,
) {
this.$scope = $scope;
this.genericReq = GenericRequest;
this.$location = $location;
Expand All @@ -57,11 +65,15 @@ export class AgentsPreviewController {
this.api = JSON.parse(AppState.getCurrentAPI()).id;
const loc = this.$location.search();
if ((loc || {}).agent && (loc || {}).agent !== '000') {
this.commonData.setTimefilter(getDataPlugin().timefilter.timefilter.getTime());
this.commonData.setTimefilter(
getDataPlugin().timefilter.timefilter.getTime(),
);
return this.showAgent({ id: loc.agent });
}

this.isClusterEnabled = AppState.getClusterInfo() && AppState.getClusterInfo().status === 'enabled';
this.isClusterEnabled =
AppState.getClusterInfo() &&
AppState.getClusterInfo().status === 'enabled';
this.loading = true;
this.osPlatforms = [];
this.versions = [];
Expand All @@ -82,22 +94,22 @@ export class AgentsPreviewController {
this.$location.search('tab', this.submenuNavItem);
});

this.$scope.$on('wazuhFetched', (evt) => {
this.$scope.$on('wazuhFetched', evt => {
evt.stopPropagation();
});
this.registerAgentsProps = {
addNewAgent: flag => this.addNewAgent(flag),
hasAgents: () => this.hasAgents,
reload: () => this.$route.reload(),
getWazuhVersion: () => this.getWazuhVersion(),
getCurrentApiAddress: () => this.getCurrentApiAddress()
getCurrentApiAddress: () => this.getCurrentApiAddress(),
};
this.hasAgents = true;
this.init = false;
const instance = new DataFactory(WzRequest.apiReq, '/agents', false, false);
//Props
this.tableAgentsProps = {
updateSummary: (summary) => {
updateSummary: summary => {
this.summary = summary;
if (this.summary.total === 0) {
if (this.addingNewAgent === undefined) {
Expand All @@ -117,18 +129,25 @@ export class AgentsPreviewController {
this.downloadCsv(filters);
this.$scope.$applyAsync();
},
showAgent: (agent) => {
showAgent: agent => {
this.showAgent(agent);
this.$scope.$applyAsync();
},
getMostActive: async () => {
return await this.getMostActive();
},
clickAction: (item, openAction = false) => {
clickAction(item, openAction, instance, this.shareAgent, this.$location, this.$scope);
clickAction(
item,
openAction,
instance,
this.shareAgent,
this.$location,
this.$scope,
);
this.$scope.$applyAsync();
},
formatUIDate: (date) => formatUIDate(date),
formatUIDate: date => formatUIDate(date),
summary: this.summary,
};
//Load
Expand Down Expand Up @@ -187,14 +206,18 @@ export class AgentsPreviewController {
'GET',
`/elastic/top/${this.firstUrlParam}/${this.secondUrlParam}/agent.name/${
this.pattern
}?agentsList=${store.getState().appStateReducers.allowedAgents.toString()}`
}?agentsList=${store
.getState()
.appStateReducers.allowedAgents.toString()}`,
);
this.mostActiveAgent.name = data.data.data;
const info = await this.genericReq.request(
'GET',
`/elastic/top/${this.firstUrlParam}/${this.secondUrlParam}/agent.id/${
this.pattern
}?agentsList=${store.getState().appStateReducers.allowedAgents.toString()}`
}?agentsList=${store
.getState()
.appStateReducers.allowedAgents.toString()}`,
);
if (info.data.data === '' && this.mostActiveAgent.name !== '') {
this.mostActiveAgent.id = '000';
Expand Down Expand Up @@ -227,9 +250,12 @@ export class AgentsPreviewController {
try {
this.errorInit = false;
const clusterInfo = AppState.getClusterInfo();
this.firstUrlParam = clusterInfo.status === 'enabled' ? 'cluster' : 'manager';
this.firstUrlParam =
clusterInfo.status === 'enabled' ? 'cluster' : 'manager';
this.secondUrlParam = clusterInfo[this.firstUrlParam];
this.pattern = (await getDataPlugin().indexPatterns.get(AppState.getCurrentPattern())).title;
this.pattern = (
await getDataPlugin().indexPatterns.get(AppState.getCurrentPattern())
).title;
} catch (error) {
const options = {
context: `${AgentsPreviewController.name}.load`,
Expand All @@ -252,20 +278,14 @@ export class AgentsPreviewController {
this.addingNewAgent = flag;
}

openRegistrationDocs() {
this.$window.open(webDocumentationLink(user-manual/registering/index.html),
'_blank'
);
}

/**
* Returns the current API address
*/
async getCurrentApiAddress() {
try {
const result = await this.genericReq.request('GET', '/hosts/apis');
const entries = result.data || [];
const host = entries.filter((e) => {
const host = entries.filter(e => {
return e.id == this.api;
});
const url = host[0].url;
Expand All @@ -279,7 +299,9 @@ export class AgentsPreviewController {
error: {
error: error,
message: error.message || error,
title: `Could not get the Wazuh API address: ${error.message || error}`,
title: `Could not get the Wazuh API address: ${
error.message || error
}`,
},
};
getErrorOrchestrator().handleError(options);
Expand Down
Loading

0 comments on commit 53bf022

Please sign in to comment.