description: Pipeline for parsing ZooKeeper log messages
processors:
- set:
    field: event.ingested
    value: '{{_ingest.timestamp}}'
- rename:
    field: message
    target_field: event.original
- grok:
    field: event.original
    trace_match: true
    patterns:
      - '%{TIMESTAMP_ISO8601:zookeeper.log.timestamp}%{SPACE}\[myid:(%{POSINT:service.node.name})?\]%{SPACE}-%{SPACE}%{LOGLEVEL:log.level}%{SPACE}\[%{DATA:zookeeper.log.process}\]%{SPACE}-%{SPACE}%{GREEDYDATA:message}'
- grok:
    field: zookeeper.log.process
    ignore_missing: true
    ignore_failure: true
    patterns:
    - '%{GREEDYDATA:process.thread.name}:%{CALLER_CLASS:log.logger}@%{POSINT:log.origin.file.line}'
    pattern_definitions:
      CALLER_CLASS: (%{JAVACLASS}|%{NOTSPACE})
- remove:
    field: zookeeper.log.process
    ignore_missing: true
- rename:
    field: '@timestamp'
    target_field: event.created
- date:
    if: ctx.event.timezone == null
    field: zookeeper.log.timestamp
    target_field: '@timestamp'
    formats:
    - yyyy-MM-dd HH:mm:ss,SSS
    on_failure:
    - append:
        field: error.message
        value: '{{ _ingest.on_failure_message }}'
- date:
    if: ctx.event.timezone != null
    field: zookeeper.log.timestamp
    target_field: '@timestamp'
    formats:
    - yyyy-MM-dd HH:mm:ss,SSS
    timezone: '{{ event.timezone }}'
    on_failure:
    - append:
        field: error.message
        value: '{{ _ingest.on_failure_message }}'
- remove:
    field: zookeeper.log.timestamp
- set:
    field: event.kind
    value: event
- script:
    lang: painless
    source: >-
      def errorLevels = ["ERROR", "FATAL"];
      if (ctx?.log?.level != null) {
        if (errorLevels.contains(ctx.log.level)) {
          ctx.event.type = "error";
        } else {
          ctx.event.type = "info";
        }
      }
on_failure:
- set:
    field: error.log
    value: '{{ _ingest.on_failure_message }}'
