Fix number of agents is not properly updated

This commit is contained in:
Adri Valle 2019-08-02 12:15:48 +02:00
parent de0e46a714
commit 2da573eace
2 changed files with 20 additions and 15 deletions

View File

@ -58,6 +58,7 @@ export class AgentsPreviewController {
*/
$onInit() {
this.init = true;
this.api = JSON.parse(this.appState.getCurrentAPI()).id;
const loc = this.$location.search();
if ((loc || {}).agent && (loc || {}).agent !== '000') {
this.commonData.setTimefilter(timefilter.getTime());
@ -126,10 +127,9 @@ export class AgentsPreviewController {
'Your download should begin automatically...',
'CSV'
);
const currentApi = JSON.parse(this.appState.getCurrentAPI()).id;
const output = await this.csvReq.fetch(
'/agents',
currentApi,
this.api,
this.wzTableFilter.get()
);
const blob = new Blob([output], { type: 'text/csv' }); // eslint-disable-line
@ -153,7 +153,6 @@ export class AgentsPreviewController {
const configuration = this.wazuhConfig.getConfig();
this.$scope.adminMode = !!(configuration || {}).admin;
const api = JSON.parse(this.appState.getCurrentAPI()).id;
const clusterInfo = this.appState.getClusterInfo();
const firstUrlParam =
clusterInfo.status === 'enabled' ? 'cluster' : 'manager';
@ -162,7 +161,7 @@ export class AgentsPreviewController {
const pattern = this.appState.getCurrentPattern();
const data = await Promise.all([
this.genericReq.request('GET', '/api/agents-unique/' + api, {}),
this.genericReq.request('GET', '/api/agents-unique/' + this.api, {}),
this.genericReq.request(
'GET',
`/elastic/top/${firstUrlParam}/${secondUrlParam}/agent.name/${pattern}`
@ -199,11 +198,7 @@ export class AgentsPreviewController {
this.versions = unique.versions.map(item => ({ id: item }));
this.osPlatforms = unique.osPlatforms;
this.lastAgent = unique.lastAgent;
this.agentsCountActive = unique.summary.agentsCountActive;
this.agentsCountDisconnected = unique.summary.agentsCountDisconnected;
this.agentsCountNeverConnected = unique.summary.agentsCountNeverConnected;
this.agentsCountTotal = unique.summary.agentsCountTotal;
this.agentsCoverity = unique.summary.agentsCoverity;
this.summary = unique.summary;
if (agentsTop.data.data === '') {
this.mostActiveAgent.name = this.appState.getClusterInfo().manager;
@ -232,10 +227,20 @@ export class AgentsPreviewController {
this.$scope.registerNewAgent = flag;
}
reloadList() {
async reloadList() {
this.refreshAgentsStats();
this.$scope.$broadcast('wazuhSearch', { term: '' });
}
async refreshAgentsStats() {
try {
const data = await this.genericReq.request('GET', '/api/agents-unique/' + this.api, {});
this.summary = ((data.data || {}).result || {}).summary || {};
} catch (error) {
this.errorHandler.handle('Error refreshing agents stats');
}
}
openRegistrationDocs() {
this.$window.open(
'https://documentation.wazuh.com/current/user-manual/registering/index.html',

View File

@ -30,7 +30,7 @@
</span>
<md-divider class="wz-margin-top-10"></md-divider>
<canvas id="bar" ng-if="ctrl.lastAgent && ctrl.lastAgent.id" class="wz-margin-top-16 chart chart-doughnut"
chart-data="[ctrl.agentsCountActive,ctrl.agentsCountDisconnected,ctrl.agentsCountNeverConnected]"
chart-data="[ctrl.summary.agentsCountActive,ctrl.summary.agentsCountDisconnected,ctrl.summary.agentsCountNeverConnected]"
chart-labels="['Active','Disconnected', 'Never connected']" chart-colors="['#57C17B', '#BC52BC', '#9E3533']"
chart-options="{cutoutPercentage: 75, legend: {display: true,position: 'right',},responsive: false, maintainAspectRatio: false}" />
<div layout="row" class="wz-margin-top-16 layout-align-center-center" ng-if="!ctrl.lastAgent || !ctrl.lastAgent.id">
@ -54,7 +54,7 @@
<div class="euiText euiText--small euiStat__description">
<p>Active</p>
</div>
<p class="euiTitle euiTitle--small euiStat__title">{{ctrl.agentsCountActive}}</p>
<p class="euiTitle euiTitle--small euiStat__title">{{ctrl.summary.agentsCountActive}}</p>
</div>
</div>
<div class="euiFlexItem euiFlexItem--flexGrowZero">
@ -63,7 +63,7 @@
<div class="euiText euiText--small euiStat__description">
<p>Disconnected</p>
</div>
<p class="euiTitle euiTitle--small euiStat__title">{{ctrl.agentsCountDisconnected}}</p>
<p class="euiTitle euiTitle--small euiStat__title">{{ctrl.summary.agentsCountDisconnected}}</p>
</div>
</div>
<div class="euiFlexItem euiFlexItem--flexGrowZero">
@ -72,7 +72,7 @@
<div class="euiText euiText--small euiStat__description">
<p>Never connected</p>
</div>
<p class="euiTitle euiTitle--small euiStat__title">{{ctrl.agentsCountNeverConnected}}</p>
<p class="euiTitle euiTitle--small euiStat__title">{{ctrl.summary.agentsCountNeverConnected}}</p>
</div>
</div>
<div class="euiFlexItem euiFlexItem--flexGrowZero">
@ -81,7 +81,7 @@
<div class="euiText euiText--small euiStat__description">
<p>Agents coverage</p>
</div>
<p class="euiTitle euiTitle--small euiStat__title">{{(ctrl.agentsCoverity | number:2)}}%</p>
<p class="euiTitle euiTitle--small euiStat__title">{{(ctrl.summary.agentsCoverity | number:2)}}%</p>
</div>
</div>
</div>