Skip to content

Commit 708f475

Browse files
authored
Remove dot from file.extension value in Auditbeat FIM (#21644) (#21741)
The ECS file.extension field should not include the dot. For example the value should be "png" and not ".png". Relates elastic/ecs#1016 (cherry picked from commit 500e8b5)
1 parent f37edd6 commit 708f475

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
3737

3838
- Change network.direction values to ECS recommended values (inbound, outbound). {issue}12445[12445] {pull}20695[20695]
3939
- Docker container needs to be explicitly run as user root for auditing. {pull}21202[21202]
40+
- File integrity dataset no longer includes the leading dot in `file.extension` values (e.g. it will report "png" instead of ".png") to comply with ECS. {pull}21644[21644]
4041

4142
*Filebeat*
4243

auditbeat/module/file_integrity/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func buildMetricbeatEvent(e *Event, existedBefore bool) mb.Event {
257257

258258
if e.Info.Type == FileType {
259259
if extension := filepath.Ext(e.Path); extension != "" {
260-
file["extension"] = extension
260+
file["extension"] = strings.TrimLeft(extension, ".")
261261
}
262262
if mimeType := getMimeType(e.Path); mimeType != "" {
263263
file["mime_type"] = mimeType

auditbeat/module/file_integrity/event_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"time"
2929

3030
"github.com/stretchr/testify/assert"
31+
"github.com/stretchr/testify/require"
3132

3233
"github.com/elastic/beats/v7/libbeat/common"
3334
)
@@ -295,7 +296,11 @@ func TestBuildEvent(t *testing.T) {
295296
assertHasKey(t, fields, "event.type")
296297

297298
assertHasKey(t, fields, "file.path")
298-
assertHasKey(t, fields, "file.extension")
299+
if assertHasKey(t, fields, "file.extension") {
300+
ext, err := fields.GetValue("file.extension")
301+
require.NoError(t, err)
302+
assert.Equal(t, ext, "txt")
303+
}
299304
assertHasKey(t, fields, "file.target_path")
300305
assertHasKey(t, fields, "file.inode")
301306
assertHasKey(t, fields, "file.uid")
@@ -427,10 +432,12 @@ func mustDecodeHex(v string) []byte {
427432
return data
428433
}
429434

430-
func assertHasKey(t testing.TB, m common.MapStr, key string) {
435+
func assertHasKey(t testing.TB, m common.MapStr, key string) bool {
431436
t.Helper()
432437
found, err := m.HasKey(key)
433438
if err != nil || !found {
434439
t.Errorf("key %v not found: %v", key, err)
440+
return false
435441
}
442+
return true
436443
}

0 commit comments

Comments
 (0)