APs UniFi OK
This commit is contained in:
parent
8172769249
commit
2e5ce3f07d
|
@ -21,6 +21,7 @@ CREATE TABLE "AccessPoint" (
|
||||||
"uptime" TEXT,
|
"uptime" TEXT,
|
||||||
"controller" TEXT,
|
"controller" TEXT,
|
||||||
"model" TEXT,
|
"model" TEXT,
|
||||||
|
"ipAddress" TEXT,
|
||||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
|
@ -150,6 +150,7 @@ model AccessPoint {
|
||||||
uptime String?
|
uptime String?
|
||||||
controller String?
|
controller String?
|
||||||
model String?
|
model String?
|
||||||
|
ipAddress String?
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import prisma from '../prisma'
|
import prisma from '../prisma'
|
||||||
import { getAccessPoints as getCiscoAccessPoints } from './ciscoController'
|
import { getAccessPoints as getCiscoAccessPoints } from './ciscoController'
|
||||||
|
import { getAccessPoints as getUnifiAccessPoints } from './unifiController'
|
||||||
|
|
||||||
async function getAccessPoints() {
|
async function getAccessPoints() {
|
||||||
const ciscoAccessPoints = await getCiscoAccessPoints()
|
const ciscoAccessPoints = await getCiscoAccessPoints()
|
||||||
|
const unifiAccessPoints = await getUnifiAccessPoints()
|
||||||
|
|
||||||
return ciscoAccessPoints
|
return [...ciscoAccessPoints, ...unifiAccessPoints]
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateDB(accessPoints) {
|
async function updateDB(accessPoints) {
|
||||||
|
@ -19,5 +21,6 @@ async function updateDB(accessPoints) {
|
||||||
|
|
||||||
export async function updateAccessPoints() {
|
export async function updateAccessPoints() {
|
||||||
const accessPoints = await getAccessPoints()
|
const accessPoints = await getAccessPoints()
|
||||||
|
|
||||||
await updateDB(accessPoints)
|
await updateDB(accessPoints)
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,13 +135,16 @@ export async function getAccessPoints() {
|
||||||
|
|
||||||
clearTimeout(timeout)
|
clearTimeout(timeout)
|
||||||
|
|
||||||
const restructuredAccessPoints = accessPoints.map(({ Nm, Mc, Md, Ut }) => ({
|
const restructuredAccessPoints = accessPoints.map(
|
||||||
|
({ Nm, Mc, Md, Ut, A4 }) => ({
|
||||||
mac: Mc,
|
mac: Mc,
|
||||||
hostname: Nm,
|
hostname: Nm,
|
||||||
uptime: Ut.toString(),
|
uptime: Ut.toString(),
|
||||||
controller: 'Cisco',
|
controller: 'Cisco',
|
||||||
model: Md
|
model: Md,
|
||||||
}))
|
ipAddress: A4
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
return restructuredAccessPoints
|
return restructuredAccessPoints
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -2,6 +2,8 @@ import { Controller } from 'node-unifi'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import { ouiFinder } from '../utils/ouiFinder'
|
import { ouiFinder } from '../utils/ouiFinder'
|
||||||
|
|
||||||
|
import { logError } from './logger'
|
||||||
|
|
||||||
const unifiController = new Controller(
|
const unifiController = new Controller(
|
||||||
process.env.UNIFI_HOST || 'unifi.pp.ifms.edu.br',
|
process.env.UNIFI_HOST || 'unifi.pp.ifms.edu.br',
|
||||||
process.env.UNIFI_PORT || 8443
|
process.env.UNIFI_PORT || 8443
|
||||||
|
@ -200,3 +202,35 @@ export async function getOnlineWifiDevices() {
|
||||||
throw new Error('Error getting devices. ' + e)
|
throw new Error('Error getting devices. ' + e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAccessPoints() {
|
||||||
|
try {
|
||||||
|
await unifiController.login(
|
||||||
|
process.env.UNIFI_USER,
|
||||||
|
process.env.UNIFI_PASSWORD
|
||||||
|
)
|
||||||
|
const accessPoints = await unifiController.getAccessDevices('default')
|
||||||
|
|
||||||
|
const restructuredAccessPoints = accessPoints[0].map(
|
||||||
|
({ mac, model, ip, uptime, name }) => ({
|
||||||
|
mac,
|
||||||
|
hostname: name,
|
||||||
|
uptime: uptime?.toString(),
|
||||||
|
controller: 'UniFi',
|
||||||
|
model,
|
||||||
|
ipAddress: ip
|
||||||
|
})
|
||||||
|
)
|
||||||
|
unifiController.logout()
|
||||||
|
|
||||||
|
return restructuredAccessPoints
|
||||||
|
} catch (e) {
|
||||||
|
logError({
|
||||||
|
tags: ['unifi', 'accessPoints'],
|
||||||
|
message: e.message,
|
||||||
|
data: { ...e, config: { ...e.config, auth: '*****' } }
|
||||||
|
})
|
||||||
|
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user