blockDevices() added device property
This commit is contained in:
parent
7b339a5a74
commit
2893a47d18
@ -293,7 +293,9 @@ function parseDevices(lines) {
|
|||||||
model: '',
|
model: '',
|
||||||
serial: '',
|
serial: '',
|
||||||
removable: false,
|
removable: false,
|
||||||
protocol: ''
|
protocol: '',
|
||||||
|
group: '',
|
||||||
|
device: ''
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
parts[0] = parts[0].trim().toUpperCase().replace(/ +/g, '');
|
parts[0] = parts[0].trim().toUpperCase().replace(/ +/g, '');
|
||||||
@ -391,6 +393,105 @@ function raidMatchLinux(data) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDevicesLinux(data) {
|
||||||
|
const result = [];
|
||||||
|
data.forEach(element => {
|
||||||
|
if (element.type.startsWith('disk')) {
|
||||||
|
result.push(element.name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchDevicesLinux(data) {
|
||||||
|
let result = data;
|
||||||
|
try {
|
||||||
|
const devices = getDevicesLinux(data);
|
||||||
|
result = result.map(blockdevice => {
|
||||||
|
if (blockdevice.type.startsWith('part') || blockdevice.type.startsWith('disk')) {
|
||||||
|
devices.forEach(element => {
|
||||||
|
if (blockdevice.name.startsWith(element)) {
|
||||||
|
blockdevice.device = '/dev/' + element;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return blockdevice;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
util.noop();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDevicesMac(data) {
|
||||||
|
const result = [];
|
||||||
|
data.forEach(element => {
|
||||||
|
if (element.type.startsWith('disk')) {
|
||||||
|
result.push({ name: element.name, model: element.model, device: element.name });
|
||||||
|
}
|
||||||
|
if (element.type.startsWith('virtual')) {
|
||||||
|
let device = '';
|
||||||
|
result.forEach(e => {
|
||||||
|
if (e.model === element.model) {
|
||||||
|
device = e.device;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (device) {
|
||||||
|
result.push({ name: element.name, model: element.model, device });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchDevicesMac(data) {
|
||||||
|
let result = data;
|
||||||
|
try {
|
||||||
|
const devices = getDevicesMac(data);
|
||||||
|
result = result.map(blockdevice => {
|
||||||
|
if (blockdevice.type.startsWith('part') || blockdevice.type.startsWith('disk') || blockdevice.type.startsWith('virtual')) {
|
||||||
|
devices.forEach(element => {
|
||||||
|
if (blockdevice.name.startsWith(element.name)) {
|
||||||
|
blockdevice.device = element.device;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return blockdevice;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
util.noop();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDevicesWin(diskDrives) {
|
||||||
|
const result = [];
|
||||||
|
diskDrives.forEach(element => {
|
||||||
|
const lines = element.split('\r\n');
|
||||||
|
const device = util.getValue(lines, 'DeviceID', ':');
|
||||||
|
let partitions = element.split('@{DeviceID=');
|
||||||
|
if (partitions.length > 1) {
|
||||||
|
partitions = partitions.slice(1);
|
||||||
|
partitions.forEach(partition => {
|
||||||
|
result.push({ name: partition.split(';').toUpperCase(), device });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchDevicesWin(data, diskDrives) {
|
||||||
|
const devices = getDevicesWin(diskDrives);
|
||||||
|
data.map(element => {
|
||||||
|
const filteresDevices = devices.filter((e) => { return e.name === element.name.toUpperCase(); });
|
||||||
|
if (filteresDevices.length > 0) {
|
||||||
|
element.device = filteresDevices[0].device;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
function blkStdoutToObject(stdout) {
|
function blkStdoutToObject(stdout) {
|
||||||
return stdout.toString()
|
return stdout.toString()
|
||||||
.replace(/NAME=/g, '{"name":')
|
.replace(/NAME=/g, '{"name":')
|
||||||
@ -424,6 +525,7 @@ function blockDevices(callback) {
|
|||||||
let lines = blkStdoutToObject(stdout).split('\n');
|
let lines = blkStdoutToObject(stdout).split('\n');
|
||||||
data = parseBlk(lines);
|
data = parseBlk(lines);
|
||||||
data = raidMatchLinux(data);
|
data = raidMatchLinux(data);
|
||||||
|
data = matchDevicesLinux(data);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(data);
|
callback(data);
|
||||||
}
|
}
|
||||||
@ -449,6 +551,7 @@ function blockDevices(callback) {
|
|||||||
let lines = stdout.toString().split('\n');
|
let lines = stdout.toString().split('\n');
|
||||||
// parse lines into temp array of devices
|
// parse lines into temp array of devices
|
||||||
data = parseDevices(lines);
|
data = parseDevices(lines);
|
||||||
|
data = matchDevicesMac(data);
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(data);
|
callback(data);
|
||||||
@ -465,31 +568,39 @@ function blockDevices(callback) {
|
|||||||
try {
|
try {
|
||||||
// util.wmic('logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value').then((stdout, error) => {
|
// util.wmic('logicaldisk get Caption,Description,DeviceID,DriveType,FileSystem,FreeSpace,Name,Size,VolumeName,VolumeSerialNumber /value').then((stdout, error) => {
|
||||||
// util.powerShell('Get-CimInstance Win32_logicaldisk | select Caption,DriveType,Name,FileSystem,Size,VolumeSerialNumber,VolumeName | fl').then((stdout, error) => {
|
// util.powerShell('Get-CimInstance Win32_logicaldisk | select Caption,DriveType,Name,FileSystem,Size,VolumeSerialNumber,VolumeName | fl').then((stdout, error) => {
|
||||||
util.powerShell('Get-CimInstance -ClassName Win32_LogicalDisk | select Caption,DriveType,Name,FileSystem,Size,VolumeSerialNumber,VolumeName | fl').then((stdout, error) => {
|
const workload = [];
|
||||||
if (!error) {
|
workload.push(util.powerShell('Get-CimInstance -ClassName Win32_LogicalDisk | select Caption,DriveType,Name,FileSystem,Size,VolumeSerialNumber,VolumeName | fl'));
|
||||||
let devices = stdout.toString().split(/\n\s*\n/);
|
workload.push(util.powerShell('Get-WmiObject -Class Win32_diskdrive | Select-Object -Property PNPDeviceId,DeviceID, Model, Size, @{L=\'Partitions\'; E={$_.GetRelated(\'Win32_DiskPartition\').GetRelated(\'Win32_LogicalDisk\') | Select-Object -Property DeviceID, VolumeName, Size, FreeSpace}} | fl'));
|
||||||
devices.forEach(function (device) {
|
util.promiseAll(
|
||||||
let lines = device.split('\r\n');
|
workload
|
||||||
let drivetype = util.getValue(lines, 'drivetype', ':');
|
).then((res) => {
|
||||||
if (drivetype) {
|
let logicalDisks = res.results[0].toString().split(/\n\s*\n/);
|
||||||
data.push({
|
let diskDrives = res.results[1].toString().split(/\n\s*\n/);
|
||||||
name: util.getValue(lines, 'name', ':'),
|
logicalDisks.forEach(function (device) {
|
||||||
identifier: util.getValue(lines, 'caption', ':'),
|
let lines = device.split('\r\n');
|
||||||
type: 'disk',
|
let drivetype = util.getValue(lines, 'drivetype', ':');
|
||||||
fsType: util.getValue(lines, 'filesystem', ':').toLowerCase(),
|
if (drivetype) {
|
||||||
mount: util.getValue(lines, 'caption', ':'),
|
data.push({
|
||||||
size: util.getValue(lines, 'size', ':'),
|
name: util.getValue(lines, 'name', ':'),
|
||||||
physical: (drivetype >= 0 && drivetype <= 6) ? drivetypes[drivetype] : drivetypes[0],
|
identifier: util.getValue(lines, 'caption', ':'),
|
||||||
uuid: util.getValue(lines, 'volumeserialnumber', ':'),
|
type: 'disk',
|
||||||
label: util.getValue(lines, 'volumename', ':'),
|
fsType: util.getValue(lines, 'filesystem', ':').toLowerCase(),
|
||||||
model: '',
|
mount: util.getValue(lines, 'caption', ':'),
|
||||||
serial: util.getValue(lines, 'volumeserialnumber', ':'),
|
size: util.getValue(lines, 'size', ':'),
|
||||||
removable: drivetype === '2',
|
physical: (drivetype >= 0 && drivetype <= 6) ? drivetypes[drivetype] : drivetypes[0],
|
||||||
protocol: ''
|
uuid: util.getValue(lines, 'volumeserialnumber', ':'),
|
||||||
});
|
label: util.getValue(lines, 'volumename', ':'),
|
||||||
}
|
model: '',
|
||||||
});
|
serial: util.getValue(lines, 'volumeserialnumber', ':'),
|
||||||
}
|
removable: drivetype === '2',
|
||||||
|
protocol: '',
|
||||||
|
group: '',
|
||||||
|
device: ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// match devices
|
||||||
|
data = matchDevicesWin(data, diskDrives);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(data);
|
callback(data);
|
||||||
}
|
}
|
||||||
@ -1232,7 +1343,7 @@ function diskLayout(callback) {
|
|||||||
if (_windows) {
|
if (_windows) {
|
||||||
try {
|
try {
|
||||||
const workload = [];
|
const workload = [];
|
||||||
workload.push(util.powerShell('Get-CimInstance Win32_DiskDrive | select Caption,Size,Status,PNPDeviceId,BytesPerSector,TotalCylinders,TotalHeads,TotalSectors,TotalTracks,TracksPerCylinder,SectorsPerTrack,FirmwareRevision,SerialNumber,InterfaceType | fl'));
|
workload.push(util.powerShell('Get-CimInstance Win32_DiskDrive | select Caption,Size,Status,PNPDeviceId,DeviceId,BytesPerSector,TotalCylinders,TotalHeads,TotalSectors,TotalTracks,TracksPerCylinder,SectorsPerTrack,FirmwareRevision,SerialNumber,InterfaceType | fl'));
|
||||||
workload.push(util.powerShell('Get-PhysicalDisk | select BusType,MediaType,FriendlyName,Model,SerialNumber,Size | fl'));
|
workload.push(util.powerShell('Get-PhysicalDisk | select BusType,MediaType,FriendlyName,Model,SerialNumber,Size | fl'));
|
||||||
if (util.smartMonToolsInstalled()) {
|
if (util.smartMonToolsInstalled()) {
|
||||||
try {
|
try {
|
||||||
@ -1256,7 +1367,7 @@ function diskLayout(callback) {
|
|||||||
const status = util.getValue(lines, 'Status', ':').trim().toLowerCase();
|
const status = util.getValue(lines, 'Status', ':').trim().toLowerCase();
|
||||||
if (size) {
|
if (size) {
|
||||||
result.push({
|
result.push({
|
||||||
device: util.getValue(lines, 'PNPDeviceId', ':'),
|
device: util.getValue(lines, 'DeviceId', ':'), // changed from PNPDeviceId to DeviceID (be be able to match devices)
|
||||||
type: device.indexOf('SSD') > -1 ? 'SSD' : 'HD', // just a starting point ... better: MSFT_PhysicalDisk - Media Type ... see below
|
type: device.indexOf('SSD') > -1 ? 'SSD' : 'HD', // just a starting point ... better: MSFT_PhysicalDisk - Media Type ... see below
|
||||||
name: util.getValue(lines, 'Caption', ':'),
|
name: util.getValue(lines, 'Caption', ':'),
|
||||||
vendor: getVendorFromModel(util.getValue(lines, 'Caption', ':', true).trim()),
|
vendor: getVendorFromModel(util.getValue(lines, 'Caption', ':', true).trim()),
|
||||||
|
|||||||
1
lib/index.d.ts
vendored
1
lib/index.d.ts
vendored
@ -457,6 +457,7 @@ export namespace Systeminformation {
|
|||||||
removable: boolean;
|
removable: boolean;
|
||||||
protocol: string;
|
protocol: string;
|
||||||
group?: string;
|
group?: string;
|
||||||
|
device?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FsStatsData {
|
interface FsStatsData {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user