This is my get output on each asset im getting data back from
I can access the dictionary values easily,
JavaScript
x
2
1
page = json_response["page"].get("number", 0)
2
but how doo i access the value of the array, i want to be able to add up each critical vulnerability
this is the return, im trying to get critical, moderate, severe values from the vulnerabilities sub array
JavaScript
1
32
32
1
{'links': [{}],
2
'page': {'number': 6, 'size': 10, 'totalPages': 13, 'totalResources': 123},
3
'resources': [{'addresses': [],
4
'assessedForPolicies': False,
5
'assessedForVulnerabilities': True,
6
'configurations': [],
7
'databases': [],
8
'files': [],
9
'history': [],
10
'hostName': 'corporate-workstation-1102DC.acme.com',
11
'hostNames': [],
12
'id': 282,
13
'ids': [],
14
'ip': '182.34.74.202',
15
'links': [],
16
'mac': 'AB:12:CD:34:EF:56',
17
'os': 'Microsoft Windows Server 2008 Enterprise Edition SP1',
18
'osFingerprint': {},
19
'rawRiskScore': 31214.3,
20
'riskScore': 37457.16,
21
'services': [],
22
'software': [],
23
'type': '',
24
'userGroups': [],
25
'users': [],
26
'vulnerabilities': {'critical': 16,
27
'exploits': 4,
28
'malwareKits': 0,
29
'moderate': 3,
30
'severe': 76,
31
'total': 95}}]}
32
Advertisement
Answer
You’ve done a poor job of explaining it, but I’d bet that resources
is a list of multiple dictionaries in your original data, and you want to do something with all of those values.
JavaScript
1
10
10
1
vulnerabilities = []
2
resources = json_response['resources']
3
for d in resources:
4
if 'vulnerabilities' in d:
5
vulnerabilities.append(d['vulnerabilities'])
6
7
print(vulnerabilities)
8
print(sum(x.get('critical', 0) for x in vulnerabilities))
9
print(sum(x.get('severe', 0) for x in vulnerabilities))
10
Output:
JavaScript
1
4
1
[{'critical': 16, 'exploits': 4, 'malwareKits': 0, 'moderate': 3, 'severe': 76, 'total': 95}]
2
16
3
76
4