From 5e78c93b71734364c687b9d7c63e1d6293b4a76b Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Mon, 30 Jan 2023 16:42:28 -0800 Subject: [PATCH] Added gam print chromeaues (#1597) --- src/GamCommands.txt | 4 +++ src/gam/__init__.py | 2 ++ src/gam/gapi/chromemanagement.py | 49 +++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/GamCommands.txt b/src/GamCommands.txt index a19e5f43..44cc9099 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -1392,6 +1392,10 @@ gam print chromeappdevices [todrive] [start ] [end ] [orderby deviceid|machine] +gam print chromeaues [todrive] + [ou|org|orgunit ] + [minauedate ] [maxauedate ] + gam print chromeversions [todrive] [ou|org|orgunit ] [start ] [end ] [recentfirst] diff --git a/src/gam/__init__.py b/src/gam/__init__.py index 7a8e97ea..1f8fc647 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -11888,6 +11888,8 @@ def ProcessGAMCommand(args): gapi_chromemanagement.printApps() elif argument in ['chromeappdevices']: gapi_chromemanagement.printAppDevices() + elif argument in ['chromeaues']: + gapi_chromemanagement.printAUEs() elif argument in ['chromeversions']: gapi_chromemanagement.printVersions() elif argument in ['chromehistory']: diff --git a/src/gam/gapi/chromemanagement.py b/src/gam/gapi/chromemanagement.py index 4341b420..c1121cb3 100644 --- a/src/gam/gapi/chromemanagement.py +++ b/src/gam/gapi/chromemanagement.py @@ -219,7 +219,7 @@ def printShowCrosTelemetry(mode): i = 3 if mode == 'info': if i >= len(sys.argv): - controlflow.system_error_exit(3, f' required for "gam info crostelemetry"') + controlflow.system_error_exit(3, ' required for "gam info crostelemetry"') filter_ = f'serialNumber={sys.argv[i]}' i += 1 mode = 'show' @@ -307,6 +307,53 @@ def printShowCrosTelemetry(mode): display.write_csv_file(csvRows, titles, 'Telemetry Devices', todrive) +CHROME_AUES_TITLES = [ + 'model', 'count', 'aueMonth', 'aueYear', 'expired' + ] +def printAUEs(): + cm = build() + customer = _get_customerid() + todrive = False + titles = CHROME_AUES_TITLES + csvRows = [] + orgunit = None + minAueDate = None + maxAueDate = None + i = 3 + while i < len(sys.argv): + myarg = sys.argv[i].lower().replace('_', '') + if myarg == 'todrive': + todrive = True + i += 1 + elif myarg in ['ou', 'org', 'orgunit']: + orgunit = _get_orgunit(sys.argv[i+1]) + i += 2 + elif myarg == 'minauedate': + minAueDate = _getFilterDate(sys.argv[i + 1]).strftime(YYYYMMDD_FORMAT) + i += 2 + elif myarg == 'maxauedate': + maxAueDate = _getFilterDate(sys.argv[i + 1]).strftime(YYYYMMDD_FORMAT) + i += 2 + else: + msg = f'{myarg} is not a valid argument to "gam print chromeversions"' + controlflow.system_error_exit(3, msg) + if orgunit: + orgUnitPath = gapi_directory_orgunits.orgunit_from_orgunitid(orgunit, None) + titles.append('orgUnitPath') + else: + orgUnitPath = '/' + gam.printGettingAllItems('Chrome Auto Update Expirations', orgUnitPath) + aues = gapi.call(cm.customers().reports(), + 'countChromeDevicesReachingAutoExpirationDate', + customer=customer, orgUnitId=orgunit, + minAueDate=minAueDate, maxAueDate=maxAueDate).get('deviceAueCountReports', []) + for aue in sorted(aues, key=lambda k: k.get('model', 'Unknown')): + if orgunit: + aue['orgUnitPath'] = orgUnitPath + csvRows.append(aue) + display.write_csv_file(csvRows, titles, 'Chrome AUEs', todrive) + + CHROME_VERSIONS_TITLES = [ 'version', 'count', 'channel', 'deviceOsVersion', 'system' ]