Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

- Change network.direction values to ECS recommended values (inbound, outbound). {issue}12445[12445] {pull}20695[20695]
- Docker container needs to be explicitly run as user root for auditing. {pull}21202[21202]
- 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]

*Filebeat*

Expand Down
2 changes: 1 addition & 1 deletion auditbeat/module/file_integrity/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func buildMetricbeatEvent(e *Event, existedBefore bool) mb.Event {

if e.Info.Type == FileType {
if extension := filepath.Ext(e.Path); extension != "" {
file["extension"] = extension
file["extension"] = strings.TrimLeft(extension, ".")
}
if mimeType := getMimeType(e.Path); mimeType != "" {
file["mime_type"] = mimeType
Expand Down
11 changes: 9 additions & 2 deletions auditbeat/module/file_integrity/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

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

assertHasKey(t, fields, "file.path")
assertHasKey(t, fields, "file.extension")
if assertHasKey(t, fields, "file.extension") {
ext, err := fields.GetValue("file.extension")
require.NoError(t, err)
assert.Equal(t, ext, "txt")
}
assertHasKey(t, fields, "file.target_path")
assertHasKey(t, fields, "file.inode")
assertHasKey(t, fields, "file.uid")
Expand Down Expand Up @@ -427,10 +432,12 @@ func mustDecodeHex(v string) []byte {
return data
}

func assertHasKey(t testing.TB, m common.MapStr, key string) {
func assertHasKey(t testing.TB, m common.MapStr, key string) bool {
t.Helper()
found, err := m.HasKey(key)
if err != nil || !found {
t.Errorf("key %v not found: %v", key, err)
return false
}
return true
}