Skip to content

Commit

Permalink
fix(compatibility): Hide button to remove filter of implicit filters …
Browse files Browse the repository at this point in the history
…in Kibana 7.16

  - Replaced query from `match` to `match_phrase`
  • Loading branch information
Desvelao committed Dec 27, 2021
1 parent 872b092 commit b7f63d0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 49 deletions.
6 changes: 3 additions & 3 deletions public/components/common/modules/modules-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export class ModulesHelper {
for (let i = 0; i < filters.length; i++) {
let found = false;
(implicitFilters || []).forEach(x => {
const objKey = x.query && x.query.match ? Object.keys(x.query.match)[0] : x.meta.key;
const objKey = x.query && x.query.match_phrase ? Object.keys(x.query.match_phrase)[0] : x.meta.key;
const key = `filter-key-${objKey}`;
const value = x.query && x.query.match
? `filter-value-${x.query.match[objKey].query}`
const value = x.query && x.query.match_phrase
? `filter-value-${x.query.match_phrase[objKey].query}`
: `filter-value-${x.meta.value}`;
const data = filters[i].attributes[3];
if (data.value.includes(key) && data.value.includes(value)) {
Expand Down
5 changes: 2 additions & 3 deletions public/components/wz-agent-selector/wz-agent-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ class WzAgentSelector extends Component {
"index": AppState.getCurrentPattern() || WAZUH_ALERTS_PATTERN
},
"query": {
"match": {
"match_phrase": {
'agent.id': {
query: agentIdList[0],
type: 'phrase'
query: agentIdList[0]
}
}
},
Expand Down
13 changes: 0 additions & 13 deletions public/controllers/agent/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,19 +617,6 @@ export class AgentsController {
this.setTabs();
}

/**
* Filter by Mitre.ID
* @param {*} id
*/
addMitrefilter(id) {
const filter = `{"meta":{"index": ${
AppState.getCurrentPattern() || WAZUH_ALERTS_PATTERN
}},"query":{"match":{"rule.mitre.id":{"query":"${id}","type":"phrase"}}}}`;
this.$rootScope.$emit('addNewKibanaFilter', {
filter: JSON.parse(filter),
});
}

/**
* Build the current section tabs
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,9 @@ class OverviewActions extends Component {
index: AppState.getCurrentPattern() || WAZUH_ALERTS_PATTERN,
},
query: {
match: {
match_phrase: {
'agent.id': {
query: agentIdList[0],
type: 'phrase',
query: agentIdList[0]
},
},
},
Expand Down
9 changes: 0 additions & 9 deletions public/controllers/overview/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,6 @@ export class OverviewController {
}
}

/**
* Filter by Mitre.ID
* @param {*} id
*/
addMitrefilter(id) {
const filter = `{"meta":{ "index": ${AppState.getCurrentPattern() || WAZUH_ALERTS_PATTERN}},"query":{"match":{"rule.mitre.id":{"query":"${id}","type":"phrase"}}}}`;
this.$rootScope.$emit('addNewKibanaFilter', { filter: JSON.parse(filter) });
}

/**
* On controller loads
*/
Expand Down
30 changes: 12 additions & 18 deletions public/utils/filter-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class FilterHandler {
}
},
query: {
match: null
match_phrase: null
},
$state: {
store: 'appState'
Expand All @@ -44,10 +44,9 @@ export class FilterHandler {
result.meta.key = 'agent.id';
result.meta.value = agent;
result.meta.params.query = agent;
result.query.match = {
result.query.match_phrase = {
'agent.id': {
query: agent,
type: 'phrase'
query: agent
}
};
return result;
Expand All @@ -58,10 +57,9 @@ export class FilterHandler {
result.meta.key = 'cluster.node';
result.meta.value = node;
result.meta.params.query = node;
result.query.match = {
result.query.match_phrase = {
'cluster.node': {
query: node,
type: 'phrase'
query: node
}
};
return result;
Expand All @@ -72,10 +70,9 @@ export class FilterHandler {
result.meta.key = 'rule.groups';
result.meta.value = group;
result.meta.params.query = group;
result.query.match = {
result.query.match_phrase = {
'rule.groups': {
query: group,
type: 'phrase'
query: group
}
};
return result;
Expand All @@ -87,10 +84,9 @@ export class FilterHandler {
result.meta.key = 'rule.id';
result.meta.value = ruleId;
result.meta.params.query = ruleId;
result.query.match = {
result.query.match_phrase = {
'rule.id': {
query: ruleId,
type: 'phrase'
query: ruleId
}
};
return result;
Expand All @@ -101,17 +97,15 @@ export class FilterHandler {
result.meta.key = isCluster ? 'cluster.name' : 'manager.name';
result.meta.value = manager;
result.meta.params.query = manager;
result.query.match = isCluster
result.query.match_phrase = isCluster
? {
'cluster.name': {
query: manager,
type: 'phrase'
query: manager
}
}
: {
'manager.name': {
query: manager,
type: 'phrase'
query: manager
}
};
return result;
Expand Down

0 comments on commit b7f63d0

Please sign in to comment.