-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfindings_csv.py
executable file
·35 lines (30 loc) · 1.03 KB
/
findings_csv.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
#!/usr/bin/env python
import csv
import requests
from urllib.parse import urljoin
token = input("API Token:")
headers = {"Authorization": "JWT {}".format(token)}
api_base_url = "https://api.probely.com"
findings_endpoint = urljoin(
api_base_url, "findings/?include=compliance&length=10000"
)
response = requests.get(findings_endpoint, headers=headers)
results = response.json()["results"]
with open("findings.csv", "w") as csv_file:
csv_writer = csv.writer(
csv_file, delimiter=",", quotechar='"', quoting=csv.QUOTE_ALL
)
for result in results:
labels = result["labels"] if result.get("labels") else []
labels_name = [label["name"] for label in labels]
row = [
result["id"],
result["severity"],
result["definition"]["name"],
result["url"],
result["last_found"],
result["state"],
result.get("assignee")["email"] if result.get("assignee") else " ",
*labels_name
]
csv_writer.writerow(row)