{{ if eq .input "httpjson" }}

type: httpjson
interval: {{ .interval }}
request.method: GET
auth.oauth2:
  enabled: true
  {{ if .client_id }}
  client.id: {{ .client_id }}
  {{ end }}
  {{ if .client_secret }}
  client.secret: {{ .client_secret }}
  {{ end }}
  {{ if .token_url }}
  token_url: {{ .token_url }}
  {{ end }}
  {{ if .user }}
  user: {{ .user }}
  {{ end }}
  {{ if .password }}
  password: {{ .password }}
  {{ end }}
# Query params will be overwritten by request.transforms from start of the input and 
# it is to indicate that this url is for SetupAuditTratil type of events as cursor stores the url as source.
# Each filebeat input cursor source needs to be uniquely identified with a name.
request.url: {{ .url }}/services/data/v52.0/query?q=setupaudittrail+rest
{{ if .proxy_url }}
request.proxy_url: {{ .proxy_url }}
{{ end }}
request.transforms:
  - set:
      target: url.params.q
      value: "SELECT Action,CreatedByContext,CreatedById,CreatedByIssuer,CreatedDate,DelegateUser,Display,Id,ResponsibleNamespacePrefix,Section FROM SetupAuditTrail WHERE CreatedDate > [[.cursor.last_published_setupaudittrail]] ORDER BY CreatedDate ASC NULLS FIRST"
      default: "SELECT Action,CreatedByContext,CreatedById,CreatedByIssuer,CreatedDate,DelegateUser,Display,Id,ResponsibleNamespacePrefix,Section FROM SetupAuditTrail ORDER BY CreatedDate ASC NULLS FIRST"
response.split:
  target: body.records
cursor:
  last_published_setupaudittrail:
    value: '[[.last_event.CreatedDate]]'

{{ else if eq .input "file" }}

type: log
paths:
{{ range $i, $path := .paths }}
  - {{$path}}
{{ end }}
exclude_files: [".gz$"]

{{ end }}

tags: {{.tags | tojson}}
publisher_pipeline.disable_host: {{ inList .tags "forwarded" }}

processors:
  - decode_json_fields:
      fields: [message]
      target: "json"
  - add_fields:
      target: ''
      fields:
        ecs.version: 1.12.0
  - add_locale: ~
