mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Inventory][ECO] Fix asKqlFilter (#200984)
fixes [#200981](https://github.com/elastic/kibana/issues/200981) ## Summary This PR fixes a problem with the asKqlFilter throwing an error when building filters with string containing special characters.
This commit is contained in:
parent
f0262080c8
commit
8f8a671567
2 changed files with 19 additions and 4 deletions
|
@ -39,7 +39,22 @@ describe('EntityClient', () => {
|
|||
};
|
||||
|
||||
const result = entityClient.asKqlFilter(entityLatest);
|
||||
expect(result).toEqual('service.name: my-service');
|
||||
expect(result).toEqual('service.name: "my-service"');
|
||||
});
|
||||
|
||||
it('should return the kql filter when an indentity field value contain special characters', () => {
|
||||
const entityLatest: EntityInstance = {
|
||||
entity: {
|
||||
...commonEntityFields.entity,
|
||||
identity_fields: ['host.name', 'foo.bar'],
|
||||
},
|
||||
host: {
|
||||
name: 'my-host:some-value:some-other-value',
|
||||
},
|
||||
};
|
||||
|
||||
const result = entityClient.asKqlFilter(entityLatest);
|
||||
expect(result).toEqual('host.name: "my-host:some-value:some-other-value"');
|
||||
});
|
||||
|
||||
it('should return the kql filter when indentity_fields is composed by multiple fields', () => {
|
||||
|
@ -56,7 +71,7 @@ describe('EntityClient', () => {
|
|||
};
|
||||
|
||||
const result = entityClient.asKqlFilter(entityLatest);
|
||||
expect(result).toEqual('(service.name: my-service AND service.environment: staging)');
|
||||
expect(result).toEqual('(service.name: "my-service" AND service.environment: "staging")');
|
||||
});
|
||||
|
||||
it('should ignore fields that are not present in the entity', () => {
|
||||
|
@ -71,7 +86,7 @@ describe('EntityClient', () => {
|
|||
};
|
||||
|
||||
const result = entityClient.asKqlFilter(entityLatest);
|
||||
expect(result).toEqual('host.name: my-host');
|
||||
expect(result).toEqual('host.name: "my-host"');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ export class EntityClient {
|
|||
const identityFieldsValue = this.getIdentityFieldsValue(entityInstance);
|
||||
|
||||
const nodes: KueryNode[] = Object.entries(identityFieldsValue).map(([identityField, value]) => {
|
||||
return nodeTypes.function.buildNode('is', identityField, value);
|
||||
return nodeTypes.function.buildNode('is', identityField, `"${value}"`);
|
||||
});
|
||||
|
||||
if (nodes.length === 0) return '';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue