Skip to content

Instantly share code, notes, and snippets.

@ebuildy
Created April 23, 2020 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebuildy/7c85631ad2511b04aa7567600aface95 to your computer and use it in GitHub Desktop.
Save ebuildy/7c85631ad2511b04aa7567600aface95 to your computer and use it in GitHub Desktop.
#!/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())
@heewey
Copy link

heewey commented May 4, 2021

Hi,

thanks for the script, but after script execution, an error message was provided.

Please advise an HTTPS and certificate use case.

 /usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:1020: InsecureRequestWarning: Unverified HTTPS request is being made to 
  host 'xyz'. Adding certificate verification is strongly advised.
  See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning,
  Traceback (most recent call last):
  File "./kibana_create_index_patterns.py", line 16, in <module>
    if str.startswith(index['index'], indexFilter):
  TypeError: string indices must be integers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment