# HTTP to File Pipeline
# Receive HTTP POST requests, transform data, and save to files in batches
#
# Source: https://docs.expanso.io/examples/http-to-file
#
# Usage:
#   curl -o config.yaml https://docs.expanso.io/examples/http-to-file.yaml
#   expanso-edge run -f config.yaml

input:
  http_server:
    address: 0.0.0.0:8082
    path: /events
    allowed_verbs:
      - POST
    sync_response:
      status: "202"
      headers:
        Content-Type: application/json

pipeline:
  processors:
    # Validate and parse JSON
    - mapping: |
        root = this.parse_json().catch(deleted())

    # Add metadata
    - mapping: |
        root.received_at = now()
        root.node_id = env("NODE_ID").or("unknown")
        root.processing_id = uuid_v4()

    # Group into batches
    - archive:
        format: json_array

    # Add batch metadata
    - mapping: |
        root.batch_id = uuid_v4()
        root.batch_size = this.length()
        root.events = this

output:
  file:
    path: /var/log/expanso/events/${!timestamp_unix()}.json
