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

Fix agents active coverage stat as NaN #5490

Merged
merged 10 commits into from
Jun 27, 2023
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to the Wazuh app project will be documented in this file.

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

### Fixed

- Fixed the agents active coverage stat as NaN in Details panel of Agents section [#5490](https://github.com/wazuh/wazuh-kibana-app/pull/5490)

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

### Added
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