diff --git a/CHANGELOG.md b/CHANGELOG.md index 16ba280..956ff12 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.8.3 | 2019-06-01 | `vboxInfo()` added stoppedSince, started, stopped | | 4.8.2 | 2019-05-31 | `dockerInfo()` changed property naming style | | 4.8.1 | 2019-05-31 | updated docs | | 4.8.0 | 2019-05-31 | added `vboxInfo()` detailed virtual box info | diff --git a/README.md b/README.md index b92f547..ae4687b 100644 --- a/README.md +++ b/README.md @@ -555,7 +555,10 @@ I also created a nice little command line tool called [mmon][mmon-github-url] ( | | [0].id | X | X | X | X | X | virtual box ID | | | [0].name | X | X | X | X | X | name | | | [0].running | X | X | X | X | X | vbox is running | +| | [0].started | X | X | X | X | X | started date time | | | [0].runningSince | X | X | X | X | X | running since (secs) | +| | [0].stopped | X | X | X | X | X | stopped date time | +| | [0].stoppedSince | X | X | X | X | X | stopped since (secs) | | | [0].guestOS | X | X | X | X | X | Guest OK | | | [0].hardwareUUID | X | X | X | X | X | Hardware UUID | | | [0].memory | X | X | X | X | X | Memory in MB | diff --git a/docs/history.html b/docs/history.html index 0dba2c1..f5c4d63 100644 --- a/docs/history.html +++ b/docs/history.html @@ -80,6 +80,11 @@ + + 4.8.3 + 2019-05-31 + vboxInfo() added stoppedSince, started, stopped + 4.8.2 2019-05-31 diff --git a/docs/index.html b/docs/index.html index af9bca8..a5b4bef 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
-
Current Version: 4.8.2
+
Current Version: 4.8.3
diff --git a/docs/vbox.html b/docs/vbox.html index 1268b35..b6147fb 100644 --- a/docs/vbox.html +++ b/docs/vbox.html @@ -105,6 +105,16 @@ X vbox is running + + + [0].started + X + X + X + X + X + started date time + [0].runningSince @@ -115,6 +125,26 @@ X running since (secs) + + + [0].stopped + X + X + X + X + X + stopped date time + + + + [0].stoppedSince + X + X + X + X + X + stopped since (secs) + [0].guestOS diff --git a/lib/index.d.ts b/lib/index.d.ts index a6c597c..14dc36b 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -526,7 +526,10 @@ export namespace Systeminformation { id: string; name: string; running: boolean; + started: string; runningSince: number; + stopped: string; + stoppedSince: number; guestOS: string; hardwareUUID: string; memory: number; diff --git a/lib/virtualbox.js b/lib/virtualbox.js index 740f1f3..52ea949 100644 --- a/lib/virtualbox.js +++ b/lib/virtualbox.js @@ -31,13 +31,10 @@ function vboxInfo(all, callback) { process.nextTick(() => { try { exec(util.getVboxmanage() + ' list vms --long', function (error, stdout) { - let parts = stdout.toString().split('Name:'); + let parts = (os.EOL + stdout.toString()).split(os.EOL + 'Name:'); parts.shift(); parts.forEach(part => { - const lines = part.split(os.EOL); - if (lines && lines[0]) { - lines[0] = 'Name:' + lines[0]; - } + const lines = ('Name:' + part).split(os.EOL); const state = util.getValue(lines, 'State'); const running = state.startsWith('running'); const runningSinceString = running ? state.replace('running (since ', '').replace(')', '').trim() : ''; @@ -51,11 +48,25 @@ function vboxInfo(all, callback) { } catch (e) { util.noop(); } + const stoppedSinceString = !running ? state.replace('powered off (since', '').replace(')', '').trim() : ''; + let stoppedSince = 0; + try { + if (!running) { + const sinceDateObj = new Date(stoppedSinceString); + const offset = sinceDateObj.getTimezoneOffset(); + stoppedSince = 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, + started: runningSinceString, runningSince, + stopped: stoppedSinceString, + stoppedSince, guestOS: util.getValue(lines, 'Guest OS'), hardwareUUID: util.getValue(lines, 'Hardware UUID'), memory: parseInt(util.getValue(lines, 'Memory size', ' '), 10),