Lightweight collection of 40+ functions to retrieve detailed hardware, system and OS information.
+Lightweight collection of 45+ functions to retrieve detailed hardware, system and OS information.
- simple to use
- get detailed information about system, cpu, baseboard, battery, memory, disks/filesystem, network, docker, software, services and processes diff --git a/docs/main.js b/docs/main.js index 4078ded..6c90ca3 100644 --- a/docs/main.js +++ b/docs/main.js @@ -23,7 +23,7 @@ function createMenu() { [0, '', 'More'], [1, 'security', 'Security Advisories'], [1, 'issues', 'Known Issues'], - [1, 'v5changes', 'Version 5 Changes'], + [1, 'changes', 'Version 5 Changes'], [1, 'history', 'Version history'], [1, 'copyright', 'Copyright & License'], [1, 'contributors', 'Contributors'], diff --git a/lib/index.js b/lib/index.js index 3470e2c..a5e4b2b 100755 --- a/lib/index.js +++ b/lib/index.js @@ -324,7 +324,8 @@ function get(valueObject, callback) { .filter(func => ({}.hasOwnProperty.call(exports, func))) .map(func => { const params = valueObject[func].substring(valueObject[func].lastIndexOf('(') + 1, valueObject[func].lastIndexOf(')')); - const funcWithoutParams = func.split('(')[0]; + let funcWithoutParams = func.indexOf(')') >= 0 ? func.split(')')[1].trim() : func; + funcWithoutParams = func.indexOf('|') >= 0 ? func.split('|')[0].trim() : funcWithoutParams; if (params) { return exports[funcWithoutParams](params) } else { @@ -340,7 +341,22 @@ function get(valueObject, callback) { if (valueObject[key] === '*' || valueObject[key] === 'all') { result[key] = data[i]; } else { - const keys = valueObject[key].replace(/,/g, ' ').replace(/ +/g, ' ').split(' '); + let keys = valueObject[key]; + // let params = ''; + let filter = ''; + let filterParts = []; + // remove params + if (keys.indexOf(')') >= 0) { + keys = keys.split(')')[1].trim(); + } + // extract filter and remove it from keys + if (keys.indexOf('|') >= 0) { + filter = keys.split('|')[1].trim(); + filterParts = filter.split(':'); + + keys = keys.split('|')[0].trim(); + } + keys = keys.replace(/,/g, ' ').replace(/ +/g, ' ').split(' '); if (data[i]) { if (Array.isArray(data[i])) { // result is in an array, go through all elements of array and pick only the right ones @@ -352,7 +368,23 @@ function get(valueObject, callback) { partialRes[k] = element[k]; } }); - partialArray.push(partialRes); + if (filter && filterParts.length === 2) { + if ({}.hasOwnProperty.call(partialRes, filterParts[0].trim())) { + const val = partialRes[filterParts[0].trim()]; + if (typeof val == 'number') { + if (val === parseFloat(filterParts[1].trim())) { + partialArray.push(partialRes); + } + } else if (typeof val == 'string') { + if (val.toLowerCase() === filterParts[1].trim().toLowerCase()) { + partialArray.push(partialRes); + } + } + } + } else { + partialArray.push(partialRes); + } + }); result[key] = partialArray; } else { diff --git a/test/si.js b/test/si.js index 3d58f58..33f4489 100644 --- a/test/si.js +++ b/test/si.js @@ -34,7 +34,6 @@ function test(f) { else if (f === 'u') { si.usb().then(data => { if (data !== null) { resolve({ data, title: 'USB' }); } else { resolve('not_supported') } }) } else if (f === 'U') { si.uuid().then(data => { if (data !== null) { resolve({ data, title: 'UUID' }); } else { resolve('not_supported') } }) } else if (f === 'v') { si.versions().then(data => { if (data !== null) { resolve({ data, title: 'Versions' }); } else { resolve('not_supported') } }) } - else if (f === 'V') { si.vboxInfo().then(data => { if (data !== null) { resolve({ data, title: 'Virtual Box' }); } else { resolve('not_supported') } }) } else if (f === 'w') { si.wifiNetworks().then(data => { if (data !== null) { resolve({ data, title: 'WIFI Networks' }); } else { resolve('not_supported') } }) } else if (f === 'y') { si.battery().then(data => { if (data !== null) { resolve({ data, title: 'Battery' }); } else { resolve('not_supported') } }) } else if (f === 'z') { si.users().then(data => { if (data !== null) { resolve({ data, title: 'Users' }); } else { resolve('not_supported') } }) } @@ -48,10 +47,11 @@ function test(f) { else if (f === '8') { si.dockerContainerStats('1').then(data => { if (data !== null) { resolve({ data, title: 'Docker Cont Stats' }); } else { resolve('not_supported') } }) } else if (f === '9') { si.dockerContainerProcesses('1').then(data => { if (data !== null) { resolve({ data, title: 'Docker Cont Processes' }); } else { resolve('not_supported') } }) } else if (f === '0') { si.dockerAll().then(data => { if (data !== null) { resolve({ data, title: 'Docker All' }); } else { resolve('not_supported') } }) } - else if (f === '+') { si.getStaticData().then(data => { if (data !== null) { resolve({ data, title: 'All Static Data' }); } else { resolve('not_supported') } }) } - else if (f === '-') { si.getDynamicData('apache2, postgres').then(data => { if (data !== null) { resolve({ data, title: 'All Dynamic Data' }); } else { resolve('not_supported') } }) } - else if (f === '#') { si.getAllData('apache2, postgres').then(data => { if (data !== null) { resolve({ data, title: 'All Data' }); } else { resolve('not_supported') } }) } - else if (f === '.') { + else if (f === '-') { si.vboxInfo().then(data => { if (data !== null) { resolve({ data, title: 'Virtual Box' }); } else { resolve('not_supported') } }) } + else if (f === ',') { si.getStaticData().then(data => { if (data !== null) { resolve({ data, title: 'All Static Data' }); } else { resolve('not_supported') } }) } + else if (f === '.') { si.getDynamicData('apache2, postgres').then(data => { if (data !== null) { resolve({ data, title: 'All Dynamic Data' }); } else { resolve('not_supported') } }) } + else if (f === '/') { si.getAllData('apache2, postgres').then(data => { if (data !== null) { resolve({ data, title: 'All Data' }); } else { resolve('not_supported') } }) } + else if (f === '?') { const valueObject = { cpu: '*', osInfo: 'platform, release', diff --git a/test/test.js b/test/test.js index c4856f0..9ff4049 100644 --- a/test/test.js +++ b/test/test.js @@ -14,19 +14,19 @@ function printHeader() { function printMenu() { console.log(''); - console.log('┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐'); - console.log('│ a ... Audio g ... Graphics p ... Processes w ... WIFI networks 1 ... NET Iface Default │'); - console.log('│ b ... BIOS h ... Bluetooth P ... Process Load y ... Battery 2 ... NET Gateway Default │'); - console.log('│ B ... Baseboard i ... INET Latency r ... Printer z ... Users 3 ... NET Interfaces │'); - console.log('│ C ... Chassis I ... INET Check Site s ... Services 4 ... NET Stats │'); - console.log('│ c ... CPU l ... CPU Load S ... Shell 5 ... NET Connections │'); - console.log('│ d ... DiskLayout L ... Full Load t ... time 6 ... Docker Info │'); - console.log('│ D ... DiskIO n ... T ... CPU Temperature 7 ... Docker Container │'); - console.log('│ e ... Block Devices m ... Memory u ... USB + ... All Static 8 ... Docker Cont Stats │'); - console.log('│ E ... Open Files M ... MEM Layout U ... UUID - ... All Dynamic 9 ... Docker Cont Proc │'); - console.log('│ f ... FS Size o ... OS Info v ... Versions # ... All 0 ... Docker All │'); - console.log('│ F ... FS Stats O ... V ... VirtualBox . ... Get Object q >>> Quit │'); - console.log('└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘'); + console.log('┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐'); + console.log('│ a ... Audio g ... Graphics r ... Printer 1 ... NET Iface Default ? ... Get Object │'); + console.log('│ b ... BIOS h ... Bluetooth s ... Services 2 ... NET Gateway Default , ... All Static │'); + console.log('│ B ... Baseboard i ... INET Latency S ... Shell 3 ... NET Interfaces . ... All Dynamic │'); + console.log('│ C ... Chassis I ... INET Check Site t ... time 4 ... NET Stats / ... All │'); + console.log('│ c ... CPU l ... CPU Load T ... CPU Temperature 5 ... NET Connections │'); + console.log('│ d ... DiskLayout L ... Full Load u ... USB 6 ... Docker Info │'); + console.log('│ D ... DiskIO m ... Memory U ... UUID 7 ... Docker Container │'); + console.log('│ e ... Block Devices M ... MEM Layout v ... Versions 8 ... Docker Cont Stats │'); + console.log('│ E ... Open Files o ... OS Info w ... WIFI networks 9 ... Docker Cont Proc │'); + console.log('│ f ... FS Size p ... Processes y ... Battery 0 ... Docker All │'); + console.log('│ F ... FS Stats P ... Process Load z ... Users - ... Virtual Box q >>> QUIT │'); + console.log('└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘'); } function EnableUserInput() {