Skip to content

Commit

Permalink
Add IP addresses netmask discovery and visualization (#2793)
Browse files Browse the repository at this point in the history
* Discover agent network interfaces

* Use simplied version of host payload with netmasks

* Add netmask field and projection to host read model

* Update host frontend views to combine netmask with ip address

* Update e2e fixtures

* Add netmasks to scenarios

* Export function to build cidr notation address

* Add missing netmask in scenario
  • Loading branch information
arbulu89 authored Jul 22, 2024
1 parent 503b750 commit a16f5f1
Show file tree
Hide file tree
Showing 78 changed files with 652 additions and 76 deletions.
27 changes: 27 additions & 0 deletions assets/js/lib/test-utils/data/hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default [
hostname: 'vmdrbddev01',
id: '240f96b1-8d26-53b7-9e99-ffb0f2e735bf',
ip_addresses: ['10.100.1.31', '10.100.1.33'],
netmasks: [24, 32],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -119,6 +120,7 @@ export default [
hostname: 'vmdrbddev02',
id: '21de186a-e38f-5804-b643-7f4ef22fecfd',
ip_addresses: ['10.100.1.32'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -232,6 +234,7 @@ export default [
hostname: 'vmdrbdprd01',
id: 'a09d9cf3-46c1-505c-8fb8-4b0a71a9114e',
ip_addresses: ['10.80.1.31', '10.80.1.33'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -345,6 +348,7 @@ export default [
hostname: 'vmdrbdprd02',
id: '927901fa-2c87-524e-b18c-3ef5187f504f',
ip_addresses: ['10.80.1.32'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -458,6 +462,7 @@ export default [
hostname: 'vmdrbdqas01',
id: 'ddcb7992-2ffb-5c10-8b39-80685f6eaaba',
ip_addresses: ['10.90.1.31', '10.90.1.33'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -571,6 +576,7 @@ export default [
hostname: 'vmdrbdqas02',
id: '422686d6-b2d1-5092-93e8-a744854f5085',
ip_addresses: ['10.90.1.32'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -684,6 +690,7 @@ export default [
hostname: 'vmhdbdev01',
id: '13e8c25c-3180-5a9a-95c8-51ec38e50cfc',
ip_addresses: ['10.100.1.11', '10.100.1.13'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -797,6 +804,7 @@ export default [
hostname: 'vmhdbdev02',
id: '0a055c90-4cb6-54ce-ac9c-ae3fedaf40d4',
ip_addresses: ['10.100.1.12'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -910,6 +918,7 @@ export default [
hostname: 'vmhdbprd01',
id: '9cd46919-5f19-59aa-993e-cf3736c71053',
ip_addresses: ['10.80.1.11', '10.80.1.13'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1023,6 +1032,7 @@ export default [
hostname: 'vmhdbprd02',
id: 'b767b3e9-e802-587e-a442-541d093b86b9',
ip_addresses: ['10.80.1.12'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1136,6 +1146,7 @@ export default [
hostname: 'vmhdbqas01',
id: '99cf8a3a-48d6-57a4-b302-6e4482227ab6',
ip_addresses: ['10.90.1.11', '10.90.1.13'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1249,6 +1260,7 @@ export default [
hostname: 'vmhdbqas02',
id: 'e0c182db-32ff-55c6-a9eb-2b82dd21bc8b',
ip_addresses: ['10.90.1.12'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1362,6 +1374,7 @@ export default [
hostname: 'vmiscsi01',
id: '69f4dcbb-efa2-5a16-8bc8-01df7dbb7384',
ip_addresses: ['10.100.1.4'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1475,6 +1488,7 @@ export default [
hostname: 'vmiscsi01',
id: '9a26b6d0-6e72-597c-9fe5-152a6875f214',
ip_addresses: ['10.80.1.4'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1588,6 +1602,7 @@ export default [
hostname: 'vmiscsi01',
id: 'f0c808b3-d869-5192-a944-20f66a6a8449',
ip_addresses: ['10.90.1.4'],
netmasks: [24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1701,6 +1716,7 @@ export default [
hostname: 'vmnwdev01',
id: '7269ee51-5007-5849-aaa7-7c4a98b0c9ce',
ip_addresses: ['10.100.1.21', '10.100.1.25'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1814,6 +1830,7 @@ export default [
hostname: 'vmnwdev02',
id: 'fb2c6b8a-9915-5969-a6b7-8b5a42de1971',
ip_addresses: ['10.100.1.22', '10.100.1.26'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -1927,6 +1944,7 @@ export default [
hostname: 'vmnwdev03',
id: '9a3ec76a-dd4f-5013-9cf0-5eb4cf89898f',
ip_addresses: ['10.100.1.23', '10.100.1.27'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -2040,6 +2058,7 @@ export default [
hostname: 'vmnwdev04',
id: '1b0e9297-97dd-55d6-9874-8efde4d84c90',
ip_addresses: ['10.100.1.24', '10.100.1.28'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -2153,6 +2172,7 @@ export default [
hostname: 'vmnwprd01',
id: '116d49bd-85e1-5e59-b820-83f66db8800c',
ip_addresses: ['10.80.1.21', '10.80.1.25'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -2266,6 +2286,7 @@ export default [
hostname: 'vmnwprd02',
id: '4b30a6af-4b52-5bda-bccb-f2248a12c992',
ip_addresses: ['10.80.1.22', '10.80.1.26'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -2379,6 +2400,7 @@ export default [
hostname: 'vmnwprd03',
id: 'a3297d85-5e8b-5ac5-b8a3-55eebc2b8d12',
ip_addresses: ['10.80.1.23', '10.80.1.27'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -2492,6 +2514,7 @@ export default [
hostname: 'vmnwprd04',
id: '0fc07435-7ee2-54ca-b0de-fb27ffdc5deb',
ip_addresses: ['10.80.1.24', '10.80.1.28'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -2605,6 +2628,7 @@ export default [
hostname: 'vmnwqas01',
id: '25677e37-fd33-5005-896c-9275b1284534',
ip_addresses: ['10.90.1.21', '10.90.1.25'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -2718,6 +2742,7 @@ export default [
hostname: 'vmnwqas02',
id: '3711ea88-9ccc-5b07-8f9d-042be449d72b',
ip_addresses: ['10.90.1.22', '10.90.1.26'],
netmasks: [24, 24],
provider: 'azure',
provider_data: {
admin_username: 'cloudadmin',
Expand Down Expand Up @@ -2831,6 +2856,7 @@ export default [
hostname: 'vmnwqas03',
id: '098fc159-3ed6-58e7-91be-38fda8a833ea',
ip_addresses: ['10.90.1.27', '10.90.1.23'],
netmasks: [24, 32],
provider: null,
provider_data: null,
sles_subscriptions: [
Expand Down Expand Up @@ -2935,6 +2961,7 @@ export default [
hostname: 'vmnwqas04',
id: '81e9b629-c1e7-538f-bff1-47d3a6580522',
ip_addresses: ['10.90.1.28', '10.90.1.24'],
netmasks: [24, 24],
provider: null,
provider_data: null,
sles_subscriptions: [
Expand Down
1 change: 1 addition & 0 deletions assets/js/lib/test-utils/factories/hosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const hostFactory = Factory.define(({ params, sequence }) => {
hostname: `${faker.person.firstName()}_${sequence}`,
cluster_id: faker.string.uuid(),
ip_addresses: [faker.internet.ip()],
netmasks: [faker.helpers.arrayElement([8, 16, 24, 32])],
provider: cloudProviderEnum(),
health: healthEnum(),
heartbeat: heartbeatEnum(),
Expand Down
12 changes: 10 additions & 2 deletions assets/js/pages/HostDetailsPage/HostDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { get } from 'lodash';
import { get, zipWith } from 'lodash';
import classNames from 'classnames';
import {
EOS_CLEAR_ALL,
Expand Down Expand Up @@ -48,6 +48,13 @@ function formatBytes(bytes, decimals = 2) {
return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
}

export const buildCidrNotation = (ipAddresses, netmasks) =>
zipWith(
ipAddresses,
netmasks,
(address, netmask) => `${address}${netmask ? `/${netmask}` : ''}`
);

function HostDetails({
agentVersion,
chartsEnabled,
Expand All @@ -59,6 +66,7 @@ function HostDetails({
hostID,
hostname,
ipAddresses = [],
netmasks = [],
provider,
providerData,
sapInstances,
Expand Down Expand Up @@ -213,7 +221,7 @@ function HostDetails({
<HostSummary
agentVersion={agentVersion}
cluster={cluster}
ipAddresses={ipAddresses}
ipAddresses={buildCidrNotation(ipAddresses, netmasks)}
/>
<div className="flex flex-col mt-4 bg-white shadow rounded-lg pt-8 px-8 xl:w-2/5 mr-4">
<SaptuneSummary
Expand Down
8 changes: 8 additions & 0 deletions assets/js/pages/HostDetailsPage/HostDetails.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ export default {
control: { type: 'array' },
description: 'IP addresses',
},
netmasks: {
control: { type: 'array' },
description: 'Netmasks associated to ip addresses',
},
provider: {
control: 'text',
description: 'The discovered CSP where the host is running',
Expand Down Expand Up @@ -176,6 +180,7 @@ export const Default = {
hostID: host.id,
hostname: host.hostname,
ipAddresses: host.ip_addresses,
netmasks: host.netmasks,
provider: host.provider,
providerData: host.provider_data,
sapInstances,
Expand Down Expand Up @@ -274,6 +279,9 @@ export const HostSummaryWithTooltip = {
args: {
...Default.args,
ipAddresses: Array.from({ length: 10 }, () => faker.internet.ipv4()),
netmasks: Array.from({ length: 10 }, () =>
faker.helpers.arrayElement([8, 16, 24, 32])
),
},
};

Expand Down
64 changes: 48 additions & 16 deletions assets/js/pages/HostDetailsPage/HostDetails.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,56 @@ describe('HostDetails component', () => {
});
});

describe('agent version', () => {
const message =
'The Agent version is outdated, some features might not work properly. It is advised to keep the Agents up to date with the Server.';

it('should not show any warning message if the agent version is correct', () => {
renderWithRouter(
<HostDetails agentVersion="2.0.0" userAbilities={userAbilities} />
);

expect(screen.queryByText(message)).not.toBeInTheDocument();
describe('Summary box', () => {
describe('agent version', () => {
const message =
'The Agent version is outdated, some features might not work properly. It is advised to keep the Agents up to date with the Server.';

it('should not show any warning message if the agent version is correct', () => {
renderWithRouter(
<HostDetails agentVersion="2.0.0" userAbilities={userAbilities} />
);

expect(screen.queryByText(message)).not.toBeInTheDocument();
});

it('should show a warning message if the agent version is outdated', () => {
renderWithRouter(
<HostDetails agentVersion="1.0.0" userAbilities={userAbilities} />
);

expect(screen.getByText(message)).toBeInTheDocument();
});
});

it('should show a warning message if the agent version is outdated', () => {
renderWithRouter(
<HostDetails agentVersion="1.0.0" userAbilities={userAbilities} />
);

expect(screen.getByText(message)).toBeInTheDocument();
describe('IP addresses', () => {
it('should show IP addresses with CIDR notation', () => {
renderWithRouter(
<HostDetails
agentVersion="2.0.0"
ipAddresses={['10.0.0.5', '10.0.0.6']}
netmasks={[24, 32]}
userAbilities={userAbilities}
/>
);

expect(
screen.getByText('10.0.0.5/24, 10.0.0.6/32')
).toBeInTheDocument();
});

it('should show plain IP addresses if netmasks are null', () => {
renderWithRouter(
<HostDetails
agentVersion="2.0.0"
ipAddresses={['10.0.0.5', '10.0.0.6']}
netmasks={[null, null]}
userAbilities={userAbilities}
/>
);

expect(screen.getByText('10.0.0.5, 10.0.0.6')).toBeInTheDocument();
});
});
});

Expand Down
1 change: 1 addition & 0 deletions assets/js/pages/HostDetailsPage/HostDetailsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function HostDetailsPage() {
hostID={host.id}
hostname={host.hostname}
ipAddresses={host.ip_addresses}
netmasks={host.netmasks}
provider={host.provider}
providerData={host.provider_data}
sapInstances={sapInstances}
Expand Down
3 changes: 2 additions & 1 deletion assets/js/pages/HostsList/HostsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ClusterLink from '@pages/ClusterDetails/ClusterLink';
import DeregistrationModal from '@pages/DeregistrationModal';
import HealthSummary from '@pages/HealthSummary';
import { getCounters } from '@pages/HealthSummary/summarySelection';
import { buildCidrNotation } from '@pages/HostDetailsPage/HostDetails';

import { addTagToHost, removeTagFromHost, deregisterHost } from '@state/hosts';
import { getAllSAPInstances } from '@state/selectors/sapSystem';
Expand Down Expand Up @@ -224,7 +225,7 @@ function HostsList() {
return {
health: host.health,
hostname: host.hostname,
ip: host.ip_addresses,
ip: buildCidrNotation(host.ip_addresses, host.netmasks),
provider: host.provider,
sid: sapSystemList.map((sapSystem) => sapSystem.sid),
cluster,
Expand Down
Loading

0 comments on commit a16f5f1

Please sign in to comment.