From 5e355192d33c7bfe119bb685bc64e837339a13f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20=C3=81ngel=20Gonz=C3=A1lez?= Date: Wed, 11 Jul 2018 21:00:20 +0200 Subject: [PATCH] Added new parameter to switch between patterns when searching --- server/lib/elastic-wrapper.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/lib/elastic-wrapper.js b/server/lib/elastic-wrapper.js index f5fc58537..60dddeda7 100644 --- a/server/lib/elastic-wrapper.js +++ b/server/lib/elastic-wrapper.js @@ -366,9 +366,19 @@ export default class ElasticWrapper { try { if(!payload) return Promise.reject(new Error('No valid payload given')); + const pattern = payload.pattern; + delete payload.pattern; + const fullPattern = await this.getIndexPatternUsingGet(pattern); + const title = fullPattern && + fullPattern._source && + fullPattern._source['index-pattern'] && + fullPattern._source['index-pattern'].title ? + fullPattern._source['index-pattern'].title : + false; + const data = await this.elasticRequest.callWithInternalUser('search', { - index: 'wazuh-alerts-3.x-*', + index: title || 'wazuh-alerts-3.x-*', type: 'wazuh', body: payload }); @@ -378,7 +388,7 @@ export default class ElasticWrapper { } catch (error) { return Promise.reject(error); } - }; + } /** * Search for the Wazuh API configuration document using its own id (usually it's a timestamp)