Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NMS-16483: Structured Node List - some IP are missing #7462

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const copyURLToClipboard = () => {
if (floating.value && props.text) {
ConfigurationHelper.copyToClipboard(props.text).then(() => {
showSnackBar({
msg: `Copied: ${props.text.length > 70 ? props.text.substring(0, 70) + '...' : props.text}`,
msg: `Copied: ${props.text.length > 70 ? props.text.substring(0, 70) + '...' : props.text}`
})
}).catch((err) => {
showSnackBar({
Expand Down
1 change: 0 additions & 1 deletion ui/src/components/Layout/Menubar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ import { FeatherDropdown, FeatherDropdownItem } from '@featherds/dropdown'
import { FeatherIcon } from '@featherds/icon'
import AddCircleAlt from '@featherds/icon/action/AddCircleAlt'
import ArrowDropDown from '@featherds/icon/navigation/ArrowDropDown'
import LightDarkMode from '@featherds/icon/action/LightDarkMode'
import UpdateUtilities from '@featherds/icon/action/UpdateUtilities'
import Person from '@featherds/icon/action/Person'
import Logo from '@/assets/LogoHorizon.vue'
Expand Down
10 changes: 5 additions & 5 deletions ui/src/components/Map/MarkerCluster.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'leaflet.markercluster/dist/MarkerCluster.css'
import { propsBinder, remapEvents } from '@vue-leaflet/vue-leaflet/src/utils'
import {
render,
setup as layerSetup,
setup as layerSetup
} from '@vue-leaflet/vue-leaflet/src/functions/layer'

const props = {
Expand Down Expand Up @@ -73,7 +73,7 @@ export default {
Polygon,
Polyline,
popup,
Util,
Util
} = await import('leaflet/dist/leaflet-src.esm')

/** create a fake window.L from just the bits we need to make markercluster load properly **/
Expand All @@ -99,7 +99,7 @@ export default {
Polygon,
Polyline,
popup,
Util,
Util
}
window['L'] = L

Expand All @@ -119,7 +119,7 @@ export default {
addLayerToMainMap({
...props,
...methods,
leafletObject: leafletRef.value,
leafletObject: leafletRef.value
})

ready.value = true
Expand All @@ -137,6 +137,6 @@ export default {
},
render() {
return render(this.ready, this.$slots)
},
}
}
</script>
39 changes: 36 additions & 3 deletions ui/src/components/Nodes/hooks/useNodeExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,41 @@
/// License.
///

import { getIpInterfaces, getNodeIpInterfaceQuery } from '@/services/ipInterfaceService'
import { getNodes } from '@/services/nodeService'
import {
IpInterface,
Node,
NodeApiResponse,
NodeColumnSelectionItem,
QueryParameters
} from '@/types'
import { hasEgressFlow, hasIngressFlow } from '../utils'
import { useIpInterfaceQuery } from './useIpInterfaceQuery'

export const useNodeExport = () => {

const getIpInterfacesForNodes = async (nodeIds: string[], managedOnly: boolean): Promise<Map<string, IpInterface[]> | boolean> => {
if (nodeIds.length === 0) {
return false
}
const query = getNodeIpInterfaceQuery(nodeIds, managedOnly)
const queryParameters = {
limit: 0,
_s: query
} as QueryParameters
const resp = await getIpInterfaces(queryParameters)
const nodeToIpInterfaceMap = new Map<string, IpInterface[]>()
if (resp) {
// find updated list of IpInterfaces for each node and update the node => ip map
for (const id of nodeIds) {
const ipsThisNode = resp.ipInterface.filter(ip => ip.nodeId.toString() === id)
nodeToIpInterfaceMap.set(id, ipsThisNode)
}
return nodeToIpInterfaceMap
}
return false
}
/**
* Create Node export data as a string, with given query parameters/filters and currently configured columns.
* @param format Export format, either 'csv' or 'json'
Expand All @@ -48,10 +73,18 @@ export const useNodeExport = () => {
return ''
}

const nodeResponse = resp as NodeApiResponse
const nodeResponse: NodeApiResponse = resp
const nodes: Node[] = nodeResponse.node

const exportableNodes = nodes.map(n => buildExportableNode(columns, n))
const nodeIds = nodes.map(n => n.id)
const interfacesMap = await getIpInterfacesForNodes(nodeIds, false)
const nodeToIpInterfaceMap = interfacesMap as Map<string, IpInterface[]>
const exportableNodes = [] as any[]
const { getBestIpInterfaceForNode } = useIpInterfaceQuery()
nodes.forEach((node) => {
const exportableNode = buildExportableNode(columns, node)
exportableNode.ipaddress = getBestIpInterfaceForNode(node.id, nodeToIpInterfaceMap).label
exportableNodes.push(exportableNode)
})

if (format === 'json') {
return JSON.stringify(exportableNodes, null, 2)
Expand Down
18 changes: 9 additions & 9 deletions ui/src/components/Resources/Graph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import { FeatherButton } from '@featherds/button'
import {
FeatherTab,
FeatherTabContainer,
FeatherTabPanel,
FeatherTabPanel
} from '@featherds/tabs'
import { PropType } from 'vue'
Chart.register(...registerables)
Expand Down Expand Up @@ -89,7 +89,7 @@ const convertedGraphDataRef = ref<ConvertedGraphData>({
values: [],
metrics: [],
printStatements: [],
properties: {},
properties: {}
})
let chart: any = {}
const legendRef = ref()
Expand All @@ -104,33 +104,33 @@ const options = computed<ChartOptions>(() => ({
plugins: {
htmlLegend: {
// ID of the container to put the legend in
containerID: `${props.label}-${props.definition}-lc`,
containerID: `${props.label}-${props.definition}-lc`
},
legend: {
display: false
},
title: {
display: true,
text: convertedGraphDataRef.value.title,
text: convertedGraphDataRef.value.title
} as TitleOptions,
zoom: {
zoom: {
wheel: {
enabled: true,
enabled: true
},
mode: 'x',
mode: 'x'
},
pan: {
enabled: true,
mode: 'x'
}
},
}
},
scales: {
y: {
title: {
display: true,
text: convertedGraphDataRef.value.verticalLabel,
text: convertedGraphDataRef.value.verticalLabel
} as TitleOptions,
ticks: {
callback: (value) => yAxisFormatter(value as number),
Expand Down Expand Up @@ -236,7 +236,7 @@ const getGraphMetricsPayload = (source: Metric[]): GraphMetricsPayload => {
start,
end,
step,
source: metricsWithoutExpressions,
source: metricsWithoutExpressions
}

if (metricsWithExpressions.length) {
Expand Down
3 changes: 1 addition & 2 deletions ui/src/stores/nodeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
/// License.
///

import { NodeQueryFilter } from './../types/index';
import { defineStore } from 'pinia'
import API from '@/services'
import { IpInterface, Node, NodeAvailability, Outage, QueryParameters, SnmpInterface } from '@/types'
Expand Down Expand Up @@ -92,7 +91,7 @@ export const useNodeStore = defineStore('nodeStore', () => {

const query = getNodeIpInterfaceQuery(nodeIds, managedOnly)
const queryParameters = {
limit: nodeIds.length,
limit: 0,
_s: query
} as QueryParameters

Expand Down
2 changes: 1 addition & 1 deletion ui/src/types/usageStatistics.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UsageStatisticsMetadata } from '@/types/usageStatistics';
import { UsageStatisticsMetadata } from '@/types/usageStatistics'
export interface UsageStatisticsStatus {
enabled: boolean | null,
initialNoticeAcknowledged?: boolean | null
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/components/Nodes/hooks/queryStringParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('Nodes queryStringParser test', () => {
['invalid iplike', { iplike: 'abc'}, null],
['invalid iplike localhost', { iplike: 'localhost'}, null],
['invalid partial iplike', { iplike: '192.168.'}, null],
['invalid iplike', { iplike: 'A.B.C.D'}, null],
['invalid iplike', { iplike: 'A.B.C.D'}, null]
]) (
'parseIpLike: %s',
(title, queryObject, expected) => {
Expand Down
46 changes: 44 additions & 2 deletions ui/tests/components/Nodes/hooks/useNodeExport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
/// License.
///

import { useNodeExport } from '@/components/Nodes/hooks/useNodeExport'
import { IpInterface, IpInterfaceApiResponse, Node, NodeApiResponse, NodeColumnSelectionItem, QueryParameters } from '@/types'
import { describe, expect, test, vi } from 'vitest'
import { mock } from 'vitest-mock-extended'
import getExportDataResponseJson from './data/getExportDataResponse.json'
import getExportDataResponseCsv from './data/getExportDataResponseCSV.json'
import { useNodeExport } from '@/components/Nodes/hooks/useNodeExport'
import { Node, NodeApiResponse, NodeColumnSelectionItem, QueryParameters } from '@/types'

const { generateBlob, getExportData } = useNodeExport()

Expand Down Expand Up @@ -79,10 +79,52 @@ const createNodeResponse = () => {
return response
}

const createIpInterfaceResponse = () => {
const ipInterface1 = mock<IpInterface>()
ipInterface1.lastIngressFlow = null
ipInterface1.ifIndex = ''
ipInterface1.ipAddress = '192.168.0.1'
ipInterface1.lastEgressFlow = null
ipInterface1.isManaged = 'M'
ipInterface1.snmpPrimary = 'N'
ipInterface1.monitoredServiceCount = 0
ipInterface1.isDown = true
ipInterface1.id = '1'
ipInterface1.lastCapsdPoll = 1728390352124
ipInterface1.nodeId = 1

const ipInterface2 = mock<IpInterface>()
ipInterface2.lastIngressFlow = null
ipInterface2.ifIndex = ''
ipInterface2.ipAddress = '192.168.99.106'
ipInterface2.lastEgressFlow = null
ipInterface2.isManaged = 'M'
ipInterface2.snmpPrimary = 'N'
ipInterface2.monitoredServiceCount = 0
ipInterface2.isDown = true
ipInterface2.id = '2'
ipInterface2.lastCapsdPoll = 1728390352124
ipInterface2.nodeId = 106

const response = {
count: 2,
offset: 0,
totalCount: 2,
ipInterface: [ipInterface1, ipInterface2]
} as IpInterfaceApiResponse

return response
}

vi.mock('@/services/nodeService', () => ({
getNodes: vi.fn(() => createNodeResponse())
}))

vi.mock('@/services/ipInterfaceService', async () => ({
getNodeIpInterfaceQuery: vi.fn(),
getIpInterfaces: vi.fn(() => createIpInterfaceResponse())
}))

describe('Nodes useNodeExport test', () => {
test('test generateBlob', () => {
const result = generateBlob('some content', 'text/html')
Expand Down
10 changes: 5 additions & 5 deletions ui/tests/components/Nodes/hooks/useNodeQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe('Nodes useNodeQuery test', () => {
{
foreignSource: 'FS',
foreignId: '',
foreignSourceId: '',
foreignSourceId: ''
}
],
[
Expand All @@ -241,7 +241,7 @@ describe('Nodes useNodeQuery test', () => {
{
foreignSource: '',
foreignId: 'ID',
foreignSourceId: '',
foreignSourceId: ''
}
],
[
Expand All @@ -252,7 +252,7 @@ describe('Nodes useNodeQuery test', () => {
{
foreignSource: '',
foreignId: '',
foreignSourceId: 'FS:FID',
foreignSourceId: 'FS:FID'
}
],
[
Expand All @@ -263,7 +263,7 @@ describe('Nodes useNodeQuery test', () => {
{
foreignSource: '',
foreignId: '',
foreignSourceId: 'FS:FID',
foreignSourceId: 'FS:FID'
}
],
[
Expand All @@ -276,7 +276,7 @@ describe('Nodes useNodeQuery test', () => {
{
foreignSource: 'FS',
foreignId: 'ID',
foreignSourceId: 'FS:FID',
foreignSourceId: 'FS:FID'
}
]
]) (
Expand Down
Loading