From 8fa0d3065a748c70b3cbd5d0ac9b1a4125f41eab Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 7 May 2020 07:33:34 +0200 Subject: [PATCH] get() added function to get partial system info --- CHANGELOG.md | 1 + README.md | 3 ++- docs/general.html | 56 +++++++++++++++++++++++++++++++++++++++++++++++ docs/history.html | 5 +++++ docs/index.html | 2 +- lib/index.d.ts | 1 + lib/index.js | 36 ++++++++++++++++++++++++++++++ 7 files changed, 102 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 582321e..d6cfb74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.25.0 | 2020-05-07 | `get()` added function to get partial system info | | 4.24.2 | 2020-05-06 | `cpu()` fix (BSD), `networkStats()` fix BSD | | 4.24.1 | 2020-05-03 | `processes()` fix parsing command and params | | 4.24.0 | 2020-05-01 | `networkInterfaces()` added subnet mask ip4 and ip6 | diff --git a/README.md b/README.md index ae3e3e5..96e8ed8 100644 --- a/README.md +++ b/README.md @@ -87,13 +87,13 @@ si.cpu() (last 7 major and minor version releases) +- Version 4.25.0: `get()` added function to get partial system info - Version 4.24.0: `networkInterfaces()` added subnet mask ip4 and ip6 - Version 4.23.0: `versions()` added param to specify which program/lib versions to detect - Version 4.22.0: `services()` added pids (windows) - Version 4.21.0: added npx copmpatibility - Version 4.20.0: `battery()` added designcapacity, voltage, unit - Version 4.19.0: `osInfo()` added uefi (OS uses UEFI during startup) -- Version 4.18.0: `networkInterfaces()` added dhcp for mac os, added dhcp linux fallback - ... You can find all changes here: [detailed changelog][changelog-url] @@ -639,6 +639,7 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | si.getStaticData(cb) | {...} | X | X | X | X | X | all static data at once | | si.getDynamicData(srv,iface,cb) | {...} | X | X | X | X | X | all dynamic data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces | | si.getAllData(srv,iface,cb) | {...} | X | X | X | X | X | all data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces | +| si.get(valueObject,cb) | {...} | X | X | X | X | X | get partial system info data at once
In valueObject you can define
all values, you want to get back
(see documentation for details) | ### cb: Asynchronous Function Calls (callback) diff --git a/docs/general.html b/docs/general.html index 765893f..2c741fe 100644 --- a/docs/general.html +++ b/docs/general.html @@ -174,6 +174,62 @@ X all data at once
Specify services and interfaces to monitor
Defaults to first external network interface
Pass "*" for ALL services (linux/win only)
Pass "*" for ALL network interfaces + + si.get(valueObject,cb) + {...} + X + X + X + X + X + get partial data at once
Specify return object for all
values that should be returned.
See example: + + + + +
Example
+
const si = require('systeminformation');
+
+// define all values, you want to get back
+valueObject = {
+  cpu: '*',
+  osInfo: 'platform, release',
+  system: 'model, manufacturer'
+}
+
+si.get(valueObject).then(data => console.log(data));
+
+{
+  cpu: {
+    manufacturer: 'Intel®',
+    brand: 'Core™ i7-8569U',
+    vendor: 'GenuineIntel',
+    family: '6',
+    model: '142',
+    stepping: '10',
+    revision: '',
+    voltage: '',
+    speed: '2.80',
+    speedmin: '2.80',
+    speedmax: '2.80',
+    governor: '',
+    cores: 8,
+    physicalCores: 4,
+    processors: 1,
+    socket: '',
+    cache: { l1d: 32768, l1i: 32768, l2: 262144, l3: 8388608 }
+  },
+  osInfo: {
+    platform: 'darwin',
+    release: '10.15.4'
+  },
+  system: {
+    model: 'MacBookPro15,2',
+    manufacturer: 'Apple Inc.'
+  }
+}
+
+

Static data is all hardware related (or more or less constant) data like system, baseboard, bios, OS, versions, cpu, network interfces, memory and disk layout

diff --git a/docs/history.html b/docs/history.html index 93bc0a8..53de7ba 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.25.0 + 2020-05-07 + get() added function to get partial system info /td> + 4.24.2 2020-05-06 diff --git a/docs/index.html b/docs/index.html index f1323ad..2e24136 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.24.2
+
Current Version: 4.25.0
diff --git a/lib/index.d.ts b/lib/index.d.ts index e0d0518..e0a9505 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -681,3 +681,4 @@ export function vboxInfo(cb?: (data: Systeminformation.VboxInfoData[]) => any): export function getStaticData(cb?: (data: Systeminformation.StaticData) => any): Promise; export function getDynamicData(srv?: string, iface?: string, cb?: (data: any) => any): Promise; export function getAllData(srv?: string, iface?: string, cb?: (data: any) => any): Promise; +export function get(valuesObject: any, cb?: (data: any) => any): Promise; diff --git a/lib/index.js b/lib/index.js index ac6ffff..f2dd0cf 100644 --- a/lib/index.js +++ b/lib/index.js @@ -308,6 +308,40 @@ function getAllData(srv, iface, callback) { }); } +function get(valueObject, callback) { + return new Promise((resolve) => { + process.nextTick(() => { + const allPromises = Object.keys(valueObject) + .filter(func => ({}.hasOwnProperty.call(exports, func))) + .map(func => exports[func]()); + + Promise.all(allPromises).then(data => { + const result = {}; + let i = 0; + for (let key in valueObject) { + if ({}.hasOwnProperty.call(valueObject, key) && {}.hasOwnProperty.call(exports, key) && data.length >= i) { + if (valueObject[key] === '*' || valueObject[key] === 'all') { + result[key] = data[i]; + } else { + const keys = valueObject[key].replace(/,/g, ' ').replace(/ +/g, ' ').split(' '); + const partialRes = {}; + keys.forEach(k => { + if ({}.hasOwnProperty.call(data[i], k)) { + partialRes[k] = data[i][k]; + } + }); + result[key] = partialRes; + } + i++; + } + } + if (callback) { callback(result); } + resolve(result); + }); + }); + }); +} + // ---------------------------------------------------------------------------------- // export all libs // ---------------------------------------------------------------------------------- @@ -374,3 +408,5 @@ exports.vboxInfo = vbox.vboxInfo; exports.getStaticData = getStaticData; exports.getDynamicData = getDynamicData; exports.getAllData = getAllData; +exports.get = get; +