mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
Fix issue rendering hosts with unexpected CPU brand string (#1606)
- Hosts with unexpected CPU brand string render properly - Other unexpected host CPU information renders properly - Add tests for host CPU parsing Fixes #1604
This commit is contained in:
parent
a0909e6bee
commit
c769bd45a1
3 changed files with 58 additions and 7 deletions
|
|
@ -1,3 +1,5 @@
|
|||
* Fixed bug rendering hosts when clock speed cannot be parsed.
|
||||
|
||||
## Kolide Fleet 1.0.5 (Oct 17, 2017)
|
||||
|
||||
* Renamed the binary from kolide to fleet
|
||||
|
|
|
|||
|
|
@ -4,14 +4,21 @@ export const parseEntityFunc = (host) => {
|
|||
const { network_interfaces: networkInterfaces } = host;
|
||||
const networkInterface = networkInterfaces && find(networkInterfaces, { id: host.primary_ip_id });
|
||||
|
||||
let clockSpeed = null;
|
||||
let clockSpeedFlt = null;
|
||||
let hostCpuOutput = null;
|
||||
|
||||
if (host && host.cpu_brand) {
|
||||
clockSpeed = host.cpu_brand.split('@ ')[1] || host.cpu_brand.split('@')[1];
|
||||
clockSpeedFlt = parseFloat(clockSpeed.split('GHz')[0].trim());
|
||||
hostCpuOutput = `${host.cpu_physical_cores} x ${Math.floor(clockSpeedFlt * 10) / 10} GHz`;
|
||||
if (host) {
|
||||
let clockSpeedOutput = null;
|
||||
try {
|
||||
const clockSpeed = host.cpu_brand.split('@ ')[1] || host.cpu_brand.split('@')[1];
|
||||
const clockSpeedFlt = parseFloat(clockSpeed.split('GHz')[0].trim());
|
||||
clockSpeedOutput = Math.floor(clockSpeedFlt * 10) / 10;
|
||||
} catch (e) {
|
||||
// Some CPU brand strings do not fit this format and we can't parse the
|
||||
// clock speed. Leave it set to 'Unknown'.
|
||||
console.log(`Unable to parse clock speed from cpu_brand: ${host.cpu_brand}`);
|
||||
}
|
||||
if (host.cpu_physical_cores || clockSpeedOutput) {
|
||||
hostCpuOutput = `${host.cpu_physical_cores || 'Unknown'} x ${clockSpeedOutput || 'Unknown'} GHz`;
|
||||
}
|
||||
}
|
||||
|
||||
const additionalAttrs = {
|
||||
|
|
|
|||
42
frontend/redux/nodes/entities/hosts/helpers.tests.js
Normal file
42
frontend/redux/nodes/entities/hosts/helpers.tests.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import expect from 'expect';
|
||||
|
||||
import { parseEntityFunc } from './helpers';
|
||||
|
||||
describe('reduxConfig - hosts helpers', () => {
|
||||
describe('parseEntityFunc', () => {
|
||||
it('parses an expected CPU string', () => {
|
||||
const host = {
|
||||
cpu_brand: 'Intel(R) Xeon(R) CPU E5-2420 0 @ 1.90GHz',
|
||||
cpu_physical_cores: 2,
|
||||
};
|
||||
expect(parseEntityFunc(host).host_cpu).toEqual('2 x 1.9 GHz');
|
||||
});
|
||||
|
||||
it('parses a host missing clock speed', () => {
|
||||
const host = {
|
||||
cpu_brand: 'Intel(R) Xeon(R) CPU E5-242',
|
||||
cpu_physical_cores: 2,
|
||||
};
|
||||
expect(parseEntityFunc(host).host_cpu).toEqual('2 x Unknown GHz');
|
||||
});
|
||||
|
||||
it('parses a host missing CPU brand', () => {
|
||||
const host = {
|
||||
cpu_physical_cores: 2,
|
||||
};
|
||||
expect(parseEntityFunc(host).host_cpu).toEqual('2 x Unknown GHz');
|
||||
});
|
||||
|
||||
it('parses a host missing CPU cores', () => {
|
||||
const host = {
|
||||
cpu_brand: 'Intel(R) Xeon(R) CPU E5-2420 0 @ 1.90GHz',
|
||||
};
|
||||
expect(parseEntityFunc(host).host_cpu).toEqual('Unknown x 1.9 GHz');
|
||||
});
|
||||
|
||||
it('parses a host missing CPU info entirely', () => {
|
||||
const host = {};
|
||||
expect(parseEntityFunc(host).host_cpu).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue