diff --git a/src/components/standalone/monitoring/ConnectivityMonitor.vue b/src/components/standalone/monitoring/ConnectivityMonitor.vue index 9ba19c66a..e4fe0b005 100644 --- a/src/components/standalone/monitoring/ConnectivityMonitor.vue +++ b/src/components/standalone/monitoring/ConnectivityMonitor.vue @@ -19,18 +19,16 @@ import InterfaceTrafficCard from './connectivity/InterfaceTrafficCard.vue' import { isEmpty } from 'lodash-es' import type { Policy } from '@/composables/useMwan' import WanConnectionsCard from './connectivity/WanConnectionsCard.vue' -import { - getName, - type DeviceOrIface, - type ZoneWithDeviceNames, - type ZoneWithDevices -} from '@/lib/standalone/network' -import { zonesSorting } from '@/stores/standalone/firewall' +import { useNetworkDevices } from '@/composables/useNetworkDevices' +import { getIpv4Addresses, getIpv6Addresses, getName, isDeviceUp } from '@/lib/standalone/network' +import { useUciNetworkConfig } from '@/composables/useUciNetworkConfig' export type Wan = { iface: string device: string status?: string + ip4Addresses?: string[] + ip6Addresses?: string[] } export type WanEvent = { @@ -39,18 +37,24 @@ export type WanEvent = { } const { t } = useI18n() +const { allDevices, listDevices, loadingListDevices, errorListDevices, errorListDevicesDetails } = + useNetworkDevices() +const { + networkConfig, + getNetworkConfig, + loadingNetworkConfig, + errorNetworkConfig, + errorNetworkConfigDetails +} = useUciNetworkConfig() const wans = ref([]) const mwanEvents = ref>({}) const mwanPolicies = ref([]) -const allDevices = ref([]) //// -const devicesByZone = ref([]) //// let loading = ref({ listWans: false, getMwanReport: false, - getMwanPolicies: false, //// - listDevices: false //// + getMwanPolicies: false }) let error = ref({ @@ -59,69 +63,78 @@ let error = ref({ getMwanReport: '', getMwanReportDetails: '', getMwanPolicies: '', - getMwanPoliciesDetails: '', - listDevices: '', //// - listDevicesDetails: '' //// + getMwanPoliciesDetails: '' }) -const wanConnections = computed(() => { - const wanData = [] +const loadingData = computed(() => { + return ( + loading.value.listWans || + loading.value.getMwanReport || + loading.value.getMwanPolicies || + loadingNetworkConfig.value || + loadingListDevices.value + ) +}) - console.log('wans', wans.value) //// +const wanConnections = computed(() => { + const wanData: Wan[] = [] for (const wan of wans.value) { // get wan status from policy data let statusFound = false - for (const policy of mwanPolicies.value) { - if (statusFound) { - break - } - - for (const policyMembers of Object.values(policy.members)) { + if (mwanPolicies.value.length > 0) { + // multiwan configured + for (const policy of mwanPolicies.value) { if (statusFound) { break } - for (const policyMember of policyMembers) { - if (policyMember.interface == wan.iface) { - wanData.push({ - ...wan, - status: policyMember.status - }) - statusFound = true + for (const policyMembers of Object.values(policy.members)) { + if (statusFound) { break } + + for (const policyMember of policyMembers) { + if (policyMember.interface == wan.iface) { + const devFound = allDevices.value.find((dev) => getName(dev) === wan.device) + + wanData.push({ + ...wan, + status: policyMember.status, + ip4Addresses: devFound ? getIpv4Addresses(devFound, networkConfig.value) : [], + ip6Addresses: devFound ? getIpv6Addresses(devFound, networkConfig.value) : [] + }) + statusFound = true + break + } + } } } - } - } - return wanData -}) + } else { + // multiwan not configured -//// -const sortedZonesAndDevices = computed(() => { - const zones: ZoneWithDevices[] = [] - devicesByZone.value.forEach((z: ZoneWithDeviceNames) => { - const deviceList: DeviceOrIface[] = [] - z.devices.forEach((devName: string) => { - const devFound = allDevices.value.find((dev) => getName(dev) === devName) + const devFound = allDevices.value.find((dev) => getName(dev) === wan.device) if (devFound) { - deviceList.push(devFound) + wanData.push({ + ...wan, + status: isDeviceUp(devFound, allDevices.value) ? 'online' : 'offline', + ip4Addresses: getIpv4Addresses(devFound, networkConfig.value), + ip6Addresses: getIpv6Addresses(devFound, networkConfig.value) + }) } - }) - const zone = { name: z.name, devices: deviceList } - zones.push(zone) - }) - - return zones.sort(zonesSorting) + } + } + return wanData.sort(sortByProperty('iface')) }) onMounted(() => { listWans() getMwanReport() getMwanPolicies() + listDevices() + getNetworkConfig() }) async function listWans() { @@ -187,30 +200,6 @@ async function getMwanPolicies() { loading.value.getMwanPolicies = false } } - -//// -async function listDevices() { - loading.value.listDevices = true - error.value.listDevices = '' - error.value.listDevicesDetails = '' - - try { - const res = await ubusCall('ns.devices', 'list-devices') - - const bondDevices = res.data.all_devices - .filter((device: DeviceOrIface) => device.name?.startsWith('bond-')) - .map((device: DeviceOrIface) => device.name?.slice(5)) - - allDevices.value = res.data.all_devices.filter( - (device: DeviceOrIface) => !bondDevices.includes(device.name ?? device['.name']) - ) - devicesByZone.value = res.data.devices_by_zone - } catch (err: any) { - error.value.listDevices = t(getAxiosErrorMessage(err)) - error.value.listDevicesDetails = err.toString() - } - loading.value.listDevices = false -} -
+ + + + + + + + +
-