You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
const Promise = require("bluebird");
|
|
const path = require("path");
|
|
const execBinary = require("../exec-binary");
|
|
const createPegParser = require("../text-parser-pegjs");
|
|
const itemsToObject = require("../items-to-object");
|
|
|
|
/* FIXME: Error handling, eg. device not found errors */
|
|
|
|
function outputParser(rootRule) {
|
|
return createPegParser({
|
|
grammarFile: path.join(__dirname, "./parser.pegjs"),
|
|
options: {
|
|
allowedStartRules: [ rootRule ]
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
attributes: function ({ devicePath }) {
|
|
return Promise.try(() => {
|
|
return execBinary("smartctl", [devicePath])
|
|
.asRoot()
|
|
.withFlags({ attributes: true })
|
|
.requireOnStdout(outputParser("RootAttributes"))
|
|
.execute();
|
|
}).then((output) => {
|
|
// NOTE: Ignore the header, for now
|
|
return output.result.attributes;
|
|
});
|
|
},
|
|
info: function ({ devicePath }) {
|
|
return Promise.try(() => {
|
|
return execBinary("smartctl", [devicePath])
|
|
.asRoot()
|
|
.withFlags({ info: true })
|
|
.requireOnStdout(outputParser("RootInfo"))
|
|
.execute();
|
|
}).then((output) => {
|
|
// NOTE: Ignore the header, for now
|
|
return itemsToObject(output.result.fields);
|
|
});
|
|
},
|
|
scan: function () {
|
|
return Promise.try(() => {
|
|
return execBinary("smartctl")
|
|
.asRoot()
|
|
.withFlags({ scan: true })
|
|
.requireOnStdout(outputParser("RootScan"))
|
|
.execute();
|
|
}).then((output) => {
|
|
// NOTE: Ignore the header, for now
|
|
return output.result.devices;
|
|
});
|
|
}
|
|
};
|