Location of custom Kibana dashboards in ElasticSearch

前端 未结 7 1200
走了就别回头了
走了就别回头了 2020-12-08 02:27

I know for a fact that saved Kibana dashboards (ie, the JSON file of the dashboard) are saved in OR associated to a particular ElasticSearch

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 03:24

    Here's a standalone Python script that can copy Kibana dashboards from elasticsearch host to another.

    #!/bin/env python
    
    """Migrate all the kibana dashboard from SOURCE_HOST to DEST_HOST.
    
    This script may be run repeatedly, but any dashboard changes on
    DEST_HOST will be overwritten if so.
    
    """
    
    import urllib2, urllib, json
    
    
    SOURCE_HOST = "your-old-es-host"
    DEST_HOST = "your-new-es-host"
    
    
    def http_post(url, data):
        request = urllib2.Request(url, data)
        return urllib2.urlopen(request).read()
    
    
    def http_put(url, data):
        opener = urllib2.build_opener(urllib2.HTTPHandler)
        request = urllib2.Request(url, data)
        request.get_method = lambda: 'PUT'
        return opener.open(request).read()
    
    
    if __name__ == '__main__':
        old_dashboards_url = "http://%s:9200/kibana-int/_search" % SOURCE_HOST
    
        # All the dashboards (assuming we have less than 9999) from
        # kibana, ignoring those with _type: temp.
        old_dashboards_query = """{
           size: 9999,
           query: { filtered: { filter: { type: { value: "dashboard" } } } } }
        }"""
    
        old_dashboards_results = json.loads(http_post(old_dashboards_url, old_dashboards_query))
        old_dashboards_raw = old_dashboards_results['hits']['hits']
    
        old_dashboards = {}
        for doc in old_dashboards_raw:
            old_dashboards[doc['_id']] = doc['_source']
    
        for id, dashboard in old_dashboards.iteritems():
            put_url = "http://%s:9200/kibana-int/dashboard/%s" % (DEST_HOST, urllib.quote(id))
            print http_put(put_url, json.dumps(dashboard))
    

提交回复
热议问题