# Copyright Broadcom, Inc. All Rights Reserved.
# SPDX-License-Identifier: APACHE-2.0

http:
  http://logstash:{{ (index .Vars.service.ports 0).port }}:
    status: 200
file:
  {{ .Vars.persistence.mountPath }}:
    exists: true
    filetype: directory
    mode: "2777"
  /bitnami/logstash/config/logstash.conf:
    exists: true
    filetype: symlink
    mode: "0777"
    contents:
    - /port.*{{ (index .Vars.containerPorts 0).containerPort }}/
command:
  {{- $rnd_ip := printf "%s.%s.%s.%s" (randNumeric 2) (randNumeric 2) (randNumeric 2) (randNumeric 2) }}
  {{- $rnd_address := printf "http://%s.com" (randAlpha 5) }}
  test-pipeline:
    # Logstash can take some time to parse and filter each input
    exec: echo '{{ $rnd_ip }} - - [18/May/2011:19:35:08 -0700] "GET /css/main.css HTTP/1.1" 200 55 "{{ $rnd_address }}" "Mozilla/5.0"' >> /tmp/test_input && sleep 20 && cat /tmp/test_log
    exit-status: 0
    stdout:
      - "{{ $rnd_ip }}"
      - /status_code.*200/
      - /referrer.*{{ $rnd_address }}/
    timeout: 30000
  {{- $uid := .Vars.containerSecurityContext.runAsUser }}
  {{- $gid := .Vars.podSecurityContext.fsGroup }}
  check-user-info:
    # The UID and GID should always be either the one specified as vars (always a bigger number that the default)
    # or the one randomly defined by openshift (larger values). Otherwise, the chart is still using the default value.
    exec: if [ $(id -u) -lt {{ $uid }} ] || [ $(id -G | awk '{print $2}') -lt {{ $gid }} ]; then exit 1; fi
    exit-status: 0
  {{ if .Vars.automountServiceAccountToken }}
  check-sa:
    exec: cat /var/run/secrets/kubernetes.io/serviceaccount/token | cut -d '.' -f 2 | xargs -I '{}' echo '{}====' | fold -w 4 | sed '$ d' | tr -d '\n' | base64 -d
    exit-status: 0
    stdout:
    - /serviceaccount.*name.*{{.Env.BITNAMI_APP_NAME }}/
  {{ end }}
