---
apiVersion: v1
kind: ConfigMap
metadata:
  name: automium-logging-filebeat-config
  namespace: kube-system
  labels:
    k8s-app: automium-logging-filebeat
data:
  filebeat.yml: |-
    setup.ilm.enabled: auto
    setup.ilm.rollover_alias: "{{ .Values.esCluster.indexName }}"
    setup.ilm.pattern: "{now/M{yyyy.MM}}-000001"
    setup.ilm.policy_name: "{{ .Values.esCluster.ILMpolicy_name }}"
    setup.ilm.policy_file: "/etc/filebeat/ILMTemplate.yaml"
    setup.template.name: "{{ .Values.esCluster.indexName }}"
    setup.template.pattern: "{{ .Values.esCluster.indexName }}-*"
    setup.template.settings.index.lifecycle.name: "{{ .Values.esCluster.ILMpolicy_name }}"

    filebeat.autodiscover:
      providers:
        - type: kubernetes
          host: ${NODE_NAME}
          hints.enabled: true
          hints.default_config.enabled: true
          add_resource_metadata:
            namespace:
              enabled: true
    processors:
    - add_fields:
        target: cluster_name
        fields:
          name: {{ .Values.clusterName }}
    output.elasticsearch:
      hosts: ['{{ .Values.esCluster.url }}']
      username: {{ .Values.esCluster.username }}
      password: {{ .Values.esCluster.password }}
      {{- if .Values.esCluster.insecureTLS }}
      ssl.verification_mode: "none"
      {{- end }}
      index: "{{ .Values.esCluster.indexName }}-%{+dd.MM.yyyy}"
  ILMTemplate.yaml: |-
    {
      "policy": {
        "phases": {
          "hot": {
            "min_age": "0ms",
            "actions": {
              "rollover": {
                "max_age": "{{ .Values.ilm.actions.rollover.max_age }}",
                "max_size": "{{ .Values.ilm.actions.rollover.maximumIndexSize }}"
              },
              "set_priority": {
                "priority": null
              }
            }
          },
          "delete": {
            "min_age": "{{ .Values.ilm.actions.delete.min_age }}",
            "actions": {
              "delete": {}
            }
          }
        }
      }
    }