blockDevices() added groups for raid (linux)
This commit is contained in:
parent
e3ae94bb40
commit
c544e80c20
@ -88,7 +88,6 @@ function fsSize(callback) {
|
|||||||
const use = parseFloat((100.0 * (used / (used + available))).toFixed(2));
|
const use = parseFloat((100.0 * (used / (used + available))).toFixed(2));
|
||||||
line.splice(0, (_linux || _freebsd || _openbsd || _netbsd) ? 6 : 5);
|
line.splice(0, (_linux || _freebsd || _openbsd || _netbsd) ? 6 : 5);
|
||||||
const mount = line.join(' ');
|
const mount = line.join(' ');
|
||||||
// const mount = line[line.length - 1];
|
|
||||||
if (!data.find(el => (el.fs === fs && el.type === fsType))) {
|
if (!data.find(el => (el.fs === fs && el.type === fsType))) {
|
||||||
data.push({
|
data.push({
|
||||||
fs,
|
fs,
|
||||||
@ -121,7 +120,7 @@ function fsSize(callback) {
|
|||||||
macOsDisks = [];
|
macOsDisks = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_linux) { cmd = 'df -lkPTx squashfs'; } // cmd = 'df -lkPTx squashfs | grep -E "^/|^.\\:"';
|
if (_linux) { cmd = 'df -lkPTx squashfs'; }
|
||||||
if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; }
|
if (_freebsd || _openbsd || _netbsd) { cmd = 'df -lkPT'; }
|
||||||
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
exec(cmd, { maxBuffer: 1024 * 1024 }, function (error, stdout) {
|
||||||
let lines = filterLines(stdout);
|
let lines = filterLines(stdout);
|
||||||
@ -343,7 +342,7 @@ function parseBlk(lines) {
|
|||||||
'serial': disk.serial,
|
'serial': disk.serial,
|
||||||
'removable': disk.rm === '1',
|
'removable': disk.rm === '1',
|
||||||
'protocol': disk.tran,
|
'protocol': disk.tran,
|
||||||
'group': disk.group,
|
'group': disk.group || '',
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
util.noop();
|
util.noop();
|
||||||
@ -354,6 +353,41 @@ function parseBlk(lines) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decodeMdabmData(lines) {
|
||||||
|
const raid = util.getValue(lines, 'md_level', '=');
|
||||||
|
const members = [];
|
||||||
|
lines.forEach(line => {
|
||||||
|
if (line.toLowerCase().startsWith('md_device_ev') && line.toLowerCase().indexOf('/dev/') > 0) {
|
||||||
|
members.push(line.split('/dev/')[1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
raid,
|
||||||
|
members
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function raidMatchLunix(data) {
|
||||||
|
// for all block devices of type "raid%"
|
||||||
|
try {
|
||||||
|
data.forEach(element => {
|
||||||
|
if (element.type.startsWith('raid')) {
|
||||||
|
const lines = execSync(`mdadm --export --detail /dev/${element.name}`).toString().split('\n');
|
||||||
|
const mdData = decodeMdabmData(lines);
|
||||||
|
if (mdData && mdData.members && mdData.members.length && mdData.raid === element.type) {
|
||||||
|
data.forEach(blockdevice => {
|
||||||
|
if (blockDevices.fsType === 'linux_raid_member' && mdData.members.indexOf(blockdevice.name) >= 0) {
|
||||||
|
blockdevice.group = element.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
util.noop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function blkStdoutToObject(stdout) {
|
function blkStdoutToObject(stdout) {
|
||||||
return stdout.toString()
|
return stdout.toString()
|
||||||
.replace(/NAME=/g, '{"name":')
|
.replace(/NAME=/g, '{"name":')
|
||||||
@ -386,6 +420,7 @@ function blockDevices(callback) {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = blkStdoutToObject(stdout).split('\n');
|
let lines = blkStdoutToObject(stdout).split('\n');
|
||||||
data = parseBlk(lines);
|
data = parseBlk(lines);
|
||||||
|
raidMatchLunix(data);
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(data);
|
callback(data);
|
||||||
}
|
}
|
||||||
@ -395,6 +430,7 @@ function blockDevices(callback) {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
let lines = blkStdoutToObject(stdout).split('\n');
|
let lines = blkStdoutToObject(stdout).split('\n');
|
||||||
data = parseBlk(lines);
|
data = parseBlk(lines);
|
||||||
|
raidMatchLunix(data);
|
||||||
}
|
}
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(data);
|
callback(data);
|
||||||
|
|||||||
1
lib/index.d.ts
vendored
1
lib/index.d.ts
vendored
@ -456,6 +456,7 @@ export namespace Systeminformation {
|
|||||||
serial: string;
|
serial: string;
|
||||||
removable: boolean;
|
removable: boolean;
|
||||||
protocol: string;
|
protocol: string;
|
||||||
|
group?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FsStatsData {
|
interface FsStatsData {
|
||||||
|
|||||||
14
lib/users.js
14
lib/users.js
@ -209,7 +209,6 @@ function users(callback) {
|
|||||||
try {
|
try {
|
||||||
let cmd = 'Get-CimInstance Win32_LogonSession | select LogonId,@{n="StartTime";e={$_.StartTime.ToString("yyyy-MM-dd HH:mm:ss")}} | fl' + '; echo \'#-#-#-#\';';
|
let cmd = 'Get-CimInstance Win32_LogonSession | select LogonId,@{n="StartTime";e={$_.StartTime.ToString("yyyy-MM-dd HH:mm:ss")}} | fl' + '; echo \'#-#-#-#\';';
|
||||||
cmd += 'Get-CimInstance Win32_LoggedOnUser | select antecedent,dependent | fl ' + '; echo \'#-#-#-#\';';
|
cmd += 'Get-CimInstance Win32_LoggedOnUser | select antecedent,dependent | fl ' + '; echo \'#-#-#-#\';';
|
||||||
// cmd += `Get-CimInstance Win32_Process -Filter 'name="explorer.exe"' | Select @{Name="sessionid";Expression={$_.SessionId}}, @{Name="domain";Expression={$_.GetOwner().Domain}}, @{Name="username";Expression={$_.GetOwner().User}} | fl` + '; echo \'#-#-#-#\';';
|
|
||||||
cmd += '$process = (Get-CimInstance Win32_Process -Filter "name = \'explorer.exe\'"); Invoke-CimMethod -InputObject $process -MethodName GetOwner | select user, domain | fl; get-process -name explorer | select-object sessionid | fl; echo \'#-#-#-#\';';
|
cmd += '$process = (Get-CimInstance Win32_Process -Filter "name = \'explorer.exe\'"); Invoke-CimMethod -InputObject $process -MethodName GetOwner | select user, domain | fl; get-process -name explorer | select-object sessionid | fl; echo \'#-#-#-#\';';
|
||||||
cmd += 'query user';
|
cmd += 'query user';
|
||||||
util.powerShell(cmd).then((data) => {
|
util.powerShell(cmd).then((data) => {
|
||||||
@ -257,17 +256,6 @@ function users(callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// function parseWinAccounts(accountParts) {
|
|
||||||
// const accounts = [];
|
|
||||||
// accountParts.forEach(account => {
|
|
||||||
// const lines = account.split('\r\n');
|
|
||||||
// const name = util.getValue(lines, 'name', ':', true);
|
|
||||||
// const domain = util.getValue(lines, 'domain', ':', true);
|
|
||||||
// accounts.push(`${domain}\${name}`);
|
|
||||||
// });
|
|
||||||
// return accounts;
|
|
||||||
// }
|
|
||||||
|
|
||||||
function parseWinSessions(sessionParts) {
|
function parseWinSessions(sessionParts) {
|
||||||
const sessions = {};
|
const sessions = {};
|
||||||
sessionParts.forEach(session => {
|
sessionParts.forEach(session => {
|
||||||
@ -325,7 +313,7 @@ function parseWinLoggedOn(loggedonParts) {
|
|||||||
const antecendent = util.getValue(lines, 'antecedent', ':', true);
|
const antecendent = util.getValue(lines, 'antecedent', ':', true);
|
||||||
let parts = antecendent.split('=');
|
let parts = antecendent.split('=');
|
||||||
const name = parts.length > 2 ? parts[1].split(',')[0].replace(/"/g, '').trim() : '';
|
const name = parts.length > 2 ? parts[1].split(',')[0].replace(/"/g, '').trim() : '';
|
||||||
const domain = parts.length > 2 ? parts[2].replace(/"/g, '').trim() : '';
|
const domain = parts.length > 2 ? parts[2].replace(/"/g, '').replace(/\)/g, '').trim() : '';
|
||||||
const dependent = util.getValue(lines, 'dependent', ':', true);
|
const dependent = util.getValue(lines, 'dependent', ':', true);
|
||||||
parts = dependent.split('=');
|
parts = dependent.split('=');
|
||||||
const id = parts.length > 1 ? parts[1].replace(/"/g, '').replace(/\)/g, '').trim() : '';
|
const id = parts.length > 1 ? parts[1].replace(/"/g, '').replace(/\)/g, '').trim() : '';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user