From 8a6d69168412f750e2134d336b78cb0199e459a8 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Sun, 29 Apr 2018 22:30:38 +0200 Subject: [PATCH] added versions().mysql and versions().nginx, starting SunOS support --- CHANGELOG.md | 1 + README.md | 2 +- lib/cpu.js | 15 +++++++++++++++ lib/filesystem.js | 19 +++++++++++++++++++ lib/graphics.js | 4 ++++ lib/internet.js | 18 +++++++++++++++++- lib/osinfo.js | 33 +++++++++++++++++++++++++++++---- lib/processes.js | 6 +++++- lib/system.js | 4 ++++ lib/users.js | 11 +++++++++++ package.json | 3 ++- 11 files changed, 108 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ae5c3a..8dcaa3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ Other changes | Version | Date | Comment | | -------------- | -------------- | -------- | +| 3.39.0 | 2018-04-29 | added `versions().mysql` and `versions().nginx`, starting `SunOS` support (untested) | | 3.38.0 | 2018-04-06 | added `battery().acconnected` | | 3.37.12 | 2018-04-05 | another optimization `battery().ischarging` for macOS | | 3.37.11 | 2018-04-05 | another optimization `battery().ischarging` for macOS | diff --git a/README.md b/README.md index 4986110..00362de 100644 --- a/README.md +++ b/README.md @@ -53,13 +53,13 @@ async function cpu() { ### Latest Activity (last 7 major and minor version releases) +- Version 3.39.0: added `versions().mysql` and `versions().nginx`, starting `SunOS` support - Version 3.38.0: added `battery.acconnected` - Version 3.37.0: extended FreeBSD support `networkStats()` - Version 3.36.0: extended FreeBSD support `networkConnections()` - Version 3.35.0: extended FreeBSD support `processLoad()` - Version 3.34.0: first partial FreeBSD support - Version 3.33.0: added bios `bios()` and main board `baseboard()` information -- Version 3.32.0: extended `memLayout()` - added manufacturer - ... You can find all changes here: [detailed changelog][changelog-url] diff --git a/lib/cpu.js b/lib/cpu.js index 6906b43..4324c46 100644 --- a/lib/cpu.js +++ b/lib/cpu.js @@ -302,6 +302,9 @@ function getCpu() { resolve(result); }); } + if (_sunos) { + resolve(result); + } if (_windows) { exec(util.getWmic() + ' cpu get name, description, revision, l2cachesize, l3cachesize, manufacturer, currentclockspeed, maxclockspeed /value', opts, function (error, stdout) { if (!error) { @@ -538,6 +541,10 @@ function cpuTemperature(callback) { if (callback) { callback(result); } resolve(result); } + if (_sunos) { + if (callback) { callback(result); } + resolve(result); + } if (_windows) { exec(util.getWmic() + ' /namespace:\\\\root\\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature', opts, function (error, stdout) { if (!error) { @@ -640,6 +647,10 @@ function cpuFlags(callback) { resolve(result); }); } + if (_sunos) { + if (callback) { callback(result); } + resolve(result); + } }); }); } @@ -737,6 +748,10 @@ function cpuCache(callback) { resolve(result); }); } + if (_sunos) { + if (callback) { callback(result); } + resolve(result); + } if (_windows) { exec(util.getWmic() + ' cpu get l2cachesize, l3cachesize /value', opts, function (error, stdout) { if (!error) { diff --git a/lib/filesystem.js b/lib/filesystem.js index e99a874..828e79c 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -73,6 +73,10 @@ function fsSize(callback) { resolve(data); }); } + if (_sunos) { + if (callback) { callback(data); } + resolve(data); + } if (_windows) { exec(util.getWmic() + ' logicaldisk get Caption,FileSystem,FreeSpace,Size', opts, function (error, stdout) { let lines = stdout.split('\r\n').filter(line => line.trim() !== '').filter((line, idx) => idx > 0); @@ -248,6 +252,10 @@ function blockDevices(callback) { resolve(data); }); } + if (_sunos) { + if (callback) { callback(data); } + resolve(data); + } if (_windows) { let drivetypes = ['Unknown', 'NoRoot', 'Removable', 'HDD', 'Network', 'CD/DVD', 'RAM']; exec(util.getWmic() + ' logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value', opts, function (error, stdout) { @@ -490,6 +498,13 @@ function disksIO(callback) { } reject(error); } + if (_sunos) { + let error = new Error(NOT_SUPPORTED); + if (callback) { + callback(NOT_SUPPORTED); + } + reject(error); + } let result = { rIO: 0, @@ -630,6 +645,10 @@ function diskLayout(callback) { if (callback) { callback(result); } resolve(result); } + if (_sunos) { + if (callback) { callback(result); } + resolve(result); + } if (_darwin) { exec('system_profiler SPSerialATADataType SPNVMeDataType', function (error, stdout) { diff --git a/lib/graphics.js b/lib/graphics.js index f420e4d..3d6efd7 100644 --- a/lib/graphics.js +++ b/lib/graphics.js @@ -332,6 +332,10 @@ function graphics(callback) { if (callback) { callback(result); } resolve(result); } + if (_sunos) { + if (callback) { callback(result); } + resolve(result); + } if (_windows) { // https://blogs.technet.microsoft.com/heyscriptingguy/2013/10/03/use-powershell-to-discover-multi-monitor-information/ exec(util.getWmic() + ' path win32_VideoController get AdapterCompatibility, AdapterDACType, name, PNPDeviceID, CurrentVerticalResolution, CurrentHorizontalResolution, CurrentNumberOfColors, AdapterRAM, CurrentBitsPerPixel, CurrentRefreshRate, MinRefreshRate, MaxRefreshRate, VideoMemoryType /value', opts, function (error, stdout) { diff --git a/lib/internet.js b/lib/internet.js index 8754cc0..f9af978 100644 --- a/lib/internet.js +++ b/lib/internet.js @@ -45,7 +45,7 @@ function inetChecksite(url, callback) { if (url) { url = url.toLowerCase(); let t = Date.now(); - if (_linux || _freebsd || _openbsd || _darwin) { + if (_linux || _freebsd || _openbsd || _darwin || _sunos) { let args = ' -I --connect-timeout 5 -m 5 ' + url + ' 2>/dev/null | head -n 1 | cut -d " " -f2'; let cmd = 'curl'; exec(cmd + args, function (error, stdout) { @@ -140,6 +140,22 @@ function inetLatency(host, callback) { resolve(result); }); } + if (_sunos) { + exec('ping -s -a ' + host + ' 56 2 | grep avg', {timeout: 3000}, function (error, stdout) { + let result = -1; + if (!error) { + const line = stdout.toString().split('='); + if (line.length > 1) { + const parts = line[1].split('/'); + if (parts.length > 1) { + result = parseFloat(parts[1]); + } + } + } + if (callback) { callback(result); } + resolve(result); + }); + } if (_windows) { exec('ping ' + host + ' -n 1', opts, function (error, stdout) { let result = -1; diff --git a/lib/osinfo.js b/lib/osinfo.js index 35372df..0ac3484 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -228,6 +228,14 @@ function osInfo(callback) { resolve(result); }); } + if (_sunos) { + result.logofile = getLogoFile(); + result.release = result.kernel; + exec('uname -o', function (error, stdout) { + let lines = stdout.toString().split('\n'); + result.distro = lines[0]; + }); + } if (_windows) { result.logofile = getLogoFile(); result.release = result.kernel; @@ -260,6 +268,8 @@ function versions(callback) { grunt: '', git: '', tsc: '', + mysql: '', + nginx: '' }; let parts = []; exec('npm -v', function (error, stdout) { @@ -298,10 +308,24 @@ function versions(callback) { result.git = (result.git.toLowerCase().split('version')[1] || '').trim(); result.git = (result.git.split(' ')[0] || '').trim(); } - if (callback) { - callback(result); - } - resolve(result); + exec('nginx -v', function (error, stdout) { + if (!error) { + result.nginx = stdout.toString().split('\n')[0] || ''; + result.nginx = (result.nginx.toLowerCase().split('/')[1] || '').trim(); + } + exec('mysql -V', function (error, stdout) { + if (!error) { + result.mysql = stdout.toString().split('\n')[0] || ''; + result.mysql = (result.mysql.toLowerCase().split(',')[0] || '').trim(); + const parts = result.mysql.split(' '); + result.mysql = (parts[parts.length - 1] || '').trim(); + } + if (callback) { + callback(result); + } + resolve(result); + }); + }); }); }); }); @@ -313,6 +337,7 @@ function versions(callback) { }); } + exports.versions = versions; function shell(callback) { diff --git a/lib/processes.js b/lib/processes.js index d729b01..bb20124 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -479,10 +479,11 @@ function processes(callback) { let cmd = ''; if ((_process_cpu.ms && Date.now() - _process_cpu.ms >= 500) || _process_cpu.ms === 0) { - if (_linux || _freebsd || _openbsd || _darwin) { + if (_linux || _freebsd || _openbsd || _darwin || _sunos) { if (_linux) cmd = 'ps -axo pid:10,pcpu:6,pmem:6,pri:5,vsz:10,rss:10,ni:5,start:20,state:20,tty:20,user:20,command'; if (_freebsd || _openbsd) cmd = 'ps -axo pid,pcpu,pmem,pri,vsz,rss,ni,start,state,tty,user,command'; if (_darwin) cmd = 'ps -acxo pid,pcpu,pmem,pri,vsz,rss,nice,start,state,tty,user,command -r'; + if (_sunos) cmd = 'ps -Ao pid,pcpu,pmem,pri,vsz,rss,nice,stime,s,tty,user,comm'; exec(cmd, function (error, stdout) { if (!error) { result.list = parseProcesses(stdout.toString().split('\n')); @@ -551,6 +552,9 @@ function processes(callback) { } } else { cmd = 'ps -o pid,vsz,rss,nice,etime,stat,tty,user,comm'; + if (_sunos) { + cmd = 'ps -o pid,vsz,rss,nice,etime,s,tty,user,comm'; + } exec(cmd, function (error, stdout) { if (!error) { let lines = stdout.toString().split('\n'); diff --git a/lib/system.js b/lib/system.js index f566192..1e41031 100644 --- a/lib/system.js +++ b/lib/system.js @@ -163,6 +163,10 @@ function system(callback) { resolve(result); }); } + if (_sunos) { + if (callback) { callback(result); } + resolve(result); + } if (_windows) { // exec('wmic csproduct get', function (error, stdout) { // TODO: refactor /value diff --git a/lib/users.js b/lib/users.js index 4904040..86b4dad 100644 --- a/lib/users.js +++ b/lib/users.js @@ -221,6 +221,17 @@ function users(callback) { resolve(result); }); } + if (_sunos) { + exec('who; echo "---"; w -h', function (error, stdout) { + if (!error) { + // lines / split + let lines = stdout.toString().split('\n'); + result = parseUsersDarwin(lines); + } + if (callback) { callback(result); } + resolve(result); + }); + } if (_darwin) { exec('who; echo "---"; w -ih', function (error, stdout) { diff --git a/package.json b/package.json index 1e2273e..6f2deff 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "linux", "win32", "freebsd", - "openbsd" + "openbsd", + "sunos" ], "engines": { "node": ">=4.0.0"