---
description: Pipeline for parsing sophos firewall logs (atp pipeline)
processors:
#######################
## ECS Event Mapping ##
#######################
- set:
    field: event.kind
    value: alert
- set:
    field: event.action
    value: "{{sophos.xg.log_subtype}}"
    if: "ctx.sophos?.xg?.log_subtype != null"
- set:
    field: event.outcome
    value: success
    if: "ctx.sophos?.xg?.log_subtype != null"
- append:
    field: event.category
    value:
      - intrusion_detection
      - network
    if: '["18009", "18010"].contains(ctx.event?.code)'
- append:
    field: event.type
    value:
      - denied
      - connection
    if: '["18009", "18010"].contains(ctx.event?.code)'
- rename:
    field: sophos.xg.eventid
    target_field: event.id
    ignore_missing: true
    if: "ctx.sophos?.xg?.eventid != null"

####################################
## ECS Server/Destination Mapping ##
####################################
- rename:
    field: sophos.xg.destinationip
    target_field: destination.ip
    ignore_missing: true
    if: "ctx.sophos?.xg?.destinationip != null"
- convert:
    field: sophos.xg.dst_port
    target_field: destination.port
    type: long
    ignore_failure: true
    ignore_missing: true
    if: "ctx.sophos?.xg?.dst_port != null"

###############################
## ECS Client/Source Mapping ##
###############################
- rename:
    field: sophos.xg.sourceip
    target_field: source.ip
    ignore_missing: true
    if: "ctx.sophos?.xg?.sourceip != null"
- rename:
    field: sophos.xg.src_ip
    target_field: source.ip
    ignore_missing: true
    if: "ctx.sophos?.xg?.src_ip != null"
- convert:
    field: sophos.xg.src_port
    target_field: source.port
    type: long
    ignore_failure: true
    ignore_missing: true
    if: "ctx.sophos?.xg?.src_port != null"
- rename:
    field: sophos.xg.user_name
    target_field: source.user.name
    ignore_missing: true

#####################
## ECS URL Mapping ##
#####################
- rename:
     field: sophos.xg.url
     target_field: url.original
     ignore_missing: true
     if: "ctx.sophos?.xg?.url != null"
- uri_parts:
    if: ctx.url?.original != null && ctx.url.original.contains("://")
    field: url.original
    target_field: url
- set:
    if: ctx.url?.original != null && ctx.url.original.contains("://")
    field: url.full
    copy_from: url.original
    ignore_empty_value: true

######################
## ECS Network Mapping
######################
- rename:
    field: sophos.xg.protocol
    target_field: network.transport
    ignore_missing: true

#############
## Cleanup ##
#############
- lowercase:
      field: event.action
      ignore_failure: true
- lowercase:
      field: event.info
      ignore_failure: true
- remove:
    field:
    - sophos.xg.dst_port
    - sophos.xg.src_port
    ignore_missing: true
on_failure:
- set:
    field: error.message
    value: '{{ _ingest.on_failure_message }}'
