Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Automatic Import] add timestamp to ECS constants #204931

Merged
merged 6 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,7 @@ export const ECS_TYPES: EcsFields = {
};

export const ECS_FIELDS: EcsFields = {
'@timestamp': 'Date/time when the event originated.',
'as.number': 'Unique number allocated to the autonomous system.',
'as.organization.name': 'Organization name of the autonomous system.',
'client.address': 'Client network address.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Go through each value step by step and modify it with the following process:
9. When you want to use an ECS field as a value for a target, but another field already has the same ECS field as its target, try to find another fitting ECS field. If none is found then the one you are least confident about should have the object replaced with null.
10. If you are not confident for a specific field, you should always set the value to null.
11. These {package_name} log samples are based on source and destination type data, prioritize these compared to other related ECS fields like host.* and observer.*.
12. Whenever possible, map the @timestamp field to the relevant field that contains the event creation date.

You ALWAYS follow these guidelines when writing your response:
<guidelines>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
* 2.0.
*/

import { ecsTestState } from '../../../__jest__/fixtures/ecs_mapping';
import { ECS_RESERVED } from './constants';

import { EcsMappingState } from '../../types';
import {
extractECSMapping,
findDuplicateFields,
findInvalidEcsFields,
handleValidateMappings,
removeReservedFields,
} from './validate';

Expand Down Expand Up @@ -286,3 +289,48 @@ describe('removeReservedFields', () => {
expect(ecsMapping).not.toEqual(result);
});
});

describe('handleValidateMappings', () => {
it('should return empty missing fields if none found', () => {
const state: EcsMappingState = ecsTestState;
state.currentMapping = {
test: {
test: {
event: { target: 'event.action', confidence: 0.95, type: 'string' },
},
},
};
state.combinedSamples = JSON.stringify({
test: {
test: {
event: 'cert.create',
},
},
});
const { missingKeys } = handleValidateMappings({ state });

expect(missingKeys).toEqual([]);
});

it('should return missing fields list if any', () => {
const state: EcsMappingState = ecsTestState;
state.currentMapping = {
test: {
test: {
event: { target: 'event.action', confidence: 0.95, type: 'string' },
},
},
};
state.combinedSamples = JSON.stringify({
test: {
test: {
event: 'cert.create',
version: '1',
},
},
});
const { missingKeys } = handleValidateMappings({ state });

expect(missingKeys).toEqual(['test.test.version']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"@kbn/kibana-utils-plugin",
"@kbn/utils",
"@kbn/zod",
"@kbn/tooling-log"
"@kbn/tooling-log",
]
}
Loading