---
description: Pipeline for parsing Sophos XG firewall logs (anti-spam pipeline).
processors:
#######################
## ECS Event Mapping ##
#######################
- set:
    field: event.kind
    value: event
- set:
    field: event.action
    value: "{{sophos.xg.log_subtype}}"
    ignore_empty_value: true
- set:
    field: event.outcome
    value: success
    ignore_empty_value: true
- set:
    field: event.kind
    value: alert
    if: '["13001", "13002", "13004", "13005", "13006", "13009", "13012", "13014", "14001", "14002", "15001", "15002"].contains(ctx.event?.code)'
- append:
    field: event.category
    value: malware
    if: '["13001", "13002", "13004", "13005", "13006", "13009", "13014", "14001", "14002", "15001", "15002"].contains(ctx.event?.code)'
- append:
    field: event.category
    value: intrusion_detection
    if: "ctx.event?.code == '13012'"
- append:
    field: event.category
    value: network
- append:
    field: event.type
    value:
     - allowed
     - connection
    if: '["13003", "13007", "13008", "13010", "13013", "14003", "15003", "18035"].contains(ctx.event?.code)'
- append:
    field: event.type
    value:
      - info
      - denied
      - connection
    if: '["13001", "13002", "13004", "13005", "13006", "13009", "13012", "13014", "14001", "14002", "15001", "15002"].contains(ctx.event?.code)'


####################################
## ECS 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"
- rename:
    field: sophos.xg.to_email_address
    target_field: destination.user.email
    ignore_missing: true

###############################
## ECS Source Mapping
###############################
- rename:
    field: sophos.xg.src_ip
    target_field: source.ip
    ignore_missing: true
- 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.from_email_address
    target_field: source.user.email
    ignore_missing: true
- rename:
     field: sophos.xg.src_domainname
     target_field: source.domain
     ignore_missing: true

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

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