Created
September 27, 2022 12:27
-
-
Save CodePint/39c533b7bd0e65ad88875260b68afd46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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