3 # ============LICENSE_START=======================================================
5 # ================================================================================
6 # Copyright (C) 2018 AT&T Intellectual Property. All rights
8 # ================================================================================
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 # ============LICENSE_END============================================
21 # ===================================================================
35 """ Parse arguments given to this script"""
37 parser = argparse.ArgumentParser(
38 description=('Description of the script'))
39 parser.add_argument('-v', '--verbose', dest='log_level', action='store_const',
40 const=logging.DEBUG, default=logging.INFO,
41 help='Use verbose logging')
42 parser.add_argument('-C', '--configuration_path',
44 help='Path of the configuration to be backed up.')
45 parser.add_argument('-f', '--force', action='store_const',
46 const=True, default=False,
47 help=('If the save folder already exists, overwrite files'
48 ' matching a configuration item that should be written.'
49 ' Files already in the folder that do not match are'
51 parser.add_argument('-H', '--kibana-host', default='http://localhost:5601',
52 help='Kibana endpoint.')
54 return parser.parse_args(args)
57 """Creates the logger based on the provided arguments"""
59 logger = logging.getLogger(__name__)
60 logger.setLevel(args.log_level)
64 """ This script dumps the kibana configuration from Kibana"""
65 args = parse_args(sys.argv[1:])
67 base_config_path = args.configuration_path
69 # get list of the set of objects we update
70 url = "%s/api/saved_objects/_find" % (args.kibana_host.rstrip("/"),)
71 saved_objects_req = requests.get(url,
72 params={'per_page': PER_PAGE,'type':['config','search','dashboard','visualization','index-pattern']})
74 saved_objects = saved_objects_req.json()['saved_objects']
76 for obj in saved_objects:
78 obj_folder = os.path.sep.join((base_config_path, obj['type']))
80 if not os.path.exists(obj_folder):
81 os.makedirs(obj_folder)
83 filename = "%s/%s-%s.json" % (obj_folder, obj['type'], obj['id'])
84 with open(filename, 'w') as file:
85 json.dump(obj, fp=file)
88 if __name__ == "__main__":