@depup/systeminformation 5.31.4-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js ADDED
@@ -0,0 +1,518 @@
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // index.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2026
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // Contributors: Guillaume Legrain (https://github.com/glegrain)
12
+ // Riccardo Novaglia (https://github.com/richy24)
13
+ // Quentin Busuttil (https://github.com/Buzut)
14
+ // Lapsio (https://github.com/lapsio)
15
+ // csy (https://github.com/csy1983)
16
+ // ----------------------------------------------------------------------------------
17
+ // License: MIT
18
+ // ==================================================================================
19
+
20
+ // ----------------------------------------------------------------------------------
21
+ // Dependencies
22
+ // ----------------------------------------------------------------------------------
23
+
24
+ const lib_version = require('../package.json').version;
25
+ const util = require('./util');
26
+ const system = require('./system');
27
+ const osInfo = require('./osinfo');
28
+ const cpu = require('./cpu');
29
+ const memory = require('./memory');
30
+ const battery = require('./battery');
31
+ const graphics = require('./graphics');
32
+ const filesystem = require('./filesystem');
33
+ const network = require('./network');
34
+ const wifi = require('./wifi');
35
+ const processes = require('./processes');
36
+ const users = require('./users');
37
+ const internet = require('./internet');
38
+ const docker = require('./docker');
39
+ const vbox = require('./virtualbox');
40
+ const printer = require('./printer');
41
+ const usb = require('./usb');
42
+ const audio = require('./audio');
43
+ const bluetooth = require('./bluetooth');
44
+
45
+ const _platform = process.platform;
46
+ const _windows = _platform === 'win32';
47
+ const _freebsd = _platform === 'freebsd';
48
+ const _openbsd = _platform === 'openbsd';
49
+ const _netbsd = _platform === 'netbsd';
50
+ const _sunos = _platform === 'sunos';
51
+
52
+ // ----------------------------------------------------------------------------------
53
+ // init
54
+ // ----------------------------------------------------------------------------------
55
+
56
+ if (_windows) {
57
+ util.getCodepage();
58
+ util.getPowershell();
59
+ }
60
+
61
+ // ----------------------------------------------------------------------------------
62
+ // General
63
+ // ----------------------------------------------------------------------------------
64
+
65
+ function version() {
66
+ return lib_version;
67
+ }
68
+
69
+ // ----------------------------------------------------------------------------------
70
+ // Get static and dynamic data (all)
71
+ // ----------------------------------------------------------------------------------
72
+
73
+ // --------------------------
74
+ // get static data - they should not change until restarted
75
+
76
+ function getStaticData(callback) {
77
+ return new Promise((resolve) => {
78
+ process.nextTick(() => {
79
+ const data = {};
80
+
81
+ data.version = version();
82
+
83
+ Promise.all([
84
+ system.system(),
85
+ system.bios(),
86
+ system.baseboard(),
87
+ system.chassis(),
88
+ osInfo.osInfo(),
89
+ osInfo.uuid(),
90
+ osInfo.versions(),
91
+ cpu.cpu(),
92
+ cpu.cpuFlags(),
93
+ graphics.graphics(),
94
+ network.networkInterfaces(),
95
+ memory.memLayout(),
96
+ filesystem.diskLayout(),
97
+ audio.audio(),
98
+ bluetooth.bluetoothDevices(),
99
+ usb.usb(),
100
+ printer.printer()
101
+ ]).then((res) => {
102
+ data.system = res[0];
103
+ data.bios = res[1];
104
+ data.baseboard = res[2];
105
+ data.chassis = res[3];
106
+ data.os = res[4];
107
+ data.uuid = res[5];
108
+ data.versions = res[6];
109
+ data.cpu = res[7];
110
+ data.cpu.flags = res[8];
111
+ data.graphics = res[9];
112
+ data.net = res[10];
113
+ data.memLayout = res[11];
114
+ data.diskLayout = res[12];
115
+ data.audio = res[13];
116
+ data.bluetooth = res[14];
117
+ data.usb = res[15];
118
+ data.printer = res[16];
119
+ if (callback) {
120
+ callback(data);
121
+ }
122
+ resolve(data);
123
+ });
124
+ });
125
+ });
126
+ }
127
+
128
+ // --------------------------
129
+ // get all dynamic data - e.g. for monitoring agents
130
+ // may take some seconds to get all data
131
+ // --------------------------
132
+ // 2 additional parameters needed
133
+ // - srv: comma separated list of services to monitor e.g. "mysql, apache, postgresql"
134
+ // - iface: define network interface for which you like to monitor network speed e.g. "eth0"
135
+
136
+ function getDynamicData(srv, iface, callback) {
137
+ if (util.isFunction(iface)) {
138
+ callback = iface;
139
+ iface = '';
140
+ }
141
+ if (util.isFunction(srv)) {
142
+ callback = srv;
143
+ srv = '';
144
+ }
145
+
146
+ return new Promise((resolve) => {
147
+ process.nextTick(() => {
148
+ iface = iface || network.getDefaultNetworkInterface();
149
+ srv = srv || '';
150
+
151
+ // use closure to track ƒ completion
152
+ let functionProcessed = (() => {
153
+ let totalFunctions = 15;
154
+ if (_windows) {
155
+ totalFunctions = 13;
156
+ }
157
+ if (_freebsd || _openbsd || _netbsd) {
158
+ totalFunctions = 11;
159
+ }
160
+ if (_sunos) {
161
+ totalFunctions = 6;
162
+ }
163
+
164
+ return function () {
165
+ if (--totalFunctions === 0) {
166
+ if (callback) {
167
+ callback(data);
168
+ }
169
+ resolve(data);
170
+ }
171
+ };
172
+ })();
173
+
174
+ const data = {};
175
+
176
+ // get time
177
+ data.time = osInfo.time();
178
+
179
+ /**
180
+ * @namespace
181
+ * @property {Object} versions
182
+ * @property {string} versions.node
183
+ * @property {string} versions.v8
184
+ */
185
+ data.node = process.versions.node;
186
+ data.v8 = process.versions.v8;
187
+
188
+ cpu.cpuCurrentSpeed().then((res) => {
189
+ data.cpuCurrentSpeed = res;
190
+ functionProcessed();
191
+ });
192
+
193
+ users.users().then((res) => {
194
+ data.users = res;
195
+ functionProcessed();
196
+ });
197
+
198
+ processes.processes().then((res) => {
199
+ data.processes = res;
200
+ functionProcessed();
201
+ });
202
+
203
+ cpu.currentLoad().then((res) => {
204
+ data.currentLoad = res;
205
+ functionProcessed();
206
+ });
207
+
208
+ if (!_sunos) {
209
+ cpu.cpuTemperature().then((res) => {
210
+ data.temp = res;
211
+ functionProcessed();
212
+ });
213
+ }
214
+
215
+ if (!_openbsd && !_freebsd && !_netbsd && !_sunos) {
216
+ network.networkStats(iface).then((res) => {
217
+ data.networkStats = res;
218
+ functionProcessed();
219
+ });
220
+ }
221
+
222
+ if (!_sunos) {
223
+ network.networkConnections().then((res) => {
224
+ data.networkConnections = res;
225
+ functionProcessed();
226
+ });
227
+ }
228
+
229
+ memory.mem().then((res) => {
230
+ data.mem = res;
231
+ functionProcessed();
232
+ });
233
+
234
+ if (!_sunos) {
235
+ battery().then((res) => {
236
+ data.battery = res;
237
+ functionProcessed();
238
+ });
239
+ }
240
+
241
+ if (!_sunos) {
242
+ processes.services(srv).then((res) => {
243
+ data.services = res;
244
+ functionProcessed();
245
+ });
246
+ }
247
+
248
+ if (!_sunos) {
249
+ filesystem.fsSize().then((res) => {
250
+ data.fsSize = res;
251
+ functionProcessed();
252
+ });
253
+ }
254
+
255
+ if (!_windows && !_openbsd && !_freebsd && !_netbsd && !_sunos) {
256
+ filesystem.fsStats().then((res) => {
257
+ data.fsStats = res;
258
+ functionProcessed();
259
+ });
260
+ }
261
+
262
+ if (!_windows && !_openbsd && !_freebsd && !_netbsd && !_sunos) {
263
+ filesystem.disksIO().then((res) => {
264
+ data.disksIO = res;
265
+ functionProcessed();
266
+ });
267
+ }
268
+
269
+ if (!_openbsd && !_freebsd && !_netbsd && !_sunos) {
270
+ wifi.wifiNetworks().then((res) => {
271
+ data.wifiNetworks = res;
272
+ functionProcessed();
273
+ });
274
+ }
275
+
276
+ internet.inetLatency().then((res) => {
277
+ data.inetLatency = res;
278
+ functionProcessed();
279
+ });
280
+ });
281
+ });
282
+ }
283
+
284
+ // --------------------------
285
+ // get all data at once
286
+ // --------------------------
287
+ // 2 additional parameters needed
288
+ // - srv: comma separated list of services to monitor e.g. "mysql, apache, postgresql"
289
+ // - iface: define network interface for which you like to monitor network speed e.g. "eth0"
290
+
291
+ function getAllData(srv, iface, callback) {
292
+ return new Promise((resolve) => {
293
+ process.nextTick(() => {
294
+ let data = {};
295
+
296
+ if (iface && util.isFunction(iface) && !callback) {
297
+ callback = iface;
298
+ iface = '';
299
+ }
300
+
301
+ if (srv && util.isFunction(srv) && !iface && !callback) {
302
+ callback = srv;
303
+ srv = '';
304
+ iface = '';
305
+ }
306
+
307
+ getStaticData().then((res) => {
308
+ data = res;
309
+ getDynamicData(srv, iface).then((res) => {
310
+ for (let key in res) {
311
+ if ({}.hasOwnProperty.call(res, key)) {
312
+ data[key] = res[key];
313
+ }
314
+ }
315
+ if (callback) {
316
+ callback(data);
317
+ }
318
+ resolve(data);
319
+ });
320
+ });
321
+ });
322
+ });
323
+ }
324
+
325
+ function get(valueObject, callback) {
326
+ return new Promise((resolve) => {
327
+ process.nextTick(() => {
328
+ const allPromises = Object.keys(valueObject)
329
+ .filter((func) => ({}).hasOwnProperty.call(exports, func))
330
+ .map((func) => {
331
+ const params = valueObject[func].substring(valueObject[func].lastIndexOf('(') + 1, valueObject[func].lastIndexOf(')'));
332
+ let funcWithoutParams = func.indexOf(')') >= 0 ? func.split(')')[1].trim() : func;
333
+ funcWithoutParams = func.indexOf('|') >= 0 ? func.split('|')[0].trim() : funcWithoutParams;
334
+ if (params) {
335
+ return exports[funcWithoutParams](params);
336
+ } else {
337
+ return exports[funcWithoutParams]('');
338
+ }
339
+ });
340
+
341
+ Promise.all(allPromises).then((data) => {
342
+ const result = {};
343
+ let i = 0;
344
+ for (let key in valueObject) {
345
+ if ({}.hasOwnProperty.call(valueObject, key) && {}.hasOwnProperty.call(exports, key) && data.length > i) {
346
+ if (valueObject[key] === '*' || valueObject[key] === 'all') {
347
+ result[key] = data[i];
348
+ } else {
349
+ let keys = valueObject[key];
350
+ let filter = '';
351
+ let filterParts = [];
352
+ // remove params
353
+ if (keys.indexOf(')') >= 0) {
354
+ keys = keys.split(')')[1].trim();
355
+ }
356
+ // extract filter and remove it from keys
357
+ if (keys.indexOf('|') >= 0) {
358
+ filter = keys.split('|')[1].trim();
359
+ filterParts = filter.split(':');
360
+
361
+ keys = keys.split('|')[0].trim();
362
+ }
363
+ keys = keys.replace(/,/g, ' ').replace(/ +/g, ' ').split(' ');
364
+ if (data[i]) {
365
+ if (Array.isArray(data[i])) {
366
+ // result is in an array, go through all elements of array and pick only the right ones
367
+ const partialArray = [];
368
+ data[i].forEach((element) => {
369
+ let partialRes = {};
370
+ if (keys.length === 1 && (keys[0] === '*' || keys[0] === 'all')) {
371
+ partialRes = element;
372
+ } else {
373
+ keys.forEach((k) => {
374
+ if ({}.hasOwnProperty.call(element, k)) {
375
+ partialRes[k] = element[k];
376
+ }
377
+ });
378
+ }
379
+ // if there is a filter, then just take those elements
380
+ if (filter && filterParts.length === 2) {
381
+ if ({}.hasOwnProperty.call(partialRes, filterParts[0].trim())) {
382
+ const val = partialRes[filterParts[0].trim()];
383
+ if (typeof val === 'number') {
384
+ if (val === parseFloat(filterParts[1].trim())) {
385
+ partialArray.push(partialRes);
386
+ }
387
+ } else if (typeof val === 'string') {
388
+ if (val.toLowerCase() === filterParts[1].trim().toLowerCase()) {
389
+ partialArray.push(partialRes);
390
+ }
391
+ }
392
+ }
393
+ } else {
394
+ partialArray.push(partialRes);
395
+ }
396
+ });
397
+ result[key] = partialArray;
398
+ } else {
399
+ const partialRes = {};
400
+ keys.forEach((k) => {
401
+ if ({}.hasOwnProperty.call(data[i], k)) {
402
+ partialRes[k] = data[i][k];
403
+ }
404
+ });
405
+ result[key] = partialRes;
406
+ }
407
+ } else {
408
+ result[key] = {};
409
+ }
410
+ }
411
+ i++;
412
+ }
413
+ }
414
+ if (callback) {
415
+ callback(result);
416
+ }
417
+ resolve(result);
418
+ });
419
+ });
420
+ });
421
+ }
422
+
423
+ function observe(valueObject, interval, callback) {
424
+ let _data = null;
425
+
426
+ const result = setInterval(() => {
427
+ get(valueObject).then((data) => {
428
+ if (JSON.stringify(_data) !== JSON.stringify(data)) {
429
+ _data = Object.assign({}, data);
430
+ callback(data);
431
+ }
432
+ });
433
+ }, interval);
434
+ return result;
435
+ }
436
+
437
+ // ----------------------------------------------------------------------------------
438
+ // export all libs
439
+ // ----------------------------------------------------------------------------------
440
+
441
+ exports.version = version;
442
+ exports.system = system.system;
443
+ exports.bios = system.bios;
444
+ exports.baseboard = system.baseboard;
445
+ exports.chassis = system.chassis;
446
+
447
+ exports.time = osInfo.time;
448
+ exports.osInfo = osInfo.osInfo;
449
+ exports.versions = osInfo.versions;
450
+ exports.shell = osInfo.shell;
451
+ exports.uuid = osInfo.uuid;
452
+
453
+ exports.cpu = cpu.cpu;
454
+ exports.cpuFlags = cpu.cpuFlags;
455
+ exports.cpuCache = cpu.cpuCache;
456
+ exports.cpuCurrentSpeed = cpu.cpuCurrentSpeed;
457
+ exports.cpuTemperature = cpu.cpuTemperature;
458
+ exports.currentLoad = cpu.currentLoad;
459
+ exports.fullLoad = cpu.fullLoad;
460
+
461
+ exports.mem = memory.mem;
462
+ exports.memLayout = memory.memLayout;
463
+
464
+ exports.battery = battery;
465
+
466
+ exports.graphics = graphics.graphics;
467
+
468
+ exports.fsSize = filesystem.fsSize;
469
+ exports.fsOpenFiles = filesystem.fsOpenFiles;
470
+ exports.blockDevices = filesystem.blockDevices;
471
+ exports.fsStats = filesystem.fsStats;
472
+ exports.disksIO = filesystem.disksIO;
473
+ exports.diskLayout = filesystem.diskLayout;
474
+
475
+ exports.networkInterfaceDefault = network.networkInterfaceDefault;
476
+ exports.networkGatewayDefault = network.networkGatewayDefault;
477
+ exports.networkInterfaces = network.networkInterfaces;
478
+ exports.networkStats = network.networkStats;
479
+ exports.networkConnections = network.networkConnections;
480
+
481
+ exports.wifiNetworks = wifi.wifiNetworks;
482
+ exports.wifiInterfaces = wifi.wifiInterfaces;
483
+ exports.wifiConnections = wifi.wifiConnections;
484
+
485
+ exports.services = processes.services;
486
+ exports.processes = processes.processes;
487
+ exports.processLoad = processes.processLoad;
488
+
489
+ exports.users = users.users;
490
+
491
+ exports.inetChecksite = internet.inetChecksite;
492
+ exports.inetLatency = internet.inetLatency;
493
+
494
+ exports.dockerInfo = docker.dockerInfo;
495
+ exports.dockerImages = docker.dockerImages;
496
+ exports.dockerContainers = docker.dockerContainers;
497
+ exports.dockerContainerStats = docker.dockerContainerStats;
498
+ exports.dockerContainerProcesses = docker.dockerContainerProcesses;
499
+ exports.dockerVolumes = docker.dockerVolumes;
500
+ exports.dockerAll = docker.dockerAll;
501
+
502
+ exports.vboxInfo = vbox.vboxInfo;
503
+
504
+ exports.printer = printer.printer;
505
+
506
+ exports.usb = usb.usb;
507
+
508
+ exports.audio = audio.audio;
509
+ exports.bluetoothDevices = bluetooth.bluetoothDevices;
510
+
511
+ exports.getStaticData = getStaticData;
512
+ exports.getDynamicData = getDynamicData;
513
+ exports.getAllData = getAllData;
514
+ exports.get = get;
515
+ exports.observe = observe;
516
+
517
+ exports.powerShellStart = util.powerShellStart;
518
+ exports.powerShellRelease = util.powerShellRelease;