forked from device42/d42-bmc-atrium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoql.py
56 lines (44 loc) · 1.35 KB
/
doql.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
56
import base64
import csv
import json
import sys
import requests
class Doql_Util():
def csv_to_json(self, doql_csv, mapping_source=None):
listrows = doql_csv.split('\n')
fields = listrows[0].split(',')
rows = csv.reader(listrows[1:-1])
out = []
for row in rows:
items = zip(fields, row)
item = {}
for (name, value) in items:
item[name] = value.strip()
# dont add empty objects
out.append(item)
# if mapping_source, store all items under mapping_source
# to conform to shape of API results
if mapping_source is not None:
out = {mapping_source: out}
return out
return out
'''
POST https://10.42.2.241/services/data/v1.0/query/
query:SELECT * FROM view_assetaction_v1
header:yes
payload = {
"query": "SELECT * FROM view_ipaddress_v1",
"header": "yes"
}
header = {
'Authorization': 'Basic ' + base64.b64encode(
('xxxx' + ':' + 'xxxxx').encode()
).decode(),
'Content-Type': 'application/x-www-form-urlencoded'
}
url = "https://10.42.2.241/services/data/v1.0/query/?quote=\""
resp = requests.post(url, data=payload, headers=header, verify=False)
doql_util = Doql_Util()
jsonified = doql_util.csv_to_json(resp.text)
print(json.dumps(jsonified, indent=2))
'''