APs UniFi OK
This commit is contained in:
parent
8172769249
commit
2e5ce3f07d
|
@ -21,6 +21,7 @@ CREATE TABLE "AccessPoint" (
|
|||
"uptime" TEXT,
|
||||
"controller" TEXT,
|
||||
"model" TEXT,
|
||||
"ipAddress" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
|
@ -150,6 +150,7 @@ model AccessPoint {
|
|||
uptime String?
|
||||
controller String?
|
||||
model String?
|
||||
ipAddress String?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import prisma from '../prisma'
|
||||
import { getAccessPoints as getCiscoAccessPoints } from './ciscoController'
|
||||
import { getAccessPoints as getUnifiAccessPoints } from './unifiController'
|
||||
|
||||
async function getAccessPoints() {
|
||||
const ciscoAccessPoints = await getCiscoAccessPoints()
|
||||
const unifiAccessPoints = await getUnifiAccessPoints()
|
||||
|
||||
return ciscoAccessPoints
|
||||
return [...ciscoAccessPoints, ...unifiAccessPoints]
|
||||
}
|
||||
|
||||
async function updateDB(accessPoints) {
|
||||
|
@ -19,5 +21,6 @@ async function updateDB(accessPoints) {
|
|||
|
||||
export async function updateAccessPoints() {
|
||||
const accessPoints = await getAccessPoints()
|
||||
|
||||
await updateDB(accessPoints)
|
||||
}
|
||||
|
|
|
@ -135,13 +135,16 @@ export async function getAccessPoints() {
|
|||
|
||||
clearTimeout(timeout)
|
||||
|
||||
const restructuredAccessPoints = accessPoints.map(({ Nm, Mc, Md, Ut }) => ({
|
||||
const restructuredAccessPoints = accessPoints.map(
|
||||
({ Nm, Mc, Md, Ut, A4 }) => ({
|
||||
mac: Mc,
|
||||
hostname: Nm,
|
||||
uptime: Ut.toString(),
|
||||
controller: 'Cisco',
|
||||
model: Md
|
||||
}))
|
||||
model: Md,
|
||||
ipAddress: A4
|
||||
})
|
||||
)
|
||||
|
||||
return restructuredAccessPoints
|
||||
} catch (e) {
|
||||
|
|
|
@ -2,6 +2,8 @@ import { Controller } from 'node-unifi'
|
|||
import { promisify } from 'util'
|
||||
import { ouiFinder } from '../utils/ouiFinder'
|
||||
|
||||
import { logError } from './logger'
|
||||
|
||||
const unifiController = new Controller(
|
||||
process.env.UNIFI_HOST || 'unifi.pp.ifms.edu.br',
|
||||
process.env.UNIFI_PORT || 8443
|
||||
|
@ -200,3 +202,35 @@ export async function getOnlineWifiDevices() {
|
|||
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