Skip to content

Instantly share code, notes, and snippets.

@CodePint
Created September 27, 2022 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodePint/39c533b7bd0e65ad88875260b68afd46 to your computer and use it in GitHub Desktop.
Save CodePint/39c533b7bd0e65ad88875260b68afd46 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import requests
KIBANA_HOST = 'http://127.0.0.1:5601'
ELASTICSEARCH_HOST = 'http://127.0.0.1:9200'
BUILTIN_INDEX_SCHEMES = ('.kibana', '.apm')
def get_indices(es_host):
return requests.get(
url=f"{es_host}/_cat/indices",
params={'format': 'json'}
).json()
def save_index_pattern(index):
return requests.post(
url=f"{KIBANA_HOST}/api/saved_objects/index-pattern/{index}",
json={"attributes": {"title": index}},
headers={"kbn-xsrf":"true"},
).json()
def main():
indices = get_indices(ELASTICSEARCH_HOST)
for item in indices:
if not item['index'].startswith(BUILTIN_INDEX_SCHEMES):
output = save_index_pattern(item['index'])
print(output)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment