-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpfda.py
61 lines (47 loc) · 1.9 KB
/
cpfda.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
57
58
59
60
61
import py42.sdk
import py42.services
import csv
import os
import typer
from datetime import datetime
app = typer.Typer()
host = os.environ.get('CP_HOST', '')
username = os.environ.get('CP_USER', '')
password = os.environ.get('CP_PASSWD', '')
report_date = datetime.now().strftime('%Y-%m-%d')
@app.command()
def get_full_disk_access(
host:str = host,
username:str = username,
password:str = password,
report_name: str = f"crashplan-fda-{report_date}.csv",
):
"""Generate a CSV Report of Devices in All Orgs where full disk access is false"""
sdk = py42.sdk.from_local_account(host, username, password)
response = sdk.orgs.get_all(active=True)
report = []
for page in response:
for org in page['orgs']:
org_id = org['orgId']
statuses = sdk.orgs.get_agent_full_disk_access_states(org_id).data # change to `devices.get_all` for other things
# Logic below would need to change based on the request
for status in statuses:
if isinstance(status, dict):
guid = status['deviceGuid']
if status['value'] == "false": # condition to show only false entries
device_name = sdk.devices.get_by_guid(guid)['name']
report.append({
'org_name': org['orgName'],
'org_id': org_id,
'guid': guid,
'name': device_name,
'status': 'FULL DISK ACCESS DISABLED',
})
with open(report_name, 'w') as csvfile:
fieldnames = ['org_name', 'org_id', 'name', 'guid', 'status']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for row in report:
writer.writerow(row)
if __name__ == "__main__":
app()