Added commands to display Chrome device counts.

This commit is contained in:
Ross Scroggs
2025-11-07 09:17:36 -08:00
parent a5ff890a15
commit 844e6442ac
6 changed files with 82 additions and 4 deletions

View File

@@ -2371,6 +2371,15 @@ gam show chromeprofilecommands <ChromeProfileNameEntity>
gam print chromeprofilecommands <ChromeProfileNameEntity> [todrive <ToDriveAttribute>*]
[formatjson [quotechar <Character>]]
# Chrome Device Counts
gam show chromedevicecounts
[mode active|perboottype|perreleasechannel] [date <Date>]
[formatjson]
gam print chromedevicecounts [todrive <ToDriveAttribute>*]
[mode active|perboottype|perreleasechannel] [date <Date>]
[formatjson [quotechar <Character>]]
# Chrome Versions Counts
gam show chromeversions

View File

@@ -1,3 +1,9 @@
7.28.02
Added commands to display Chrome device counts.
* See: https://github.com/GAM-team/GAM/wiki/Chrome-Device-Counts
7.28.01
Updated `gam <UserTypeEntity> show fileinfo <DriveFileEntity>` to display `displayName` as the key field

View File

@@ -25,7 +25,7 @@ https://github.com/GAM-team/GAM/wiki
"""
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
__version__ = '7.28.01'
__version__ = '7.28.02'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
#pylint: disable=wrong-import-position
@@ -31919,6 +31919,65 @@ def doPrintShowChromeNeedsAttn():
if csvPF:
csvPF.writeCSVfile('Chrome Devices Needing Attention')
CHROME_DEVICE_COUNTS_MODE_CHOICES = ['active', 'perboottype', 'perreleasechannel']
CHROME_DEVICE_COUNTS_MODE_FUNCTIONS = {
'active': 'countActiveDevices',
'perboottype': 'countDevicesPerBootType',
'perreleasechannel': 'countDevicesPerReleaseChannel'
}
CHROME_DEVICE_COUNTS_MODE_CSV_TITLE = {
'active': 'Chrome Active Devices',
'perboottype': 'Chrome Devices per Boot Type',
'perreleasechannel': 'Chrome Devices per Release Channel'
}
# gam print chromedevicecounts [todrive <ToDriveAttribute>*]
# [mode active|perboottype|perreleasechannel] [date <Date>]
# [formatjson [quotechar <Character>]]
# gam show chromedevicecounts
# [mode active|perboottype|perreleasechannel] [date <Date>]
# [formatjson]
def doPrintShowChromeDeviceCounts():
cm = buildGAPIObject(API.CHROMEMANAGEMENT)
customerId = _getCustomersCustomerIdWithC()
csvPF = CSVPrintFile() if Act.csvFormat() else None
FJQC = FormatJSONQuoteChar(csvPF)
pdate = todaysDate()
mode = 'active'
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if csvPF and myarg == 'todrive':
csvPF.GetTodriveParameters()
elif myarg == 'mode':
mode = getChoice(CHROME_DEVICE_COUNTS_MODE_CHOICES)
elif myarg == 'date':
pdate = getYYYYMMDD(returnDateTime=True)
else:
FJQC.GetFormatJSONQuoteChar(myarg, True)
kwargs = {'date_day': pdate.day, 'date_month': pdate.month, 'date_year': pdate.year}
try:
counts = callGAPI(cm.customers().reports(), CHROME_DEVICE_COUNTS_MODE_FUNCTIONS[mode],
throwReasons=[GAPI.INVALID, GAPI.INVALID_ARGUMENT, GAPI.PERMISSION_DENIED, GAPI.SERVICE_NOT_AVAILABLE],
retryReasons=GAPI.SERVICE_NOT_AVAILABLE_RETRY_REASONS,
customer=customerId, **kwargs)
except (GAPI.invalid, GAPI.invalidArgument, GAPI.permissionDenied, GAPI.serviceNotAvailable) as e:
entityActionFailedWarning([Ent.CHROME_DEVICE_COUNT, None], str(e))
return
for k, v in counts.items():
counts[k] = int(v)
if not csvPF:
if not FJQC.formatJSON:
showJSON(CHROME_DEVICE_COUNTS_MODE_CSV_TITLE[mode], counts)
else:
printLine(json.dumps(cleanJSON(counts), ensure_ascii=False, sort_keys=True))
else:
row = flattenJSON(counts)
if not FJQC.formatJSON:
csvPF.WriteRowTitles(row)
elif csvPF.CheckRowTitles(row):
csvPF.WriteRowNoFilter({'JSON': json.dumps(cleanJSON(counts), ensure_ascii=False, sort_keys=True)})
csvPF.writeCSVfile(CHROME_DEVICE_COUNTS_MODE_CSV_TITLE[mode])
CHROME_VERSIONS_TITLES = ['channel', 'system', 'deviceOsVersion']
# gam print chromeversions [todrive <ToDriveAttribute>*]
@@ -78683,6 +78742,7 @@ MAIN_COMMANDS_WITH_OBJECTS = {
Cmd.ARG_CHROMEAPP: doPrintShowChromeApps,
Cmd.ARG_CHROMEAPPDEVICES: doPrintShowChromeAppDevices,
Cmd.ARG_CHROMEAUES: doPrintShowChromeAues,
Cmd.ARG_CHROMEDEVICECOUNTS: doPrintShowChromeDeviceCounts,
Cmd.ARG_CHROMEHISTORY: doPrintShowChromeHistory,
Cmd.ARG_CHROMENEEDSATTN: doPrintShowChromeNeedsAttn,
Cmd.ARG_CHROMEPOLICY: doPrintShowChromePolicies,
@@ -78820,6 +78880,7 @@ MAIN_COMMANDS_WITH_OBJECTS = {
Cmd.ARG_CHROMEAPP: doPrintShowChromeApps,
Cmd.ARG_CHROMEAPPDEVICES: doPrintShowChromeAppDevices,
Cmd.ARG_CHROMEAUES: doPrintShowChromeAues,
Cmd.ARG_CHROMEDEVICECOUNTS: doPrintShowChromeDeviceCounts,
Cmd.ARG_CHROMEHISTORY: doPrintShowChromeHistory,
Cmd.ARG_CHROMENEEDSATTN: doPrintShowChromeNeedsAttn,
Cmd.ARG_CHROMEPOLICY: doPrintShowChromePolicies,

View File

@@ -397,8 +397,7 @@ _CLIENT_SCOPES = [
'api': CLOUDIDENTITY_POLICY,
'subscopes': READONLY,
'roByDefault': True,
'scope': 'https://www.googleapis.com/auth/cloud-identity.policies'
},
'scope': 'https://www.googleapis.com/auth/cloud-identity.policies'},
{'name': 'Cloud Identity API - User Invitations',
'api': CLOUDIDENTITY_USERINVITATIONS,
'subscopes': READONLY,
@@ -413,7 +412,7 @@ _CLIENT_SCOPES = [
'subscopes': [],
'offByDefault': True,
'scope': STORAGE_READWRITE_SCOPE},
{'name': 'Contacts API - Domain Shared Contacts and GAL',
{'name': 'Contacts API - Domain Shared Contacts',
'api': CONTACTS,
'subscopes': [],
'scope': 'https://www.google.com/m8/feeds'},

View File

@@ -754,6 +754,7 @@ class GamCLArgs():
ARG_CHATSPACE = 'chatspace'
ARG_CHATSPACES = 'chatspaces'
ARG_CHATSPACEDM = 'chatspacedm'
ARG_CHROMEDEVICECOUNTS = 'chromedevicecounts'
ARG_CHROMEAPP = 'chromeapp'
ARG_CHROMEAPPS = 'chromeapps'
ARG_CHROMEAPPDEVICES = 'chromeappdevices'

View File

@@ -106,6 +106,7 @@ class GamEntity():
CHROME_BROWSER_ENROLLMENT_TOKEN = 'cbet'
CHROME_CHANNEL = 'chan'
CHROME_DEVICE = 'chdv'
CHROME_DEVICE_COUNT = 'chdc'
CHROME_MODEL = 'chmo'
CHROME_NETWORK_ID = 'chni'
CHROME_NETWORK_NAME = 'chnn'
@@ -473,6 +474,7 @@ class GamEntity():
CHROME_BROWSER_ENROLLMENT_TOKEN: ['Chrome Browser Enrollment Tokens', 'Chrome Browser Enrollment Token'],
CHROME_CHANNEL: ['Chrome Channels', 'Chrome Channel'],
CHROME_DEVICE: ['Chrome Devices', 'Chrome Device'],
CHROME_DEVICE_COUNT: ['Chrome Device Counts', 'Chrome Device Count'],
CHROME_MODEL: ['Chrome Models', 'Chrome Model'],
CHROME_NETWORK_ID: ['Chrome Network IDs', 'Chrome Network ID'],
CHROME_NETWORK_NAME: ['Chrome Network Names', 'Chrome Network Name'],