added virtual box VM info

This commit is contained in:
Sebastian Hildebrandt
2019-05-31 22:46:55 +02:00
parent e65067af72
commit 4dad5284a9
14 changed files with 654 additions and 8 deletions
+3
View File
@@ -35,6 +35,7 @@ const processes = require('./processes');
const users = require('./users');
const internet = require('./internet');
const docker = require('./docker');
const vbox = require('./virtualbox');
let _platform = process.platform;
const _windows = (_platform === 'win32');
@@ -364,6 +365,8 @@ exports.dockerContainerStats = docker.dockerContainerStats;
exports.dockerContainerProcesses = docker.dockerContainerProcesses;
exports.dockerAll = docker.dockerAll;
exports.vboxInfo = vbox.vboxInfo;
exports.getStaticData = getStaticData;
exports.getDynamicData = getDynamicData;
exports.getAllData = getAllData;
+2 -3
View File
@@ -602,7 +602,7 @@ function versions(callback) {
} else {
functionProcessed();
}
})
});
} else {
exec('java -version 2>&1', function (error, stdout) {
if (!error) {
@@ -632,8 +632,7 @@ function versions(callback) {
});
}
});
const vboxmanagePath = _windows ? process.env.VBOX_INSTALL_PATH || process.env.VBOX_MSI_INSTALL_PATH + '\\VBoxManage.exe' + '" ' : 'vboxmanage';
exec(vboxmanagePath + ' -v 2>&1', function (error, stdout) {
exec(util.getVboxmanage() + ' -v 2>&1', function (error, stdout) {
if (!error) {
const vbox = stdout.toString().split('\n')[0] || '';
const parts = vbox.split('r');
+5
View File
@@ -254,6 +254,10 @@ function wmic(command, options) {
});
}
function getVboxmanage() {
return _windows ? process.env.VBOX_INSTALL_PATH || process.env.VBOX_MSI_INSTALL_PATH + '\\VBoxManage.exe' + '" ' : 'vboxmanage';
}
function powerShell(cmd) {
let result = '';
@@ -407,6 +411,7 @@ exports.parseHead = parseHead;
exports.findObjectByKey = findObjectByKey;
exports.getWmic = getWmic;
exports.wmic = wmic;
exports.getVboxmanage = getVboxmanage;
exports.powerShell = powerShell;
exports.nanoSeconds = nanoSeconds;
exports.countUniqueLines = countUniqueLines;
+102
View File
@@ -0,0 +1,102 @@
'use strict';
// @ts-check
// ==================================================================================
// virtualbox.js
// ----------------------------------------------------------------------------------
// Description: System Information - library
// for Node.js
// Copyright: (c) 2014 - 2019
// Author: Sebastian Hildebrandt
// ----------------------------------------------------------------------------------
// License: MIT
// ==================================================================================
// 14. Docker
// ----------------------------------------------------------------------------------
const os = require('os');
const exec = require('child_process').exec;
const util = require('./util');
function vboxInfo(all, callback) {
// fallback - if only callback is given
if (util.isFunction(all) && !callback) {
callback = all;
all = false;
}
all = all || false;
let result = [];
return new Promise((resolve) => {
process.nextTick(() => {
try {
exec(util.getVboxmanage() + ' list vms --long', function (error, stdout) {
let parts = stdout.toString().split('Name:');
parts.shift();
parts.forEach(part => {
const lines = part.split(os.EOL);
if (lines && lines[0]) {
lines[0] = 'Name:' + lines[0];
}
const state = util.getValue(lines, 'State');
const running = state.startsWith('running');
const runningSinceString = running ? state.replace('running (since ', '').replace(')', '').trim() : '';
let runningSince = 0;
try {
if (running) {
const sinceDateObj = new Date(runningSinceString);
const offset = sinceDateObj.getTimezoneOffset();
runningSince = Math.round((Date.now() - Date.parse(sinceDateObj)) / 1000) + offset * 60;
}
} catch (e) {
util.noop();
}
result.push({
id: util.getValue(lines, 'UUID'),
name: util.getValue(lines, 'Name'),
running,
runningSince,
guestOS: util.getValue(lines, 'Guest OS'),
hardwareUUID: util.getValue(lines, 'Hardware UUID'),
memory: parseInt(util.getValue(lines, 'Memory size', ' '), 10),
vram: parseInt(util.getValue(lines, 'VRAM size'), 10),
cpus: parseInt(util.getValue(lines, 'Number of CPUs'), 10),
cpuExepCap: util.getValue(lines, 'CPU exec cap'),
cpuProfile: util.getValue(lines, 'CPUProfile'),
chipset: util.getValue(lines, 'Chipset'),
firmware: util.getValue(lines, 'Firmware'),
pageFusion: util.getValue(lines, 'Page Fusion') === 'enabled',
configFile: util.getValue(lines, 'Config file'),
snapshotFolder: util.getValue(lines, 'Snapshot folder'),
logFolder: util.getValue(lines, 'Log folder'),
HPET: util.getValue(lines, 'HPET') === 'enabled',
PAE: util.getValue(lines, 'PAE') === 'enabled',
longMode: util.getValue(lines, 'Long Mode') === 'enabled',
tripleFaultReset: util.getValue(lines, 'Triple Fault Reset') === 'enabled',
APIC: util.getValue(lines, 'APIC') === 'enabled',
X2APIC: util.getValue(lines, 'X2APIC') === 'enabled',
ACPI: util.getValue(lines, 'ACPI') === 'enabled',
IOAPIC: util.getValue(lines, 'IOAPIC') === 'enabled',
biosAPICmode: util.getValue(lines, 'BIOS APIC mode'),
bootMenuMode: util.getValue(lines, 'Boot menu mode'),
bootDevice1: util.getValue(lines, 'Boot Device 1'),
bootDevice2: util.getValue(lines, 'Boot Device 2'),
bootDevice3: util.getValue(lines, 'Boot Device 3'),
bootDevice4: util.getValue(lines, 'Boot Device 4'),
timeOffset: util.getValue(lines, 'Time offset'),
RTC: util.getValue(lines, 'RTC'),
});
});
if (callback) { callback(result); }
resolve(result);
});
} catch (e) {
if (callback) { callback(result); }
resolve(result);
}
});
});
}
exports.vboxInfo = vboxInfo;