Updating script to use data views to support kibana 8.0 and beyond
as some of api is now depreacated. Change-Id: I58d5c388cc0f6ba56c5fe646be352a0641e0661d
This commit is contained in:
parent
05f2f45971
commit
d9e0230365
@ -15,7 +15,7 @@ apiVersion: v1
|
||||
appVersion: v8.9.0
|
||||
description: OpenStack-Helm Kibana
|
||||
name: kibana
|
||||
version: 0.1.16
|
||||
version: 0.1.17
|
||||
home: https://www.elastic.co/products/kibana
|
||||
sources:
|
||||
- https://github.com/elastic/kibana
|
||||
|
@ -14,30 +14,65 @@ limitations under the License.
|
||||
*/}}
|
||||
set -ex
|
||||
|
||||
create_data_view() {
|
||||
local index_name=$1
|
||||
curl -u "${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||
--max-time 30 \
|
||||
-X POST "${KIBANA_ENDPOINT}/api/data_views/data_view" \
|
||||
-H "kbn-xsrf: true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"data_view\": {
|
||||
\"title\": \"${index_name}-*\",
|
||||
\"timeFieldName\": \"@timestamp\"
|
||||
}
|
||||
}"
|
||||
}
|
||||
|
||||
data_view_exists() {
|
||||
local index_name=$1
|
||||
local response=$(curl -s -u "${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||
--max-time 30 \
|
||||
-X GET "${KIBANA_ENDPOINT}/api/data_views" \
|
||||
-H "kbn-xsrf: true" \
|
||||
-H "Content-Type: application/json")
|
||||
|
||||
if echo "$response" | grep -q "\"title\":\"${index_name}-[*]\""; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
set_default_data_view() {
|
||||
local index_name=$1
|
||||
curl -u "${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||
--max-time 30 \
|
||||
-X POST "${KIBANA_ENDPOINT}/api/data_views/default" \
|
||||
-H "kbn-xsrf: true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"value\": \"${index_name}-*\"
|
||||
}"
|
||||
}
|
||||
|
||||
# Create data views
|
||||
{{- range $objectType, $indices := .Values.conf.create_kibana_indexes.indexes }}
|
||||
{{- range $indices }}
|
||||
curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||
-XPOST "${KIBANA_ENDPOINT}/api/saved_objects/index-pattern/{{ . }}*" -H 'kbn-xsrf: true' \
|
||||
-H 'Content-Type: application/json' -d \
|
||||
'{"attributes":{"title":"{{ . }}-*","timeFieldName":"@timestamp"}}'
|
||||
while true
|
||||
do
|
||||
if [[ $(curl -s -o /dev/null -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||
-w "%{http_code}" -XGET "${KIBANA_ENDPOINT}/api/saved_objects/index-pattern/{{ . }}*") == '200' ]]
|
||||
then
|
||||
break
|
||||
if ! data_view_exists "{{ . }}"; then
|
||||
create_data_view "{{ . }}"
|
||||
echo "Data view '{{ . }}' created successfully."
|
||||
else
|
||||
curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||
-XPOST "${KIBANA_ENDPOINT}/api/saved_objects/index-pattern/{{ . }}*" -H 'kbn-xsrf: true' \
|
||||
-H 'Content-Type: application/json' -d \
|
||||
'{"attributes":{"title":"{{ . }}-*","timeFieldName":"@timestamp"}}'
|
||||
sleep 30
|
||||
echo "Data view '{{ . }}' already exists."
|
||||
fi
|
||||
done
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
curl -K- <<< "--user ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
|
||||
-XPOST "${KIBANA_ENDPOINT}/api/kibana/settings/defaultIndex" -H 'kbn-xsrf: true' \
|
||||
-H 'Content-Type: application/json' -d \
|
||||
'{"value" : "{{ .Values.conf.create_kibana_indexes.default_index }}*"}'
|
||||
# Ensure default data view exists and set it
|
||||
default_index="{{ .Values.conf.create_kibana_indexes.default_index }}"
|
||||
if ! data_view_exists "$default_index"; then
|
||||
create_data_view "$default_index"
|
||||
echo "Default data view '${default_index}' created successfully."
|
||||
fi
|
||||
|
||||
set_default_data_view "$default_index"
|
||||
echo "Default data view set to '${default_index}'."
|
||||
|
@ -17,4 +17,5 @@ kibana:
|
||||
- 0.1.14 Add 2023.1 Ubuntu Focal overrides
|
||||
- 0.1.15 Use quay.io/airshipit/kubernetes-entrypoint:latest-ubuntu_focal by default
|
||||
- 0.1.16 Add 2024.1 Ubuntu Jammy overrides
|
||||
- 0.1.17 Update script to use data views replacing deprecated api
|
||||
...
|
||||
|
Loading…
Reference in New Issue
Block a user