-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·46 lines (44 loc) · 1.86 KB
/
Copy pathmain.py
File metadata and controls
executable file
·46 lines (44 loc) · 1.86 KB
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
from shared.resources import connect_to_api, parse_policy
from datetime import datetime
import flask
my_devices = connect_to_api("GET", "http://127.0.0.1:5005/api/v1/devices/verified/")
my_devices = my_devices.json().get("data")
my_policies = connect_to_api("GET", "http://127.0.0.1:5005/api/v1/config/compliance/")
my_policies = my_policies.json().get("data")
policy_config = {}
current = datetime.now()
print("********** Creating Compliance Report... **********")
with open(
f"./compliance/reports/report-{current.strftime('%d-%m-%Y_%H:%M:%S')}.txt", "w"
) as file:
file.write(
f"********** Compliance Report, Ran {current.strftime('%d-%m-%Y %H:%M:%S')} **********\n\n"
)
for device in my_devices:
viol_id = 1
file.write(f"\n********** Host {device.get('deviceName')} ********** \n")
for policy in my_policies:
if policy.get("platform") == device.get("NOS") and device.get(
"Role"
).split()[2].lower() in policy.get("device_types"):
if policy.get("parent") != "None":
configPair = (policy.get("parent"), policy.get("config"))
else:
configPair = (None, policy.get("config"))
result = parse_policy(
configPair,
f"./compliance/currentConfigs/{device.get('deviceName')}.txt",
)
if not result:
file.write(
f"- Violation {viol_id}"
f" - {policy.get('name')} is not applied\n"
)
viol_id += 1
connect_to_api(
"DELETE",
f"http://127.0.0.1:5005/api/v1/devices/verified/{device.get('deviceName')}/",
)
if viol_id == 1:
file.write("No violations found!\n")
print("********** Completed! **********")