From 86aae0f741aaab292048779bdbce9694833d1210 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jes=C3=BAs=20=C3=81ngel?=
Date: Mon, 10 Jun 2019 16:57:59 +0200
Subject: [PATCH] Revert "Removed getFieldTop logic"
This reverts commit d187f914da7a0a12b525382e7def5ff37b3b5b5f.
---
public/controllers/agent/agents-preview.js | 37 +++++++++--
public/templates/agents-prev/agents-prev.html | 15 +++++
server/controllers/wazuh-elastic.js | 64 +++++++++++++++++++
server/routes/wazuh-elastic.js | 9 +++
test/server/wazuh-elastic.js | 4 ++
5 files changed, 124 insertions(+), 5 deletions(-)
diff --git a/public/controllers/agent/agents-preview.js b/public/controllers/agent/agents-preview.js
index c9639aa8a..44526012b 100644
--- a/public/controllers/agent/agents-preview.js
+++ b/public/controllers/agent/agents-preview.js
@@ -73,6 +73,10 @@ export class AgentsPreviewController {
this.versions = [];
this.groups = [];
this.nodes = [];
+ this.mostActiveAgent = {
+ name: '',
+ id: ''
+ };
// Load URL params
if (loc && loc.tab) {
@@ -151,13 +155,20 @@ export class AgentsPreviewController {
const api = JSON.parse(this.appState.getCurrentAPI()).id;
const clusterInfo = this.appState.getClusterInfo();
+ const firstUrlParam =
+ clusterInfo.status === 'enabled' ? 'cluster' : 'manager';
+ const secondUrlParam = clusterInfo[firstUrlParam];
- const agentsUnique = await this.genericReq.request(
- 'GET',
- '/api/agents-unique/' + api,
- {}
- );
+ const pattern = this.appState.getCurrentPattern();
+ const data = await Promise.all([
+ this.genericReq.request('GET', '/api/agents-unique/' + api, {}),
+ this.genericReq.request(
+ 'GET',
+ `/elastic/top/${firstUrlParam}/${secondUrlParam}/agent.name/${pattern}`
+ )
+ ]);
+ const [agentsUnique, agentsTop] = data;
const unique = agentsUnique.data.result;
this.searchBarModel = {
@@ -193,6 +204,22 @@ export class AgentsPreviewController {
this.agentsCountNeverConnected = unique.summary.agentsCountNeverConnected;
this.agentsCountTotal = unique.summary.agentsCountTotal;
this.agentsCoverity = unique.summary.agentsCoverity;
+
+ if (agentsTop.data.data === '') {
+ this.mostActiveAgent.name = this.appState.getClusterInfo().manager;
+ this.mostActiveAgent.id = '000';
+ } else {
+ this.mostActiveAgent.name = agentsTop.data.data;
+ const info = await this.genericReq.request(
+ 'GET',
+ `/elastic/top/${firstUrlParam}/${secondUrlParam}/agent.id/${pattern}`
+ );
+ if (info.data.data === '' && this.mostActiveAgent.name !== '') {
+ this.mostActiveAgent.id = '000';
+ } else {
+ this.mostActiveAgent.id = info.data.data;
+ }
+ }
} catch (error) {
this.errorInit = this.errorHandler.handle(error, false, false, true);
}
diff --git a/public/templates/agents-prev/agents-prev.html b/public/templates/agents-prev/agents-prev.html
index 0bfa233cd..7198ea7d6 100644
--- a/public/templates/agents-prev/agents-prev.html
+++ b/public/templates/agents-prev/agents-prev.html
@@ -106,6 +106,21 @@
-
+
+
+
+
+
+ {{ctrl.mostActiveAgent.name}}
+
+ -
+
+
diff --git a/server/controllers/wazuh-elastic.js b/server/controllers/wazuh-elastic.js
index 3469ec3c9..28fafd54b 100644
--- a/server/controllers/wazuh-elastic.js
+++ b/server/controllers/wazuh-elastic.js
@@ -192,6 +192,70 @@ export class WazuhElasticCtrl {
}
}
+ /**
+ * This get the fields keys
+ * @param {Object} req
+ * @param {Object} reply
+ * @returns {Array