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.
67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
5 years ago
|
"use strict";
|
||
|
|
||
|
const {createDataObject, LocalProperties, ID} = require("../../graphql/data-object");
|
||
|
const upperSnakeCase = require("../../upper-snake-case");
|
||
|
|
||
|
module.exports = function (types) {
|
||
|
return function Drive({ path }) {
|
||
|
return createDataObject({
|
||
|
[LocalProperties]: {
|
||
|
path: path,
|
||
|
blockDevice: () => {
|
||
|
return types.BlockDevice({ path: path });
|
||
|
},
|
||
|
/* FIXME: allBlockDevices, for representing every single block device that's hosted on this physical drive, linearly. Need to figure out how that works with representation of mdraid arrays, LVM volumes, etc. */
|
||
|
},
|
||
|
smartctlScan: {
|
||
|
[ID]: path,
|
||
|
interface: "interface"
|
||
|
},
|
||
|
smartctlInfo: {
|
||
|
[ID]: path,
|
||
|
model: "model",
|
||
|
modelFamily: "modelFamily",
|
||
|
smartAvailable: "smartAvailable",
|
||
|
smartEnabled: "smartEnabled",
|
||
|
serialNumber: "serialNumber",
|
||
|
wwn: "wwn",
|
||
|
firmwareVersion: "firmwareVersion",
|
||
|
size: "size",
|
||
|
rpm: "rpm",
|
||
|
logicalSectorSize: (device) => device.sectorSizes.logical,
|
||
|
physicalSectorSize: (device) => device.sectorSizes.physical,
|
||
|
formFactor: "formFactor",
|
||
|
ataVersion: "ataVersion",
|
||
|
sataVersion: "sataVersion"
|
||
|
},
|
||
|
smartctlAttributes: {
|
||
|
[ID]: path,
|
||
|
smartAttributes: (attributes) => {
|
||
|
return attributes.map((attribute) => {
|
||
|
return Object.assign({}, attribute, {
|
||
|
type: upperSnakeCase(attribute.type),
|
||
|
updatedWhen: upperSnakeCase(attribute.updatedWhen)
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
smartHealth: (attributes) => {
|
||
|
let failed = attributes.filter((item) => {
|
||
|
return (item.failingNow === true || item.failedBefore === true);
|
||
|
});
|
||
|
|
||
|
let deteriorating = attributes.filter((item) => {
|
||
|
return (item.type === "preFail" && item.worstValueSeen < 100);
|
||
|
});
|
||
|
|
||
|
if (failed.length > 0) {
|
||
|
return "FAILING";
|
||
|
} else if (deteriorating.length > 0) {
|
||
|
return "DETERIORATING";
|
||
|
} else {
|
||
|
return "HEALTHY";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
};
|