added system uuid() (os specific), versions() added postgresql

This commit is contained in:
Sebastian Hildebrandt 2018-11-18 15:36:28 +01:00
parent 98bc6a401e
commit 831c50d8c9
7 changed files with 108 additions and 21 deletions

View File

@ -100,6 +100,7 @@ Other changes
| Version | Date | Comment | | Version | Date | Comment |
| -------------- | -------------- | -------- | | -------------- | -------------- | -------- |
| 3.49.0 | 2018-11-19 | added system `uuid()` (os specific), `versions()` added postgresql |
| 3.48.4 | 2018-11-18 | windows: garbled output because of codepage | | 3.48.4 | 2018-11-18 | windows: garbled output because of codepage |
| 3.48.3 | 2018-11-18 | `dockerContainerStats()` fixed issue `cpu_percent` win | | 3.48.3 | 2018-11-18 | `dockerContainerStats()` fixed issue `cpu_percent` win |
| 3.48.2 | 2018-11-18 | `dockerContainerStats()` fixed issue `cpu_percent`, win exec | | 3.48.2 | 2018-11-18 | `dockerContainerStats()` fixed issue `cpu_percent`, win exec |

View File

@ -243,6 +243,8 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (
| | logofile | X | X | X | X | X | e.g. 'apple', 'debian', 'fedora', ... | | | logofile | X | X | X | X | X | e.g. 'apple', 'debian', 'fedora', ... |
| | serial | | X | X | X | | OS/Host serial number | | | serial | | X | X | X | | OS/Host serial number |
| | build | | | X | X | | OS build version | | | build | | | X | X | | OS build version |
| | codepage | X | X | X | X | | OS build version |
| si.uuid(cb) | : string | X | X | X | X| | device ID (based on OS install) |
| si.versions(cb) | {...} | X | X | X | X | X | version information (kernel, ssl, node, ...) | | si.versions(cb) | {...} | X | X | X | X | X | version information (kernel, ssl, node, ...) |
| si.shell(cb) | : string | X | X | X | | | standard shell | | si.shell(cb) | : string | X | X | X | | | standard shell |
| si.users(cb) | [{...}] | X | X | X | X | X | array of users online | | si.users(cb) | [{...}] | X | X | X | X | X | array of users online |

View File

@ -260,7 +260,7 @@ function blockDevices(callback) {
if (_windows) { if (_windows) {
let drivetypes = ['Unknown', 'NoRoot', 'Removable', 'Local', 'Network', 'CD/DVD', 'RAM']; let drivetypes = ['Unknown', 'NoRoot', 'Removable', 'Local', 'Network', 'CD/DVD', 'RAM'];
try { try {
exec(util.getWmic() + ' logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value', util.execOptsWin, function (error, stdout) { util.execWin(util.getWmic() + ' logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value', util.execOptsWin, function (error, stdout) {
if (!error) { if (!error) {
let devices = stdout.toString().split(/\n\s*\n/); let devices = stdout.toString().split(/\n\s*\n/);
devices.forEach(function (device) { devices.forEach(function (device) {

View File

@ -335,11 +335,11 @@ function graphics(callback) {
if (_windows) { if (_windows) {
// https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/ // https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/
try { try {
exec(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', util.execOptsWin, function (error, stdout) { util.execWin(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', util.execOptsWin, function (error, stdout) {
if (!error) { if (!error) {
let csections = stdout.split(/\n\s*\n/); let csections = stdout.split(/\n\s*\n/);
result.controllers = parseLinesWindowsControllers(csections); result.controllers = parseLinesWindowsControllers(csections);
exec(util.getWmic() + ' path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value', util.execOptsWin, function (error, stdout) { util.execWin(util.getWmic() + ' path win32_desktopmonitor get Caption, MonitorManufacturer, MonitorType, ScreenWidth, ScreenHeight /value', util.execOptsWin, function (error, stdout) {
let dsections = stdout.split(/\n\s*\n/); let dsections = stdout.split(/\n\s*\n/);
if (!error) { if (!error) {
result.displays = parseLinesWindowsDisplays(dsections); result.displays = parseLinesWindowsDisplays(dsections);

View File

@ -46,7 +46,7 @@ const _sunos = (_platform === 'sunos');
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
if (_windows) { if (_windows) {
util.getWinCodepage(); util.getCodepage();
} }
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
@ -78,6 +78,7 @@ function getStaticData(callback) {
system.bios(), system.bios(),
system.baseboard(), system.baseboard(),
osInfo.osInfo(), osInfo.osInfo(),
osInfo.uuid(),
osInfo.versions(), osInfo.versions(),
cpu.cpu(), cpu.cpu(),
cpu.cpuFlags(), cpu.cpuFlags(),
@ -90,13 +91,14 @@ function getStaticData(callback) {
data.bios = res[1]; data.bios = res[1];
data.baseboard = res[2]; data.baseboard = res[2];
data.os = res[3]; data.os = res[3];
data.versions = res[4]; data.uuid = res[4];
data.cpu = res[5]; data.versions = res[5];
data.cpu.flags = res[6]; data.cpu = res[6];
data.graphics = res[7]; data.cpu.flags = res[7];
data.net = res[8]; data.graphics = res[8];
data.memLayout = res[9]; data.net = res[9];
data.diskLayout = res[10]; data.memLayout = res[10];
data.diskLayout = res[11];
if (callback) { callback(data); } if (callback) { callback(data); }
resolve(data); resolve(data);
}); });
@ -312,6 +314,7 @@ exports.time = osInfo.time;
exports.osInfo = osInfo.osInfo; exports.osInfo = osInfo.osInfo;
exports.versions = osInfo.versions; exports.versions = osInfo.versions;
exports.shell = osInfo.shell; exports.shell = osInfo.shell;
exports.uuid = osInfo.uuid;
exports.cpu = cpu.cpu; exports.cpu = cpu.cpu;
exports.cpuFlags = cpu.cpuFlags; exports.cpuFlags = cpu.cpuFlags;

View File

@ -169,6 +169,7 @@ function osInfo(callback) {
kernel: os.release(), kernel: os.release(),
arch: os.arch(), arch: os.arch(),
hostname: os.hostname(), hostname: os.hostname(),
codepage: '',
logofile: '', logofile: '',
serial: '', serial: '',
build: '' build: ''
@ -197,6 +198,7 @@ function osInfo(callback) {
result.logofile = getLogoFile(result.distro); result.logofile = getLogoFile(result.distro);
result.release = (release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, ''); result.release = (release.DISTRIB_RELEASE || release.VERSION_ID || 'unknown').replace(/"/g, '');
result.codename = (release.DISTRIB_CODENAME || '').replace(/"/g, ''); result.codename = (release.DISTRIB_CODENAME || '').replace(/"/g, '');
result.codepage = util.getCodepage();
//} //}
if (callback) { if (callback) {
callback(result); callback(result);
@ -214,6 +216,7 @@ function osInfo(callback) {
result.release = util.getValue(lines, 'kern.osrelease').split('-')[0]; result.release = util.getValue(lines, 'kern.osrelease').split('-')[0];
result.serial = util.getValue(lines, 'kern.uuid'); result.serial = util.getValue(lines, 'kern.uuid');
result.codename = ''; result.codename = '';
result.codepage = util.getCodepage();
} }
if (callback) { if (callback) {
callback(result); callback(result);
@ -229,6 +232,7 @@ function osInfo(callback) {
result.release = util.getValue(lines, 'ProductVersion'); result.release = util.getValue(lines, 'ProductVersion');
result.build = util.getValue(lines, 'BuildVersion'); result.build = util.getValue(lines, 'BuildVersion');
result.logofile = getLogoFile(result.distro); result.logofile = getLogoFile(result.distro);
result.codepage = util.getCodepage();
if (callback) { if (callback) {
callback(result); callback(result);
} }
@ -254,6 +258,7 @@ function osInfo(callback) {
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.codepage = util.getCodepage();
if (callback) { if (callback) {
callback(result); callback(result);
} }
@ -495,3 +500,61 @@ function shell(callback) {
} }
exports.shell = shell; exports.shell = shell;
function uuid(callback) {
return new Promise((resolve) => {
process.nextTick(() => {
let result = '';
let parts;
if (_darwin) {
exec('ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformUUID', function (error, stdout) {
if (!error) {
parts = stdout.toString().split('\n')[0].replace(/"/g, '').split('=');
result = parts.length > 1 ? parts[1].trim().toLowerCase() : '';
}
if (callback) {
callback(result);
}
resolve(result);
});
}
if (_linux) {
exec('( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :', function (error, stdout) {
if (!error) {
result = stdout.toString().split('\n')[0].trim().toLowerCase();
}
if (callback) {
callback(result);
}
resolve(result);
});
}
if (_freebsd || _openbsd) {
exec('kenv -q smbios.system.uuid', function (error, stdout) {
if (!error) {
result = stdout.toString().split('\n')[0].trim().toLowerCase();
}
if (callback) {
callback(result);
}
resolve(result);
});
}
if (_windows) {
exec('%windir%\\System32\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid', util.execOptsWin, function (error, stdout) {
if (!error) {
result = stdout.toString().split('\n')[0].split('REG_SZ')[1].replace(/\r+|\n+|\s+/ig, '').toLowerCase();
}
if (callback) {
callback(result);
}
resolve(result);
});
}
});
});
}
exports.uuid = uuid;

View File

@ -19,11 +19,16 @@ const exec = require('child_process').exec;
const execSync = require('child_process').execSync; const execSync = require('child_process').execSync;
let _platform = process.platform; let _platform = process.platform;
const _linux = (_platform === 'linux');
const _darwin = (_platform === 'darwin');
const _windows = (_platform === 'win32'); const _windows = (_platform === 'win32');
const _freebsd = (_platform === 'freebsd');
const _openbsd = (_platform === 'openbsd');
// const _sunos = (_platform === 'sunos');
let _cores = 0; let _cores = 0;
let wmic = ''; let wmic = '';
let codepageWin = ''; let codepage = '';
const execOptsWin = { const execOptsWin = {
windowsHide: true, windowsHide: true,
@ -182,19 +187,32 @@ function powerShell(cmd) {
}); });
} }
function getWinCodepage() { function getCodepage() {
if (_windows) { if (_windows) {
if (!codepageWin) { if (!codepage) {
try { try {
const stdout = execSync('chcp'); const stdout = execSync('chcp');
const lines = stdout.toString().split('\r\n'); const lines = stdout.toString().split('\r\n');
const parts = lines[0].split(':'); const parts = lines[0].split(':');
codepageWin = parts.length > 1 ? parts[1].replace('.', '') : ''; codepage = parts.length > 1 ? parts[1].replace('.', '') : '';
} catch (err) { } catch (err) {
codepageWin = '437'; codepage = '437';
} }
} }
return codepageWin; return codepage;
}
if (_linux || _darwin || _freebsd || _openbsd) {
if (!codepage) {
try {
const stdout = execSync('echo $LANG');
const lines = stdout.toString().split('\r\n');
const parts = lines[0].split('.');
codepage = parts.length > 1 ? parts[1].trim : '';
} catch (err) {
codepage = 'UTF-8';
}
}
return codepage;
} }
} }
@ -203,10 +221,10 @@ function execWin(cmd, opts, callback) {
callback = opts; callback = opts;
opts = execOptsWin; opts = execOptsWin;
} }
let newCmd = 'chcp 65001 > nul && cmd /C ' + cmd + ' && chcp ' + codepageWin + ' > nul'; let newCmd = 'chcp 65001 > nul && cmd /C ' + cmd + ' && chcp ' + codepage + ' > nul';
exec(newCmd, execOptsWin, function (error, stdout) { exec(newCmd, execOptsWin, function (error, stdout) {
callback(error, stdout) callback(error, stdout);
}) });
} }
function nanoSeconds() { function nanoSeconds() {
@ -220,7 +238,7 @@ function nanoSeconds() {
function noop() { } function noop() { }
exports.execOptsWin = execOptsWin; exports.execOptsWin = execOptsWin;
exports.getWinCodepage = getWinCodepage; exports.getCodepage = getCodepage;
exports.execWin = execWin; exports.execWin = execWin;
exports.isFunction = isFunction; exports.isFunction = isFunction;
exports.unique = unique; exports.unique = unique;