---
description: Pipeline for parsing sophos firewall logs (ipd 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: '["06001", "06002", "07001", "07002"].contains(ctx.event?.code)'
- append:
    field: event.type
    value:
      - denied
      - connection
    if: '["06001", "06002", "07001", "07002"].contains(ctx.event?.code)'

####################################
## ECS Server/Destination Mapping ##
####################################
- rename:
    field: sophos.xg.dst_ip
    target_field: destination.ip
    ignore_missing: true
    if: "ctx.sophos?.xg?.dst_ip != 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.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
    if: "ctx.sophos?.xg?.user_name != null"

######################
## ECS Rule Mapping ##
######################
- rename:
    field: sophos.xg.signature_id
    target_field: rule.id
    ignore_missing: true
    if: "ctx.sophos?.xg?.signature_id != null"
- rename:
    field: sophos.xg.signature_msg
    target_field: rule.name
    ignore_missing: true
    if: "ctx.sophos?.xg?.signature_msg != null"
- rename:
    field: sophos.xg.classification
    target_field: rule.category
    ignore_missing: true
    if: "ctx.sophos?.xg?.classification != null"

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

#############
## Cleanup ##
#############
- lowercase:
      field: network.protocol
      ignore_failure: true
- 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 }}'
