Skip to content

Commit

Permalink
chassis(), baseboard() parsing improvements (windows)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Sep 15, 2023
1 parent 9e10a90 commit 26f2b14
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions lib/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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); }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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); }
Expand Down

0 comments on commit 26f2b14

Please sign in to comment.