Skip to content

Commit

Permalink
x-pack/filebeat/module/mysqlenterprise: fix handling of streaming dat…
Browse files Browse the repository at this point in the history
…a sent as partial array object (#35160)

MySQL send its audit logs as parts of an infinitely long JSON array and
so separates each line of the logs with a comma. We don't know that we
are in an array since the first line of the log may not have been sent
to us, so remove the trailing comma to treat each element of the partial
array object as an object in a JSON stream.

(cherry picked from commit 9e83729)
  • Loading branch information
efd6 authored and mergify[bot] committed Apr 21, 2023
1 parent 4485c28 commit 091f7b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Correctly collect TCP and UDP metrics for unspecified address values. {pull}35111[35111]
- Fix base for UDP and TCP queue metrics and UDP drops metric. {pull}35123[35123]
- Sanitize filenames for request tracer in httpjson and cel inputs. {pull}35143[35143]
- decode_cef processor: Fix ECS output by making `observer.ip` into an array of strings instead of string. {issue}35140[35140] {pull}35149[35149]
- Fix handling of MySQL audit logs with strict JSON parser. {issue}35158[35158] {pull}35160[35160]

*Heartbeat*

Expand Down
15 changes: 15 additions & 0 deletions x-pack/filebeat/module/mysqlenterprise/audit/ingest/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,24 @@ processors:
- set:
field: event.ingested
value: '{{_ingest.timestamp}}'
- set:
field: event.original
copy_from: message
- script:
description: Trim trailing commas.
# MySQL sends audit logs as parts of a single infinite JSON array
# rather than as a JSON stream, and so has comma separators. We
# don't have the array open token, so remove the commas.
lang: painless
source:
ctx.message = ctx.message.substring(0, ctx.message.length() - 1);
if: ctx.message instanceof String && ctx.message.endsWith(',')
- json:
field: message
target_field: mysqlenterprise.audit
- remove:
field: message
ignore_missing: true
- remove:
field: '@timestamp'
ignore_missing: true
Expand Down

0 comments on commit 091f7b8

Please sign in to comment.