openstack-helm-infra/fluent-logging/templates/bin/_create_template.sh.tpl
Steve Wilkerson 4b8f46abee Fluent-logging: Support creation of arbitrary number of templates
This updates the fluent-logging chart to support the creation of
an arbitrary number of templates for elasticsearch. This allows
for the definition of multiple index mappings driven via the
chart's values. This provides flexibility in determining specific
structures for indexes that may differ between log types.

This also moves to define these mappings via json instead of XML.
As gotpl can convert yaml directly to json, and elasticsearch can
ingest json directly for index creation, we no longer need an XML
helper function to generate the required configuration. This helps
reduce the number of helper functions we need to maintain

Change-Id: I3c85fb9a1e700eb1592d96f83e632172d0eb2681
2018-06-04 12:46:34 -05:00

18 lines
525 B
Smarty

#!/bin/bash
set -ex
{{ range $template, $fields := .Values.conf.templates }}
result=$(curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
-XPUT "${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}/_template/{{$template}}" \
-H 'Content-Type: application/json' -d @/tmp/{{$template}}.json \
| python -c "import sys, json; print json.load(sys.stdin)['acknowledged']")
if [ "$result" == "True" ]; then
echo "{{$template}} template created!"
else
echo "{{$template}} template not created!"
fi
{{ end }}