baseboard() added memMax, memSlots
This commit is contained in:
parent
f09915f1f5
commit
c21a6e1f4f
@ -13,11 +13,13 @@
|
|||||||
// 3. Operating System
|
// 3. Operating System
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
const os = require('os');
|
const nodeUtil = require('util');
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
|
const execSync = require('child_process').execSync;
|
||||||
|
const execPromise = nodeUtil.promisify(require('child_process').exec);
|
||||||
|
const os = require('os');
|
||||||
const util = require('./util');
|
const util = require('./util');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { execSync } = require('child_process');
|
|
||||||
|
|
||||||
let _platform = process.platform;
|
let _platform = process.platform;
|
||||||
|
|
||||||
@ -320,19 +322,20 @@ function osInfo(callback) {
|
|||||||
result.logofile = getLogoFile();
|
result.logofile = getLogoFile();
|
||||||
result.release = result.kernel;
|
result.release = result.kernel;
|
||||||
try {
|
try {
|
||||||
util.wmic('os get /value').then((stdout) => {
|
const workload = [];
|
||||||
let lines = stdout.toString().split('\r\n');
|
workload.push(util.wmic('os get /value'));
|
||||||
|
workload.push(execPromise('systeminfo'));
|
||||||
|
util.promiseAll(
|
||||||
|
workload
|
||||||
|
).then(data => {
|
||||||
|
let lines = data.results[0].toString().split('\r\n');
|
||||||
result.distro = util.getValue(lines, 'Caption', '=').trim();
|
result.distro = util.getValue(lines, 'Caption', '=').trim();
|
||||||
result.serial = util.getValue(lines, 'SerialNumber', '=').trim();
|
result.serial = util.getValue(lines, 'SerialNumber', '=').trim();
|
||||||
result.build = util.getValue(lines, 'BuildNumber', '=').trim();
|
result.build = util.getValue(lines, 'BuildNumber', '=').trim();
|
||||||
result.servicepack = util.getValue(lines, 'ServicePackMajorVersion', '=').trim() + '.' + util.getValue(lines, 'ServicePackMinorVersion', '=').trim();
|
result.servicepack = util.getValue(lines, 'ServicePackMajorVersion', '=').trim() + '.' + util.getValue(lines, 'ServicePackMinorVersion', '=').trim();
|
||||||
result.codepage = util.getCodepage();
|
result.codepage = util.getCodepage();
|
||||||
try {
|
const systeminfo = data.results[1].stdout.toString();
|
||||||
const systeminfo = execSync('systeminfo').toString();
|
|
||||||
result.hypervisor = (systeminfo.indexOf('hypervisor has been detected') !== -1) || (systeminfo.indexOf('Es wurde ein Hypervisor erkannt') !== -1) || (systeminfo.indexOf('Un hyperviseur a ') !== -1);
|
result.hypervisor = (systeminfo.indexOf('hypervisor has been detected') !== -1) || (systeminfo.indexOf('Es wurde ein Hypervisor erkannt') !== -1) || (systeminfo.indexOf('Un hyperviseur a ') !== -1);
|
||||||
} catch (e) {
|
|
||||||
util.noop();
|
|
||||||
}
|
|
||||||
isUefiWindows().then(uefi => {
|
isUefiWindows().then(uefi => {
|
||||||
result.uefi = uefi;
|
result.uefi = uefi;
|
||||||
if (callback) {
|
if (callback) {
|
||||||
|
|||||||
@ -13,8 +13,10 @@
|
|||||||
// 2. System (Hardware, BIOS, Base Board)
|
// 2. System (Hardware, BIOS, Base Board)
|
||||||
// ----------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const nodeUtil = require('util');
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
const execSync = require('child_process').execSync;
|
const execSync = require('child_process').execSync;
|
||||||
|
const execPromise = nodeUtil.promisify(require('child_process').exec);
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const util = require('./util');
|
const util = require('./util');
|
||||||
@ -566,6 +568,8 @@ function baseboard(callback) {
|
|||||||
version: '',
|
version: '',
|
||||||
serial: '-',
|
serial: '-',
|
||||||
assetTag: '-',
|
assetTag: '-',
|
||||||
|
memMax: null,
|
||||||
|
memSlots: null
|
||||||
};
|
};
|
||||||
let cmd = '';
|
let cmd = '';
|
||||||
if (_linux || _freebsd || _openbsd || _netbsd) {
|
if (_linux || _freebsd || _openbsd || _netbsd) {
|
||||||
@ -575,8 +579,13 @@ function baseboard(callback) {
|
|||||||
} else {
|
} else {
|
||||||
cmd = 'export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL';
|
cmd = 'export LC_ALL=C; dmidecode -t 2 2>/dev/null; unset LC_ALL';
|
||||||
}
|
}
|
||||||
exec(cmd, function (error, stdout) {
|
const workload = [];
|
||||||
let lines = stdout.toString().split('\n');
|
workload.push(execPromise(cmd));
|
||||||
|
workload.push(execPromise('export LC_ALL=C; dmidecode -t memory 2>/dev/null'));
|
||||||
|
util.promiseAll(
|
||||||
|
workload
|
||||||
|
).then(data => {
|
||||||
|
let lines = data.results[0].stdout.toString().split('\n');
|
||||||
result.manufacturer = util.getValue(lines, 'Manufacturer');
|
result.manufacturer = util.getValue(lines, 'Manufacturer');
|
||||||
result.model = util.getValue(lines, 'Product Name');
|
result.model = util.getValue(lines, 'Product Name');
|
||||||
result.version = util.getValue(lines, 'Version');
|
result.version = util.getValue(lines, 'Version');
|
||||||
@ -601,19 +610,53 @@ function baseboard(callback) {
|
|||||||
if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; }
|
if (result.serial.toLowerCase().indexOf('o.e.m.') !== -1) { result.serial = '-'; }
|
||||||
if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) { result.assetTag = '-'; }
|
if (result.assetTag.toLowerCase().indexOf('o.e.m.') !== -1) { result.assetTag = '-'; }
|
||||||
|
|
||||||
|
// mem
|
||||||
|
lines = data.results[1].stdout.toString().split('\n');
|
||||||
|
result.memMax = util.toInt(util.getValue(lines, 'Maximum Capacity')) * 1024 * 1024 * 1024 || null;
|
||||||
|
result.memSlots = util.toInt(util.getValue(lines, 'Number Of Devices')) || null;
|
||||||
|
|
||||||
|
// raspberry
|
||||||
|
const linesRpi = fs.readFileSync('/proc/cpuinfo').toString().split('\n');
|
||||||
|
const hardware = util.getValue(linesRpi, 'hardware');
|
||||||
|
if (hardware.startsWith('BCM')) {
|
||||||
|
const rpi = util.decodePiCpuinfo(linesRpi);
|
||||||
|
result.manufacturer = rpi.manufacturer;
|
||||||
|
result.model = 'Raspberry Pi';
|
||||||
|
result.serial = rpi.serial;
|
||||||
|
result.version = rpi.type + ' - ' + rpi.revision;
|
||||||
|
result.memMax = os.totalmem();
|
||||||
|
result.memSlots = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (_darwin) {
|
if (_darwin) {
|
||||||
exec('ioreg -c IOPlatformExpertDevice -d 2', function (error, stdout) {
|
const workload = [];
|
||||||
if (!error) {
|
workload.push(execPromise('ioreg -c IOPlatformExpertDevice -d 2'));
|
||||||
let lines = stdout.toString().replace(/[<>"]/g, '').split('\n');
|
workload.push(execPromise('system_profiler SPMemoryDataType'));
|
||||||
|
util.promiseAll(
|
||||||
|
workload
|
||||||
|
).then(data => {
|
||||||
|
let lines = data.results[0].stdout.toString().replace(/[<>"]/g, '').split('\n');
|
||||||
result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
|
result.manufacturer = util.getValue(lines, 'manufacturer', '=', true);
|
||||||
result.model = util.getValue(lines, 'model', '=', true);
|
result.model = util.getValue(lines, 'model', '=', true);
|
||||||
result.version = util.getValue(lines, 'version', '=', true);
|
result.version = util.getValue(lines, 'version', '=', true);
|
||||||
result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
|
result.serial = util.getValue(lines, 'ioplatformserialnumber', '=', true);
|
||||||
result.assetTag = util.getValue(lines, 'board-id', '=', true);
|
result.assetTag = util.getValue(lines, 'board-id', '=', true);
|
||||||
|
|
||||||
|
// mem
|
||||||
|
let devices = data.results[1].stdout.toString().split(' BANK ');
|
||||||
|
if (devices.length === 1) {
|
||||||
|
devices = data.results[1].stdout.toString().split(' DIMM');
|
||||||
|
}
|
||||||
|
devices.shift();
|
||||||
|
result.memSlots = devices.length;
|
||||||
|
|
||||||
|
if (os.arch() === 'arm64') {
|
||||||
|
result.memSlots = 0;
|
||||||
|
result.memMax = os.totalmem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
@ -626,9 +669,13 @@ function baseboard(callback) {
|
|||||||
}
|
}
|
||||||
if (_windows) {
|
if (_windows) {
|
||||||
try {
|
try {
|
||||||
util.wmic('baseboard get /value').then((stdout, error) => {
|
const workload = [];
|
||||||
if (!error) {
|
workload.push(util.wmic('baseboard get /value'));
|
||||||
let lines = stdout.toString().split('\r\n');
|
workload.push(util.wmic('memphysical get MaxCapacity, MemoryDevices /value'));
|
||||||
|
util.promiseAll(
|
||||||
|
workload
|
||||||
|
).then(data => {
|
||||||
|
let lines = data.results[0].toString().split('\r\n');
|
||||||
|
|
||||||
result.manufacturer = util.getValue(lines, 'manufacturer', '=');
|
result.manufacturer = util.getValue(lines, 'manufacturer', '=');
|
||||||
result.model = util.getValue(lines, 'model', '=');
|
result.model = util.getValue(lines, 'model', '=');
|
||||||
@ -641,7 +688,11 @@ function baseboard(callback) {
|
|||||||
if (!result.assetTag) {
|
if (!result.assetTag) {
|
||||||
result.assetTag = util.getValue(lines, 'sku', '=');
|
result.assetTag = util.getValue(lines, 'sku', '=');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// memphysical
|
||||||
|
lines = data.results[1].toString().split('\r\n');
|
||||||
|
result.memMax = util.toInt(util.getValue(lines, 'MaxCapacity', '=')) || null;
|
||||||
|
result.memSlots = util.toInt(util.getValue(lines, 'MemoryDevices', '=')) || null;
|
||||||
|
|
||||||
if (callback) { callback(result); }
|
if (callback) { callback(result); }
|
||||||
resolve(result);
|
resolve(result);
|
||||||
|
|||||||
40
lib/util.js
40
lib/util.js
@ -832,6 +832,45 @@ function decodePiCpuinfo(lines) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function promiseAll(promises) {
|
||||||
|
const resolvingPromises = promises.map(function (promise) {
|
||||||
|
return new Promise(function (resolve) {
|
||||||
|
var payload = new Array(2);
|
||||||
|
promise.then(function (result) {
|
||||||
|
payload[0] = result;
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
payload[1] = error;
|
||||||
|
})
|
||||||
|
.then(function () {
|
||||||
|
// The wrapped Promise returns an array: 0 = result, 1 = error ... we resolve all
|
||||||
|
resolve(payload);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var errors = [];
|
||||||
|
var results = [];
|
||||||
|
|
||||||
|
// Execute all wrapped Promises
|
||||||
|
return Promise.all(resolvingPromises)
|
||||||
|
.then(function (items) {
|
||||||
|
items.forEach(function (payload) {
|
||||||
|
if (payload[1]) {
|
||||||
|
errors.push(payload[1]);
|
||||||
|
results.push(null);
|
||||||
|
} else {
|
||||||
|
errors.push(null);
|
||||||
|
results.push(payload[0]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
errors: errors,
|
||||||
|
results: results
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function noop() { }
|
function noop() { }
|
||||||
|
|
||||||
exports.toInt = toInt;
|
exports.toInt = toInt;
|
||||||
@ -861,6 +900,7 @@ exports.isRaspbian = isRaspbian;
|
|||||||
exports.sanitizeShellString = sanitizeShellString;
|
exports.sanitizeShellString = sanitizeShellString;
|
||||||
exports.isPrototypePolluted = isPrototypePolluted;
|
exports.isPrototypePolluted = isPrototypePolluted;
|
||||||
exports.decodePiCpuinfo = decodePiCpuinfo;
|
exports.decodePiCpuinfo = decodePiCpuinfo;
|
||||||
|
exports.promiseAll = promiseAll;
|
||||||
exports.stringReplace = stringReplace;
|
exports.stringReplace = stringReplace;
|
||||||
exports.stringToLower = stringToLower;
|
exports.stringToLower = stringToLower;
|
||||||
exports.stringToString = stringToString;
|
exports.stringToString = stringToString;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user