Created
April 23, 2020 15:19
-
-
Save ebuildy/7c85631ad2511b04aa7567600aface95 to your computer and use it in GitHub Desktop.
This file contains 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 argparse, json, requests | |
parser = argparse.ArgumentParser(description='Create automatically index patterns, from elasticsearch indices.') | |
parser.add_argument('elasticsearch_url',type=str, help='elasticsearch full URL') | |
parser.add_argument('kibana_url', type=str, help='kibana full URL') | |
args = parser.parse_args() | |
indices = requests.get(args.elasticsearch_url + "/_cat/indices?format=json", verify=False).json() | |
indexFilter = "consolidation-" | |
for index in indices: | |
if str.startswith(index['index'], indexFilter): | |
print(index["index"]) | |
payload={ | |
"attributes": { | |
"title": index["index"] | |
} | |
} | |
name = str.replace(index["index"], indexFilter, "") | |
ret = requests.post(args.kibana_url + "/api/saved_objects/index-pattern/" + name, json=payload, headers={"kbn-xsrf":"true"}, verify=False) | |
print(ret.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
thanks for the script, but after script execution, an error message was provided.
Please advise an HTTPS and certificate use case.