From 1fea44f1fcffb644302a772285942aa44f6fb35b Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 29 Jun 2021 14:04:44 +0000 Subject: [server/registration] Adjust hw collection parsing to the new scheme (edid restruct to keys and group by drives) --- server/api/registration.js | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/server/api/registration.js b/server/api/registration.js index 8487577..e1a37ad 100644 --- a/server/api/registration.js +++ b/server/api/registration.js @@ -587,7 +587,7 @@ async function parseHardwareInformation (data) { } /* Smartctl */ - for (let key in data.smartctl) { + for (let key in data.drives) { let drive = { 'model': '', 'family': '', // NEW @@ -602,9 +602,12 @@ async function parseHardwareInformation (data) { } let units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'] + const driveData = data.drives[key] + const smartctl = driveData.smartctl + /* Figure out if it's HDD, SSD or CD/DVD-ROM */ - if (data.smartctl[key]['user_capacity']) { - let capacity = data.smartctl[key]['user_capacity']['bytes'] + if (smartctl['user_capacity']) { + let capacity = smartctl['user_capacity']['bytes'] let unitcounter = 0 while (capacity > 1000) { if (unitcounter + 1 <= units.length) { @@ -615,31 +618,31 @@ async function parseHardwareInformation (data) { drive['capacity'] = Math.round(capacity) drive['unit'] = units[unitcounter] - if (data.smartctl[key]['rotation_rate']) { - if (data.smartctl[key]['rotation_rate'] > 0) { + if (smartctl['rotation_rate']) { + if (smartctl['rotation_rate'] > 0) { drive['type'] = 'HDD' - } else if (data.smartctl[key]['rotation_rate'] === 0) { + } else if (smartctl['rotation_rate'] === 0) { drive['type'] = 'SSD' } } } else { const regexCDDVD = /\/dev\/sr[0-9]+/ // Seems to be a CD/DVD-ROM - if (data.smartctl[key]['readlink'].match(regexCDDVD)) drive['type'] = 'CD/DVD-ROM' + if (driveData.readlink.match(regexCDDVD)) drive['type'] = 'CD/DVD-ROM' else drive['type'] = 'UNKNOWN' } - if (data.smartctl[key]['form_factor']) drive['formfactor'] = data.smartctl[key]['form_factor'].name - if (data.smartctl[key]['sata_version']) drive['connection'] = data.smartctl[key]['sata_version'].string - if (data.smartctl[key]['interface_speed']) { - if (data.smartctl[key]['interface_speed'].current) drive['connection_speed'] = data.smartctl[key]['interface_speed'].current.string - else if (data.smartctl[key]['interface_speed'].max) drive['connection_speed'] = data.smartctl[key]['interface_speed'].max.string + if (smartctl['form_factor']) drive['formfactor'] = smartctl['form_factor'].name + if (smartctl['sata_version']) drive['connection'] = smartctl['sata_version'].string + if (smartctl['interface_speed']) { + if (smartctl['interface_speed'].current) drive['connection_speed'] = smartctl['interface_speed'].current.string + else if (smartctl['interface_speed'].max) drive['connection_speed'] = smartctl['interface_speed'].max.string } - if (data.smartctl[key]['model_name']) drive.model = data.smartctl[key]['model_name'] - if (data.smartctl[key]['model_family']) drive.family = data.smartctl[key]['model_family'] - if (data.smartctl[key]['serial_number']) drive.serial = data.smartctl[key]['serial_number'] - if (data.smartctl[key]['firmware_version']) drive.firmware = data.smartctl[key]['firmware_version'] + if (smartctl['model_name']) drive.model = smartctl['model_name'] + if (smartctl['model_family']) drive.family = smartctl['model_family'] + if (smartctl['serial_number']) drive.serial = smartctl['serial_number'] + if (smartctl['firmware_version']) drive.firmware = smartctl['firmware_version'] client.drives.push(drive) } @@ -692,14 +695,15 @@ async function parseHardwareInformation (data) { } /* edid */ - for (let rawEdid of data.edid) { + for (let port in data.edid) { + const rawEdid = data.edid[port] const edid = EdidReader.parse(rawEdid.edid) client.monitors.push({ model: edid.modelName, vendor: edid.vendor, serialnumber: edid.serialNumber, modes: edid.standardDisplayModes, - port: rawEdid.path.split('/')[4].substring(6), + port: port, resolution: { width: edid.dtds[0].horActivePixels, height: edid.dtds[0].vertActivePixels -- cgit v1.2.3-55-g7522