From a33c63782442079ad50b4c1280c6da7f5faf447b Mon Sep 17 00:00:00 2001 From: myxxmikeyxx Date: Thu, 24 Jun 2021 15:50:03 -0400 Subject: [PATCH] working on code.js --- Code.js | 54 ++++++++++++++++++++++++++------------------- testing2.json | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ testing3.json | 35 +++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 23 deletions(-) create mode 100644 testing2.json create mode 100644 testing3.json diff --git a/Code.js b/Code.js index 986fba6..4a54784 100644 --- a/Code.js +++ b/Code.js @@ -3,8 +3,9 @@ // See restrictions at http://www.opensource.org/licenses/gpl-3.0.html -var headers = ['etag', 'Org Unit Path', 'Serial Number', 'Platform Version', 'Device Id', 'Status', 'Last Enrollment Time', - 'Firmware Version', 'Last Sync', 'OS Version', 'Boot Mode', 'Annotated Location', 'Notes', 'Annotated User', 'Mac Address', '']; +// var headers = ['etag', 'Annotated Asset ID', 'Manufacture Date', 'Org Unit Path', 'Serial Number', 'Platform Version', 'Device Id','Status', 'Last Enrollment Time', 'Firmware Version', 'Last Sync', 'OS Version', 'Boot Mode', 'Annotated Location', 'Notes', 'Annotated User', 'Mac Address', '']; + +var headers = ['Org Unit Path', 'Annotated User', 'Annotated Location', 'Annotated Asset ID', 'Notes', 'Mac Address', 'Ethernet Mac Address', 'etag', 'Platform Version', 'Device ID', 'Serial Number', 'Status', 'Last Enrollment', 'Recent Users', 'Active Time', 'Model Firmware Version', 'Last Sync', 'OS Version', 'Boot Mode', 'Support End Date']; function myFunction() { @@ -50,8 +51,8 @@ function menuItem4() { // .alert('You clicked the second menu item!'); // moveColumns(); testingListChomeDevices(); - setHeader(); - filterSheet(); + // setHeader(); + // filterSheet(); } function menuItem5() { @@ -211,6 +212,8 @@ function testingListChomeDevices() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var allDevices = []; + var deviceKey = []; + var deviceValue = []; var maxRow = sheet.getMaxRows(); var maxColumn = sheet.getMaxColumns(); sheet.clearContents(); @@ -218,29 +221,34 @@ function testingListChomeDevices() { clearSheet(); } SpreadsheetApp.flush(); + var response = AdminDirectory.Chromeosdevices.list('my_customer', { maxResults: 100, projection: "FULL" }); + allDevices = allDevices.concat(response.chromeosdevices); + // Logger.log("Response: " + response); + // response.chromeosdevices.forEach(element => Browser.msgBox(element)); + // allDevices.forEach(element => Browser.msgBox(element)); + // https://www.freecodecamp.org/news/javascript-foreach-how-to-loop-through-an-array-in-js/ + // allDevices.forEach(function () { + // // code + + // }); + // allDevices.forEach(element => { + // Browser.msgBox(element.count); + // }); + + + // https://zetcode.com/javascript/jsonforeach/ + // allDevices.forEach(obj => { + // Object.entries(obj).forEach(([key, value]) => { + // deviceKey.push(key) + // deviceValue.push(value) + // console.log(`${key} ${value}`); + // }); + // console.log('-------------------'); + // }); sheet.getRange(1, 1, 1, headers.length).setValues([headers]); - sheet.autoResizeColumn(headers.length); - SpreadsheetApp.flush(); - - var response = AdminDirectory.Chromeosdevices.list('my_customer', { maxResults: 1, projection: "FULL" }); - Logger.log("Response: " + response); - Logger.log("Response Chrome Devices: " + response.chromeosdevices); - // allDevices = allDevices.concat(response.chromeosdevices); - allDevices.push(...response.chromeosdevices.pop()); setRowsData(sheet, allDevices); - // while (response.nextPageToken) { - // response = AdminDirectory.Chromeosdevices.list('my_customer', { maxResults: 100, projection: "FULL", pageToken: response.nextPageToken }); - // // allDevices = allDevices.concat(response.chromeosdevices); - // allDevices.push(...response.chromeosdevices); - // } - if (allDevices.length > 0) { - if (allDevices.length > maxRow) { - sheet.insertRows(maxRow, (allDevices.length - maxRow)); - } - setRowsData(sheet, allDevices); - } SpreadsheetApp.flush(); } catch (err) { Browser.msgBox("Error: " + err.message); diff --git a/testing2.json b/testing2.json new file mode 100644 index 0000000..a82aac1 --- /dev/null +++ b/testing2.json @@ -0,0 +1,61 @@ +{ + "serialNumber":"F0TK393", + "osVersion":"85.0.4183.84", + "annotatedUser":"gadmin4th@greensburg.k12.in.us", + "macAddress":"dc41a992ba26", + "status":"ACTIVE", + "firmwareVersion":"Google_Fleex.11297.141.0", + "lastSync":"2021-01-25T19:15:56.586Z", + "lastEnrollmentTime":"2021-01-25T18:05:14.392Z", + "manufactureDate":"2020-12-11", + "etag":"\"ajuIDY2MlKKzrdUn942df2OCBNkpUIbNakI8lMkbmjA/FRfJivzNeYMenB01rPOqQADu5vA\"", + "autoUpdateExpiration":"1780297200000", + "orgUnitPath":"/Elementary Students/ElementaryChrome/4thGradeChrome", + "bootMode":"Verified", + "systemRamFreeReports":[ + {"reportTime":"2021-01-25T18:05:27.296Z", + "systemRamFreeInfo":["2581913600"]} + ], + "systemRamTotal":"3990949888", + "diskVolumeReports":[ + {"volumeInfo":[ + {"storageFree":"1995472896", + "storageTotal":"1995472896", + "volumeId":"/media/archive"}, + {"storageFree":"11681792", + "storageTotal":"12042240", + "volumeId":"/usr/share/oem"}, + {"storageFree":"1995472896", + "storageTotal":"1995472896", + "volumeId":"/media/removable"} + ]}], + "kind":"admin#directory#chromeosdevice", + "cpuStatusReports":[ + {"reportTime":"2021-01-25T18:05:27.296Z", + "cpuUtilizationPercentageInfo":[24]}, + {"reportTime":"2021-01-25T18:06:27.267Z", + "cpuTemperatureInfo":[ + {"label":"Core 1", + "temperature":37}, + {"temperature":37, + "label":"Package id 0"}, + {"temperature":37, + "label":"Core 0"}, + {"label":"iwlwifi_1", + "temperature":29} + ]}], + "deviceId":"bf9b0a6d-be3e-4710-a921-98c24558c20e", + "model":"Dell Chromebook 3100", + "activeTimeRanges":[ + {"date":"2021-01-25", + "activeTime":60000} + ], + "platformVersion":"13310.59.0 (Official Build) stable-channel octopus", + "tpmVersionInfo":{ + "specLevel":"74", + "tpmModel":"1", + "manufacturer":"43524f53", + "vendorSpecific":"784347206654504D", + "firmwareVersion":"7921eab30ee34b3e", + "family":"322e3000"} +} \ No newline at end of file diff --git a/testing3.json b/testing3.json new file mode 100644 index 0000000..128fa5d --- /dev/null +++ b/testing3.json @@ -0,0 +1,35 @@ +{ + manufactureDate=2020-12-11, + diskVolumeReports=[ + Ljava.lang.Object;@1db584d9, + macAddress=dc41a992ba26, + tpmVersionInfo={ + manufacturer=43524f53, + specLevel=74, + tpmModel=1, + family=322e3000, + firmwareVersion=7921eab30ee34b3e, + vendorSpecific=784347206654504D}, + autoUpdateExpiration=1780297200000, + lastSync=2021-01-25T19:15:56.586Z, + etag="ajuIDY2MlKKzrdUn942df2OCBNkpUIbNakI8lMkbmjA/FRfJivzNeYMenB01rPOqQADu5vA", + cpuStatusReports=[ + Ljava.lang.Object;@53e00a99, + platformVersion=13310.59.0 (Official Build) stable-channel octopus, + systemRamFreeReports=[ + Ljava.lang.Object;@336abaf2, + osVersion=85.0.4183.84, + status=ACTIVE, + orgUnitPath=/Elementary Students/ElementaryChrome/4thGradeChrome, + activeTimeRanges=[ + Ljava.lang.Object;@64ce4361, + model=Dell Chromebook 3100, + deviceId=bf9b0a6d-be3e-4710-a921-98c24558c20e, + kind=admin#directory#chromeosdevice, + annotatedUser=gadmin4th@greensburg.k12.in.us, + systemRamTotal=3990949888, + serialNumber=F0TK393, + lastEnrollmentTime=2021-01-25T18:05:14.392Z, + firmwareVersion=Google_Fleex.11297.141.0, + bootMode=Verified +} \ No newline at end of file