Skip to content

Commit

Permalink
Improve ECS categorization field mappings in traefik module (#19379) (#…
Browse files Browse the repository at this point in the history
…19392)

- event.kind
- event.category
- event.type
- event.outcome
- related.ip
- related.user

Closes #16183

(cherry picked from commit f814f41)
  • Loading branch information
leehinman authored Jul 8, 2020
1 parent 77dc072 commit 72c5c29
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 132 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ field. You can revert this change by configuring tags for the module and omittin
- Explicitly set ECS version in all Filebeat modules. {pull}19198[19198]
- Add awscloudwatch input. {pull}19025[19025]
- Add support for timezone offsets and `Z` to decode_cef timestamp parser. {pull}19346[19346]
- Improve ECS categorization field mappings in traefik module. {issue}16183[16183] {pull}19379[19379]

*Heartbeat*

Expand Down
131 changes: 0 additions & 131 deletions filebeat/module/traefik/access/ingest/pipeline.json

This file was deleted.

106 changes: 106 additions & 0 deletions filebeat/module/traefik/access/ingest/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
description: Pipeline for parsing Traefik access logs. Requires the geoip and user_agent
plugins.
processors:
- dissect:
field: message
pattern: '%{source.address} %{traefik.access.user_identifier} %{user.name} [%{traefik.access.time}]
"%{http.request.method} %{url.original} HTTP/%{http.version}" %{http.response.status_code}
%{traefik.access.message}'
- grok:
field: traefik.access.message
patterns:
- (?:%{NUMBER:http.response.body.bytes:long}|-)( (?:"%{DATA:http.request.referrer}"|-)?(
(?:"%{DATA:user_agent.original}"|-)?)?( (?:%{NUMBER:traefik.access.request_count:long}|-)?)?(
(?:"%{DATA:traefik.access.frontend_name}"|-)?)?( "%{DATA:traefik.access.backend_url}")?(
%{NUMBER:temp.duration:long}ms)?)?
ignore_missing: true
- remove:
field: message
ignore_missing: true
- remove:
field: traefik.access.message
ignore_missing: true
- rename:
field: '@timestamp'
target_field: event.created
- date:
field: traefik.access.time
target_field: '@timestamp'
formats:
- dd/MMM/yyyy:H:m:s Z
- remove:
field: traefik.access.time
- convert:
field: http.response.status_code
type: long
- grok:
field: source.address
patterns:
- ^(%{IP:source.ip}|%{HOSTNAME:source.domain})$
- script:
lang: painless
source: ctx.event.duration = Math.round(ctx.temp.duration * params.scale)
params:
scale: 1000000
if: ctx.temp?.duration != null
- remove:
field: temp.duration
ignore_missing: true
- user_agent:
field: user_agent.original
ignore_failure: true
- geoip:
field: source.ip
target_field: source.geo
ignore_missing: true
- geoip:
database_file: GeoLite2-ASN.mmdb
field: source.ip
target_field: source.as
properties:
- asn
- organization_name
ignore_missing: true
- rename:
field: source.as.asn
target_field: source.as.number
ignore_missing: true
- rename:
field: source.as.organization_name
target_field: source.as.organization.name
ignore_missing: true
- set:
field: event.kind
value: event
- append:
field: event.category
value: web
if: "ctx?.http?.request?.method != null && ctx.http.request.method != '-'"
- append:
field: event.type
value: access
if: "ctx?.http?.request?.method != null && ctx.http.request.method != '-'"
- set:
field: event.outcome
value: success
if: "ctx?.http?.response?.status_code != null && ctx.http.response.status_code < 400"
- set:
field: event.outcome
value: failure
if: "ctx?.http?.response?.status_code != null && ctx.http.response.status_code >= 400"
- append:
field: related.ip
value: "{{source.ip}}"
if: "ctx?.source?.ip != null"
- append:
field: related.ip
value: "{{destination.ip}}"
if: "ctx?.destination?.ip != null"
- append:
field: related.user
value: "{{user.name}}"
if: "ctx?.user?.name != null && ctx.user.name != '-'"
on_failure:
- set:
field: error.message
value: '{{ _ingest.on_failure_message }}'
2 changes: 1 addition & 1 deletion filebeat/module/traefik/access/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var:
os.windows:
- c:/programdata/traefik/logs/*access.log*

ingest_pipeline: ingest/pipeline.json
ingest_pipeline: ingest/pipeline.yml
input: config/traefik-access.yml

requires.processors:
Expand Down
Loading

0 comments on commit 72c5c29

Please sign in to comment.