forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional time formats to decode_cef (elastic#19346)
The date formats in the CEF guide describe the time formats in terms of Java's SimpleTimeFormat class. The `zzz` specifier covers a few additional formats than what are covered by `MST` in Go's time format. Namely on the Go side it was missing support for offsets (e.g. +04, +0400, +04:00). This change additional adds support for the ISO8601 `Z` time zone value (this does not strictly match the CEF guide's format). These are the Java SimpleDateFormats in the CEF guide: MMM dd HH:mm:ss.SSS zzz MMM dd HH:mm:sss.SSS MMM dd HH:mm:ss zzz MMM dd HH:mm:ss MMM dd yyyy HH:mm:ss.SSS zzz MMM dd yyyy HH:mm:ss.SSS MMM dd yyyy HH:mm:ss zzz MMM dd yyyy HH:mm:ss
- Loading branch information
1 parent
bd1731a
commit 733f666
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package cef | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestToTimestamp(t *testing.T) { | ||
var times = []string{ | ||
// Unix epoch in milliseconds. | ||
"1322004689000", | ||
|
||
// MMM dd HH:mm:ss.SSS zzz | ||
"Jun 23 17:37:24.000 Z", | ||
"Jun 23 17:37:24.000 EST", | ||
"Jun 23 17:37:24.000 +05", | ||
"Jun 23 17:37:24.000 +0500", | ||
"Jun 23 17:37:24.000 +05:00", | ||
|
||
// MMM dd HH:mm:sss.SSS | ||
"Jun 23 17:37:24.000", | ||
|
||
// MMM dd HH:mm:ss zzz | ||
"Jun 23 17:37:24 Z", | ||
"Jun 23 17:37:24 EST", | ||
"Jun 23 17:37:24 +05", | ||
"Jun 23 17:37:24 +0500", | ||
"Jun 23 17:37:24 +05:00", | ||
|
||
// MMM dd HH:mm:ss | ||
"Jun 23 17:37:24", | ||
|
||
// MMM dd yyyy HH:mm:ss.SSS zzz | ||
"Jun 23 2020 17:37:24.000 Z", | ||
"Jun 23 2020 17:37:24.000 EST", | ||
"Jun 23 2020 17:37:24.000 +05", | ||
"Jun 23 2020 17:37:24.000 +0500", | ||
"Jun 23 2020 17:37:24.000 +05:00", | ||
|
||
// MMM dd yyyy HH:mm:ss.SSS | ||
"Jun 23 2020 17:37:24.000", | ||
|
||
// MMM dd yyyy HH:mm:ss zzz | ||
"Jun 23 2020 17:37:24 Z", | ||
"Jun 23 2020 17:37:24 EST", | ||
"Jun 23 2020 17:37:24 +05", | ||
"Jun 23 2020 17:37:24 +0500", | ||
"Jun 23 2020 17:37:24 +05:00", | ||
|
||
// MMM dd yyyy HH:mm:ss | ||
"Jun 23 2020 17:37:24", | ||
} | ||
|
||
for _, timeValue := range times { | ||
_, err := toTimestamp(timeValue) | ||
assert.NoError(t, err, timeValue) | ||
} | ||
} |