From 26f2b140ff456384d563ad5c6cad9b4b33ce0cc8 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Fri, 15 Sep 2023 03:53:51 -0700 Subject: [PATCH] chassis(), baseboard() parsing improvements (windows) --- lib/system.js | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/lib/system.js b/lib/system.js index 5c2a6b0f..d8f897d0 100644 --- a/lib/system.js +++ b/lib/system.js @@ -317,6 +317,12 @@ function system(callback) { exports.system = system; +function cleanDefaults(s) { + if (s === 'Default string') { s = ''; } + if (s.toLowerCase().indexOf('o.e.m.') !== -1) { s = ''; } + + return s +} function bios(callback) { return new Promise((resolve) => { @@ -418,7 +424,7 @@ function bios(callback) { } result.releaseDate = util.getValue(lines, 'releasedate', ':'); result.revision = util.getValue(lines, 'buildnumber', ':'); - result.serial = util.getValue(lines, 'serialnumber', ':'); + result.serial = cleanDefaults(util.getValue(lines, 'serialnumber', ':')); } if (callback) { callback(result); } @@ -555,23 +561,26 @@ function baseboard(callback) { const workload = []; const win10plus = parseInt(os.release()) >= 10; const maxCapacityAttribute = win10plus ? 'MaxCapacityEx' : 'MaxCapacity'; - workload.push(util.powerShell('Get-CimInstance Win32_baseboard | select Model,Manufacturer,Product,Version,SerialNumber,PartNumber,SKU | fl')); + workload.push(util.powerShell('Get-CimInstance Win32_baseboard | select Model,Manufacturer,Product,Version,SerialNumber,PartNumber,SKU,SMBIOSAssetTag | fl')); workload.push(util.powerShell(`Get-CimInstance Win32_physicalmemoryarray | select ${maxCapacityAttribute}, MemoryDevices | fl`)); util.promiseAll( workload ).then((data) => { let lines = data.results[0] ? data.results[0].toString().split('\r\n') : ['']; - result.manufacturer = util.getValue(lines, 'manufacturer', ':'); - result.model = util.getValue(lines, 'model', ':'); + result.manufacturer = cleanDefaults(util.getValue(lines, 'manufacturer', ':')); + result.model = cleanDefaults(util.getValue(lines, 'model', ':')); if (!result.model) { - result.model = util.getValue(lines, 'product', ':'); + result.model = cleanDefaults(util.getValue(lines, 'product', ':')); + } + result.version = cleanDefaults(util.getValue(lines, 'version', ':')); + result.serial = cleanDefaults(util.getValue(lines, 'serialnumber', ':')); + result.assetTag = cleanDefaults(util.getValue(lines, 'partnumber', ':')); + if (!result.assetTag) { + result.assetTag = cleanDefaults(util.getValue(lines, 'sku', ':')); } - result.version = util.getValue(lines, 'version', ':'); - result.serial = util.getValue(lines, 'serialnumber', ':'); - result.assetTag = util.getValue(lines, 'partnumber', ':'); if (!result.assetTag) { - result.assetTag = util.getValue(lines, 'sku', ':'); + result.assetTag = cleanDefaults(util.getValue(lines, 'SMBIOSAssetTag', ':')); } // memphysical @@ -688,22 +697,21 @@ function chassis(callback) { } if (_windows) { try { - util.powerShell('Get-CimInstance Win32_SystemEnclosure | select Model,Manufacturer,ChassisTypes,Version,SerialNumber,PartNumber,SKU | fl').then((stdout, error) => { + util.powerShell('Get-CimInstance Win32_SystemEnclosure | select Model,Manufacturer,ChassisTypes,Version,SerialNumber,PartNumber,SKU,SMBIOSAssetTag | fl').then((stdout, error) => { if (!error) { let lines = stdout.toString().split('\r\n'); - result.manufacturer = util.getValue(lines, 'manufacturer', ':'); - result.model = util.getValue(lines, 'model', ':'); + result.manufacturer = cleanDefaults(util.getValue(lines, 'manufacturer', ':')); + result.model = cleanDefaults(util.getValue(lines, 'model', ':')); const ctype = parseInt(util.getValue(lines, 'ChassisTypes', ':').replace(/\D/g, '')); result.type = (ctype && !isNaN(ctype) && ctype < chassisTypes.length) ? chassisTypes[ctype - 1] : ''; - result.version = util.getValue(lines, 'version', ':'); - result.serial = util.getValue(lines, 'serialnumber', ':'); - result.assetTag = util.getValue(lines, 'partnumber', ':'); - result.sku = util.getValue(lines, 'sku', ':'); - if (result.manufacturer.toLowerCase().indexOf('o.e.m.') !== -1) { result.manufacturer = '-'; } - if (result.version.toLowerCase().indexOf('o.e.m.') !== -1) { result.version = '-'; } - if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; } - if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) { result.assetTag = '-'; } + result.version = cleanDefaults(util.getValue(lines, 'version', ':')); + result.serial = cleanDefaults(util.getValue(lines, 'serialnumber', ':')); + result.assetTag = cleanDefaults(util.getValue(lines, 'partnumber', ':')); + if (!result.assetTag) { + result.assetTag = cleanDefaults(util.getValue(lines, 'SMBIOSAssetTag', ':')); + } + result.sku = cleanDefaults(util.getValue(lines, 'sku', ':')); } if (callback) { callback(result); }