diskLayout() added S.M.A.R.T. status
This commit is contained in:
+95
-8
@@ -608,6 +608,7 @@ function diskLayout(callback) {
|
||||
process.nextTick(() => {
|
||||
|
||||
let result = [];
|
||||
let cmd = '';
|
||||
|
||||
if (_linux) {
|
||||
exec('export LC_ALL=C; lshw -class disk; unset LC_ALL', function (error, stdout) {
|
||||
@@ -617,6 +618,7 @@ function diskLayout(callback) {
|
||||
devices.forEach(function (device) {
|
||||
let lines = device.split('\n');
|
||||
let mediumType = '';
|
||||
const BSDName = util.getValue(lines, 'logical name', ':', true).trim();
|
||||
const logical = util.getValue(lines, 'logical name', ':', true).trim().replace(/\/dev\//g, '');
|
||||
try {
|
||||
mediumType = execSync('cat /sys/block/' + logical + '/queue/rotational').toString().split('\n')[0];
|
||||
@@ -642,14 +644,53 @@ function diskLayout(callback) {
|
||||
firmwareRevision: util.getValue(lines, 'version:', ':', true).trim(),
|
||||
serialNum: util.getValue(lines, 'serial:', ':', true).trim(),
|
||||
interfaceType: '',
|
||||
smartStatus: 'unknown',
|
||||
BSDName: BSDName
|
||||
});
|
||||
cmd = cmd + 'printf "\n' + BSDName + '|"; smartctl -H ' + BSDName + ' | grep overall;';
|
||||
}
|
||||
});
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
if (cmd) {
|
||||
cmd = cmd + 'printf "\n"';
|
||||
exec(cmd, function (error, stdout) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
lines.forEach(line => {
|
||||
if (line) {
|
||||
let parts = line.split('|');
|
||||
if (parts.length === 2) {
|
||||
let BSDName = parts[0];
|
||||
parts[1] = parts[1].trim();
|
||||
let parts2 = parts[1].split(':');
|
||||
if (parts2.length === 2) {
|
||||
parts2[1] = parts2[1].trim();
|
||||
let status = parts2[1].toLowerCase();
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
if (result[i].BSDName === BSDName) {
|
||||
result[i].smartStatus = (status === 'passed' ? 'Ok' : (status === 'failed!' ? 'Predicted Failure' : 'unknown'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
delete result[i].BSDName;
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
} else {
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
delete result[i].BSDName;
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_freebsd || _openbsd) {
|
||||
@@ -673,6 +714,7 @@ function diskLayout(callback) {
|
||||
let lines = device.split('\n');
|
||||
const mediumType = util.getValue(lines, 'Medium Type', ':', true).trim();
|
||||
const sizeStr = util.getValue(lines, 'capacity', ':', true).trim();
|
||||
const BSDName = util.getValue(lines, 'BSD Name', ':', true).trim();
|
||||
if (sizeStr) {
|
||||
let sizeValue = 0;
|
||||
if (sizeStr.indexOf('(') >= 0) {
|
||||
@@ -696,8 +738,11 @@ function diskLayout(callback) {
|
||||
sectorsPerTrack: -1,
|
||||
firmwareRevision: util.getValue(lines, 'Revision', ':', true).trim(),
|
||||
serialNum: util.getValue(lines, 'Serial Number', ':', true).trim(),
|
||||
interfaceType: util.getValue(lines, 'InterfaceType', ':', true).trim()
|
||||
interfaceType: util.getValue(lines, 'InterfaceType', ':', true).trim(),
|
||||
smartStatus: 'unknown',
|
||||
BSDName: BSDName
|
||||
});
|
||||
cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;';
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -709,6 +754,7 @@ function diskLayout(callback) {
|
||||
let lines = device.split('\n');
|
||||
const linkWidth = util.getValue(lines, 'link width', ':', true).trim();
|
||||
const sizeStr = util.getValue(lines, '!capacity', ':', true).trim();
|
||||
const BSDName = util.getValue(lines, 'BSD Name', ':', true).trim();
|
||||
if (sizeStr) {
|
||||
let sizeValue = 0;
|
||||
if (sizeStr.indexOf('(') >= 0) {
|
||||
@@ -733,16 +779,55 @@ function diskLayout(callback) {
|
||||
firmwareRevision: util.getValue(lines, 'Revision', ':', true).trim(),
|
||||
serialNum: util.getValue(lines, 'Serial Number', ':', true).trim(),
|
||||
interfaceType: ('PCIe ' + linkWidth).trim(),
|
||||
smartStatus: 'unknown',
|
||||
BSDName: BSDName
|
||||
});
|
||||
cmd = cmd + 'printf "\n' + BSDName + '|"; diskutil info /dev/' + BSDName + ' | grep SMART;';
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
if (cmd) {
|
||||
cmd = cmd + 'printf "\n"';
|
||||
exec(cmd, function (error, stdout) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
lines.forEach(line => {
|
||||
if (line) {
|
||||
let parts = line.split('|');
|
||||
if (parts.length === 2) {
|
||||
let BSDName = parts[0];
|
||||
parts[1] = parts[1].trim();
|
||||
let parts2 = parts[1].split(':');
|
||||
if (parts2.length === 2) {
|
||||
parts2[1] = parts2[1].trim();
|
||||
let status = parts2[1].toLowerCase();
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
if (result[i].BSDName === BSDName) {
|
||||
result[i].smartStatus = (status === 'not supported' ? 'not supported' : (status === 'verified' ? 'Ok' : (status === 'failing' ? 'Predicted Failure' : 'unknown')));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
delete result[i].BSDName;
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
} else {
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
delete result[i].BSDName;
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
@@ -753,6 +838,7 @@ function diskLayout(callback) {
|
||||
devices.forEach(function (device) {
|
||||
let lines = device.split('\r\n');
|
||||
const size = util.getValue(lines, 'Size', '=').trim();
|
||||
const status = util.getValue(lines, 'Status', '=').trim();
|
||||
if (size) {
|
||||
result.push({
|
||||
type: device.indexOf('SSD') > -1 ? 'SSD' : 'HD', // not really correct(!) ... maybe this one is better: MSFT_PhysicalDisk - Media Type??
|
||||
@@ -768,7 +854,8 @@ function diskLayout(callback) {
|
||||
sectorsPerTrack: parseInt(util.getValue(lines, 'SectorsPerTrack', '=')),
|
||||
firmwareRevision: util.getValue(lines, 'FirmwareRevision', '=').trim(),
|
||||
serialNum: util.getValue(lines, 'SerialNumber', '=').trim(),
|
||||
interfaceType: util.getValue(lines, 'InterfaceType', '=').trim()
|
||||
interfaceType: util.getValue(lines, 'InterfaceType', '=').trim(),
|
||||
smartStatus: (status === 'Ok' ? 'Ok' : (status === 'Degraded' ? 'Degraded' : (status === 'Pred Fail' ? 'Predicted Failure' : 'Unknown')))
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user