-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timezone config option to decode_cef
CEF message that contain timestamps without a timezone were parsed as UTC. The time zone was not configurable. This adds a `timezone` option to the decode_cef processor and cef module to allow the time zone to be specified when a timestamp does not contain an offset or zone. CEF:0|Aruba Networks|ClearPass|6.8.7.120583|2002|RADIUS Accounting|1|rt=Aug 04 2021 11:31:15 Note that the CEF module receives messages using the syslog input. The syslog input does not have a configurable time zone and always assumes timestamps without time zones are given in the machine's local time zone. This change won't affect how the syslog envelop's time stamp is parsed by the module. This also replaces the deprecated `import "4d63.com/tz"` with Go's relatively new built-in `time/tzdata` package. The `timestamp` processor was updated. Fixes #27232
- Loading branch information
1 parent
d6f899e
commit c47f3c9
Showing
23 changed files
with
259 additions
and
153 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,69 +9,6 @@ Third party libraries used by the Elastic Beats project: | |
================================================================================ | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : 4d63.com/tz | ||
Version: v1.1.1-0.20191124060701-6d37baae851b | ||
Licence type (autodetected): MIT | ||
-------------------------------------------------------------------------------- | ||
|
||
Contents of probable licence file $GOMODCACHE/4d63.com/[email protected]/LICENSE: | ||
|
||
MIT License | ||
|
||
Copyright (c) 2018 Leigh McCulloch | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
-------------------------------------------------------------------------------- | ||
|
||
zoneinfo.go generated from /lib/time/zoneinfo.zip from Go. | ||
|
||
Copyright (c) 2009 The Go Authors. All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following disclaimer | ||
in the documentation and/or other materials provided with the | ||
distribution. | ||
* Neither the name of Google Inc. nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : cloud.google.com/go | ||
Version: v0.51.0 | ||
|
@@ -19369,35 +19306,6 @@ Contents of probable licence file $GOMODCACHE/k8s.io/[email protected]/LICENSE: | |
Indirect dependencies | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : 4d63.com/embedfiles | ||
Version: v0.0.0-20190311033909-995e0740726f | ||
Licence type (autodetected): MIT | ||
-------------------------------------------------------------------------------- | ||
|
||
Contents of probable licence file $GOMODCACHE/4d63.com/[email protected]/LICENSE: | ||
|
||
Copyright (c) 2017, Leigh McCulloch | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
Dependency : bazil.org/fuse | ||
Version: v0.0.0-20160811212531-371fbbdaa898 | ||
|
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
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,94 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package cfgtype | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
|
||
// Embed the timezone database so this code works across platforms. | ||
_ "time/tzdata" | ||
) | ||
|
||
var fixedOffsetFormats = []string{"-07", "-0700", "-07:00"} | ||
|
||
// Timezone maps time instants to the zone in use at that time. Typically, the | ||
// Timezone represents the collection of time offsets in use in a geographical | ||
// area. For many Locations the time offset varies depending on whether daylight | ||
// savings time is in use at the time instant. | ||
type Timezone time.Location | ||
|
||
// NewTimezone returns a new timezone. | ||
func NewTimezone(tz string) (*Timezone, error) { | ||
loc, err := loadLocation(tz) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to parse timezone %q", tz) | ||
} | ||
return (*Timezone)(loc), nil | ||
} | ||
|
||
// MustNewTimezone returns a new timezone. If tz is invalid it panics. | ||
func MustNewTimezone(tz string) *Timezone { | ||
timestamp, err := NewTimezone(tz) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return timestamp | ||
} | ||
|
||
// Location returns a *time.Location. If timezone is nil it returns *time.UTC. | ||
func (tz *Timezone) Location() *time.Location { | ||
if tz == nil { | ||
return time.UTC | ||
} | ||
return (*time.Location)(tz) | ||
} | ||
|
||
// MarshalJSON implements json.Marshaler interface. | ||
func (tz *Timezone) MarshalJSON() ([]byte, error) { | ||
if tz == nil { | ||
return []byte("null"), nil | ||
} | ||
return json.Marshal(tz.Location().String()) | ||
} | ||
|
||
// Unpack converts a time zone name or offset to Timezone. If using a fixed | ||
// offset then the format must be [+-]HHMM (e.g +0800 or -0530). | ||
func (tz *Timezone) Unpack(v string) error { | ||
timezone, err := NewTimezone(v) | ||
if err != nil { | ||
return err | ||
} | ||
*tz = *timezone | ||
return nil | ||
} | ||
|
||
func loadLocation(timezone string) (*time.Location, error) { | ||
for _, format := range fixedOffsetFormats { | ||
t, err := time.Parse(format, timezone) | ||
if err == nil { | ||
name, offset := t.Zone() | ||
return time.FixedZone(name, offset), nil | ||
} | ||
} | ||
|
||
// Handle IANA time zones. | ||
return time.LoadLocation(timezone) | ||
} |
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 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package cfgtype | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestTimezoneUnpack(t *testing.T) { | ||
testCases := []struct { | ||
ZoneName string | ||
}{ | ||
{"America/New_York"}, | ||
{"Local"}, | ||
{"+0500"}, | ||
{"-0500"}, | ||
{"+05:00"}, | ||
{"-05:00"}, | ||
{"+05"}, | ||
{"-05"}, | ||
{"UTC"}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.ZoneName, func(t *testing.T) { | ||
tz := &Timezone{} | ||
err := tz.Unpack(tc.ZoneName) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestTimezoneUnpackFixedZone(t *testing.T) { | ||
tz := &Timezone{} | ||
err := tz.Unpack("+0530") | ||
require.NoError(t, err) | ||
|
||
now := time.Time{} | ||
loc := tz.Location() | ||
offset := now.In(loc) | ||
offsetHour := offset.Hour() | ||
offsetMinute := offset.Minute() | ||
require.Equal(t, 5, offsetHour) | ||
require.Equal(t, 30, offsetMinute) | ||
} |
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
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
Oops, something went wrong.