import subprocess import sys,json # Set your cluster details username = sys.argv[1] password = sys.argv[2] def get_cluster_name(username,password): url = 'http://headnodehost:8080/api/v1/clusters/' curl_command = 'curl -u {}:{} -H "X-Requested-By: ambari" -X GET {}'.format(username, password, url) try: output = subprocess.check_output(curl_command, shell=True) json_output = json.loads(output.strip()) cluster_name=json_output['items'][0]['Clusters']['cluster_name'] return cluster_name except subprocess.CalledProcessError as e: print('Error:', e) return {} def save_configs(data,output_file): with open(output_file, 'w') as file: json.dump(data, file, indent=4) def get_ambari_current_configurations(cluster_name, username, password): url = 'http://headnodehost:8080/api/v1/clusters/{}/configurations/service_config_versions?is_current=true'.format(cluster_name) curl_command = 'curl -u {}:{} -H "X-Requested-By: ambari" -X GET {}'.format(username, password, url) try: output = subprocess.check_output(curl_command, shell=True) json_output = json.loads(output.strip()) return json_output except subprocess.CalledProcessError as e: print('Error:', e) return {} cluster_name=get_cluster_name(username,password) configurations = get_ambari_current_configurations(cluster_name, username, password) file_name="%s.out"%cluster_name save_configs(configurations,file_name)