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

Make journald emit map[string]interface{} #38

Merged
merged 1 commit into from
Jul 20, 2020
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
16 changes: 13 additions & 3 deletions plugin/builtin/input/journald.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (plugin *JournaldInput) Start() error {
}

func (plugin *JournaldInput) parseJournalEntry(line []byte) (*entry.Entry, string, error) {
var record map[string]string
var record map[string]interface{}
err := plugin.json.Unmarshal(line, &record)
if err != nil {
return nil, "", err
Expand All @@ -173,7 +173,12 @@ func (plugin *JournaldInput) parseJournalEntry(line []byte) (*entry.Entry, strin
return nil, "", errors.New("journald record missing __REALTIME_TIMESTAMP field")
}

timestampInt, err := strconv.ParseInt(timestamp, 10, 64)
timestampString, ok := timestamp.(string)
if !ok {
return nil, "", errors.New("journald field for timestamp is not a string")
}

timestampInt, err := strconv.ParseInt(timestampString, 10, 64)
if err != nil {
return nil, "", fmt.Errorf("parse timestamp: %s", err)
}
Expand All @@ -185,9 +190,14 @@ func (plugin *JournaldInput) parseJournalEntry(line []byte) (*entry.Entry, strin
return nil, "", errors.New("journald record missing __CURSOR field")
}

cursorString, ok := cursor.(string)
if !ok {
return nil, "", errors.New("journald field for cursor is not a string")
}

entry := plugin.NewEntry(record)
entry.Timestamp = time.Unix(0, timestampInt*1000) // in microseconds
return entry, cursor, nil
return entry, cursorString, nil
}

func (plugin *JournaldInput) syncOffsets() {
Expand Down
2 changes: 1 addition & 1 deletion plugin/builtin/input/journald_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestInputJournald(t *testing.T) {
err = journaldInput.Start()
require.NoError(t, err)

expected := map[string]string{
expected := map[string]interface{}{
"_BOOT_ID": "c4fa36de06824d21835c05ff80c54468",
"_CAP_EFFECTIVE": "0",
"_TRANSPORT": "journal",
Expand Down