input {
  beats {
    port => 5044
    ssl_enabled => true
    ssl_certificate => "{{ ssl_public_certs_path }}/logstash-public.crt"
    ssl_key => "{{ ssl_private_key_path }}/logstash-private.key"
  }
}

filter {
  if [fields][log_type] == "resource-usage-log" {
    grok {
      match => { "[log][file][path]" => ".*/(?<filename>[^/]*)$" }
    }
  }
  if [fields][log_type] == "safenode-log" {
    grok {
      match => { "[log][file][path]" => "/home/safe/.local/share/safe/node/%{GREEDYDATA:filename}" }
    }
  }
}

output {
  if [fields][log_type] == "resource-usage-log" {
    s3 {
      access_key_id => "{{ aws_access_key_id }}"
      secret_access_key => "{{ aws_secret_access_key }}"
      region => "{{ aws_region }}"
      bucket => "{{ aws_bucket }}"
      canned_acl => "public-read"
      time_file => 5
      rotation_strategy => "time"
      prefix => "testnet-logs/%{[fields][testnet_name]}/%{[host][name]}/%{filename}"
      codec => plain {
        format => "%{message}\n"
      }
    }
  }
  if [fields][log_type] == "safenode-log" {
    s3 {
      access_key_id => "{{ aws_access_key_id }}"
      secret_access_key => "{{ aws_secret_access_key }}"
      region => "{{ aws_region }}"
      bucket => "{{ aws_bucket }}"
      canned_acl => "public-read"
      time_file => 5
      rotation_strategy => "time"
      prefix => "testnet-logs/%{[fields][testnet_name]}/%{[host][name]}/%{filename}"
      codec => plain {
        format => "%{message}\n"
      }
    }
  }
}
