123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #!/bin/sh
- set -o nounset -o errexit -o pipefail -o xtrace
- username="${SCRIPT_OPENSEARCH_DASHBOARDS_USERNAME:-admin}"
- password="${SCRIPT_OPENSEARCH_DASHBOARDS_PASSWORD:-admin}"
- hostname="${SCRIPT_OPENSEARCH_DASHBOARDS_HOSTNAME:-opensearch-dashboards}"
- port="${SCRIPT_OPENSEARCH_DASHBOARDS_PORT:-5601}"
- users_and_passwors=(
- "${username}:${password}"
- "readall:readall"
- )
- # Return 0 if index pattern exists, other number otherwise.
- index_pattern()
- {
- curl --fail \
- --user "${username}:${password}" \
- --request GET \
- --silent \
- --verbose \
- "http://${hostname}:${port}/api/saved_objects/index-pattern/${1}"
- }
- for user_and_password in "${users_and_passwors[@]}"
- do
- if index_pattern 'logstash*'
- then
- echo "index-pattern 'logstash*' exists, skipping creation." >&2
- else
- curl --user "$user_and_password" \
- --silent \
- --verbose \
- --request POST \
- "http://${hostname}:${port}/api/saved_objects/index-pattern/logstash*" \
- --header "osd-xsrf:true" \
- --header "content-type:application/json" \
- --data '{"attributes": {"title": "logstash*", "timeFieldName": "@timestamp"}}'
- fi
- # sampleSize
- # The number of rows to show in the table
- # Default: 500
- #
- # truncate:maxHeight
- # The maximum height that a cell in a table should occupy. Set to 0 to disable truncation
- # Default: 115
- curl --user "$user_and_password" \
- --silent \
- --verbose \
- --request POST \
- --header 'Content-Type: application/json' \
- --header "osd-xsrf:true" \
- --data-raw '{"changes":{"discover:sampleSize":10000,"truncate:maxHeight":0}}' \
- "http://${hostname}:${port}/api/opensearch-dashboards/settings"
- done
- # Return 0 if the policy exists, other number otherwise.
- delete_old_indexes_policy()
- {
- curl --fail \
- --user "${username}:${password}" \
- --request GET \
- --silent \
- --verbose \
- "http://${hostname}:${port}/api/ism/policies/delete_old_indexes"
- }
- if [[ $(delete_old_indexes_policy) == *'{"ok":true,"response":{"id":"delete_old_indexes"'* ]]
- then
- echo "delete_old_indexes policy exists, skipping creation." >&2
- else
- curl --user "${username}:${password}" \
- --silent \
- --verbose \
- --header "osd-version: 1.2.0" \
- "http://${hostname}:${port}/api/ism/policies/delete_old_indexes" \
- --request PUT \
- --header 'Content-Type: application/json' \
- --data-raw '
- {
- "policy": {
- "description": "A simple default policy that deletes old indexes between hot and cold states.",
- "default_state": "hot",
- "states": [
- {
- "name": "hot",
- "actions": [],
- "transitions": [
- {
- "state_name": "cold",
- "conditions": {
- "min_index_age": "1d"
- }
- }
- ]
- },
- {
- "name": "cold",
- "actions": [
- {
- "delete": {}
- }
- ],
- "transitions": []
- }
- ],
- "ism_template": [
- {
- "index_patterns": [
- "filebeat-*",
- "logstash-*",
- "security-auditlog-*",
- "winlogbeat-*"
- ],
- "priority": 1
- }
- ]
- }
- }
- '
- fi
|