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

[Filebeat] Fix RFC5424 date format in system/syslog in pipeline #12529

Merged
merged 5 commits into from
Jun 14, 2019
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 @@ -119,6 +119,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Require client_auth by default when ssl is enabled for tcp input {pull}12333[12333]
- Require certificate authorities, certificate file, and key when SSL is enabled for the TCP input. {pull}12355[12355]
- Load correct pipelines when system module is configured in modules.d. {pull}12340[12340]
- Fix timezone offset parsing in system/syslog. {pull}12529[12529]

*Heartbeat*

Expand Down
5 changes: 4 additions & 1 deletion filebeat/module/system/syslog/ingest/pipeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
"formats": [
"MMM d HH:mm:ss",
"MMM dd HH:mm:ss",
"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZ"
"yyyy-MM-dd'T'HH:mm:ss.SSSZZ",
"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZ",
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX",
"yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX"
],
"ignore_failure": true
}
Expand Down
2 changes: 2 additions & 0 deletions filebeat/module/system/syslog/test/tz-offset.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1986-04-26T01:23:45.101+0400 rmbkmonitor04 shutdown[2649]: shutting down for system halt
1986-04-26T01:23:45.388424+04:00 rmbkmonitor04 thermald: constraint_0_power_limit_uw exceeded.
31 changes: 31 additions & 0 deletions filebeat/module/system/syslog/test/tz-offset.log-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[
{
"@timestamp": "1986-04-25T21:23:45.101Z",
"event.dataset": "system.syslog",
"event.module": "system",
"event.timezone": "+00:00",
"fileset.name": "syslog",
"host.hostname": "rmbkmonitor04",
"input.type": "log",
"log.file.path": "tz-offset.log",
"log.offset": 0,
"message": "shutting down for system halt",
"process.name": "shutdown",
"process.pid": 2649,
"service.type": "system"
},
{
"@timestamp": "1986-04-25T21:23:45.388Z",
"event.dataset": "system.syslog",
"event.module": "system",
"event.timezone": "+00:00",
"fileset.name": "syslog",
"host.hostname": "rmbkmonitor04",
"input.type": "log",
"log.file.path": "tz-offset.log",
"log.offset": 89,
"message": "constraint_0_power_limit_uw exceeded.",
"process.name": "thermald",
"service.type": "system"
}
]
21 changes: 20 additions & 1 deletion filebeat/tests/system/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,32 @@ def clean_keys(obj):
# ECS versions change for any ECS release, large or small
ecs_key = ["ecs.version"]

# Keep source log filename for exceptions
filename = None
if "log.file.path" in obj:
filename = os.path.basename(obj["log.file.path"]).lower()

for key in host_keys + time_keys + other_keys + ecs_key:
delete_key(obj, key)

# Remove timestamp for comparison where timestamp is not part of the log line
if (obj["event.dataset"] in ["icinga.startup", "redis.log", "haproxy.log", "system.auth", "system.syslog"]):
if (obj["event.dataset"] in ["icinga.startup", "redis.log", "haproxy.log", "system.auth"]):
delete_key(obj, "@timestamp")

# HACK: This keeps @timestamp for the tz-offset.log in system.syslog.
#
# This can't be done for all syslog logs because most of them lack the year
# in their timestamp, so Elasticsearch will set it to the current year and
# that will cause the tests to fail every new year.
#
# The log.file.path key needs to be kept so that it is stored in the golden
# data, to prevent @timestamp to be removed from it before comparison.
if obj["event.dataset"] == "system.syslog":
if filename == "tz-offset.log":
obj["log.file.path"] = filename
else:
delete_key(obj, "@timestamp")


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a bit hacky but I think for now we don't have choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely hacky :)

Note to reviewers: This is needed because in most syslog logs, the year is missing from the timestamp, so Elasticsearch will set it to the current year and that will cause the tests to fail every new year.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah should the explanation you gave be in the comment in the code? This is hacky enough after a while we probably won't remember why it's added 😄(If there is no better solution.)

Copy link
Contributor Author

@adriansr adriansr Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the explanation you gave be in the comment in the code?

Right!

def delete_key(obj, key):
if key in obj:
Expand Down