🐈
bundleから端末リストを取得
はじめに
OSが古い人を通知するためにbundleから端末リスト(PC, スマホ)を取得してスプレッドシートに全部貼る。
なお、bundleはLANSCOPEやintuneなど、複数のMDMから端末情報をインポートすることができ便利。端末のマスタを用意していない場合は、bundleをそのまま端末マスタにしてもいい。
というより写真がアップロードできるのでbundleを使いたいが、PC故障のワークフローやPC契約マスタと既存の端末マスタが紐づいているので断念している。
code
bundle.js
const TOKEN = PropertiesService.getScriptProperties().getProperty('token');
const URL_API = 'https://xxxxxxxxxxxxxxx.bundle.jp/api/v1';
function fetchBundle(query){
const options = {
'method': 'POST',
'payload': JSON.stringify({query: query}),
'headers': {
'content-type': 'application/json',
'Accept': 'application/json',
'Authorization': `Bearer ${TOKEN}`,
},
muteHttpExceptions:true,
};
const res = UrlFetchApp.fetch(URL_API, options);
return JSON.parse(res).data.team;
}
function getAssetList() {
let assetList = [];
let cursor = '';
let json = {};
do{
const query = `
{
team {
assets(first:100, after:"${cursor}"){
pageInfo {
endCursor
hasNextPage
},
nodes{
serialNumber,
assetCategory{
name
}
assetAttributeValues{
... on AssetAttributeValueString {
stringValue
}
assetAttribute{
name,
id
}
}
}
}
}
}
`;
json = fetchBundle(query);
assetList = assetList.concat(json.assets.nodes.map(json => new Asset(json)));
cursor = json.assets.pageInfo.endCursor;
Utilities.sleep(1 * 1000);
}while (json.assets.pageInfo.hasNextPage);
return assetList;
}
Asset.js
class Asset {
constructor(json) {
this.serialNumber = json.serialNumber;
const isLanscope = json.assetCategory.name.includes('LANSCOPE');
const getAttributeValue = name => json.assetAttributeValues.find(attr => attr.assetAttribute.name === name).stringValue;
this.type = getAttributeValue(isLanscope ? 'LANSCOPE_OSタイプ' : 'INTUNE_OS');
this.osVersion = getAttributeValue(isLanscope ? 'LANSCOPE_OSバージョン' : 'INTUNE_OSバージョン');
}
getOutList() {
return [
this.serialNumber,
this.type,
this.osVersion
];
}
}
結果
後はここからバージョンが古い人を通知していく。
bundleで利用者と紐づけている人は追加で利用者をとってもいいかも。
Discussion