-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_cdh_dbs_info.py
56 lines (49 loc) · 1.67 KB
/
get_cdh_dbs_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
#Obtención de los valores de parámetros de BB.DD. de Cloudera a partir de llamada a la API
import os
import sys
import json
#URL base
urlBase = "http://localhost:7180"
#Version de la API
apiRelease = "v13"
#Petición a API a través de curl, sólo GET
def execCurl(url):
headers = " -H 'Content-type: application/json' -H 'Accept-Charset: UTF-8'"
cmdGet = "curl -k -sS -X GET -u " + "'" + userCDH + ":" + passCDH + "' " + urlBase + "/api/" + apiRelease + url + " 2>/dev/null"
try:
return json.loads(os.popen(cmdGet).read())
except:
print("No ha sido posible realizar la peticion " + url)
sys.exit()
##Main
#Solicitud de credenciales de usuario administrador de Cloudera Manager
userCDH = raw_input("Introducir el nombre de usuario administrador de Cloudera Manager: ")
passCDH = raw_input("Introducir la password del usuario " + userCDH + ": ")
#Obtención y recorrido del JSON con la configuración y output de los parámetros
json = execCurl("/cm/deployment")
for n1 in json["clusters"]:
print "\nCluster: " + n1["displayName"]
for n2 in n1["services"]:
data = 0
print n2["displayName"]
for n3 in n2["config"]["items"]:
if "database" in n3["name"]:
data += 1
print "\t" + n3["name"] + ": " + n3["value"]
for n4 in n2["roleConfigGroups"]:
for n5 in n4["config"]["items"]:
if "database" in n5["name"]:
data += 1
print "\t" + n5["name"] + ": " + n5["value"]
if data == 0:
print "\tN/A"
for n1 in json["managementService"]["roleConfigGroups"]:
data = 0
print n1["displayName"]
for n2 in n1["config"]["items"]:
if "database" in n2["name"]:
data += 1
print "\t" + n2["name"] + ": " + n2["value"]
if data == 0:
print "\tN/A"