Consider RECENT as ONLINE. Don't fail if as failed page request.
This commit is contained in:
parent
67a41076db
commit
b61a2727c3
|
@ -12,7 +12,9 @@ async function generateStatsForAccessPoint(accessPoint) {
|
|||
accessPoint: {
|
||||
mac: accessPoint.mac
|
||||
},
|
||||
status: 'ONLINE'
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
}
|
||||
},
|
||||
_count: {
|
||||
_all: true
|
||||
|
|
|
@ -7,7 +7,7 @@ const TIMEOUT_IN_MS = 120000
|
|||
const REQUEST_TIMEOUT_IN_MS = 20000
|
||||
|
||||
const getDevicesUri = (skip = 0, page = 1, take = 50) =>
|
||||
`data/client-table.html?columns=524287&take=${take}&skip=${skip}&page=${page}&pageSize=50&sort[0][field]=ST&sort[0][dir]=desc`
|
||||
`https://${process.env.CISCO_HOST}/data/client-table.html?columns=524287&take=${take}&skip=${skip}&page=${page}&pageSize=50&sort[0][field]=ST&sort[0][dir]=desc`
|
||||
|
||||
const httpsAgent = new https.Agent({
|
||||
rejectUnauthorized: false
|
||||
|
@ -16,7 +16,6 @@ const httpsAgent = new https.Agent({
|
|||
const ciscoAxios = create({
|
||||
withCredentials: true,
|
||||
httpsAgent: httpsAgent,
|
||||
baseURL: `https://${process.env.CISCO_HOST}/`,
|
||||
timeout: REQUEST_TIMEOUT_IN_MS,
|
||||
auth: {
|
||||
username: process.env.CISCO_USER,
|
||||
|
@ -24,6 +23,20 @@ const ciscoAxios = create({
|
|||
}
|
||||
})
|
||||
|
||||
async function renewSessionId() {
|
||||
try {
|
||||
await ciscoAxios.get(getDevicesUri())
|
||||
} catch (e) {
|
||||
if (e.response?.status === 401) {
|
||||
const newSessionId = e.response.headers['set-cookie'][0]
|
||||
.split(';')[0]
|
||||
.split('=')[1]
|
||||
|
||||
ciscoAxios.defaults.headers.Cookie = `sessionId=${newSessionId}`
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getDevices() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const source = CancelToken.source()
|
||||
|
@ -43,17 +56,7 @@ function getDevices() {
|
|||
|
||||
const responsesPromises = []
|
||||
|
||||
try {
|
||||
await ciscoAxios.get(getDevicesUri())
|
||||
} catch (e) {
|
||||
if (e.response?.status === 401) {
|
||||
const newSessionId = e.response.headers['set-cookie'][0]
|
||||
.split(';')[0]
|
||||
.split('=')[1]
|
||||
|
||||
ciscoAxios.defaults.headers.Cookie = `sessionId=${newSessionId}`
|
||||
}
|
||||
}
|
||||
await renewSessionId()
|
||||
|
||||
try {
|
||||
const firstResponse = await ciscoAxios.get(getDevicesUri(), {
|
||||
|
@ -76,7 +79,16 @@ function getDevices() {
|
|||
page++
|
||||
}
|
||||
|
||||
const responses = await Promise.all(responsesPromises)
|
||||
const fulfilledResponses = await Promise.allSettled(responsesPromises)
|
||||
|
||||
const responses = fulfilledResponses
|
||||
.filter(resp => resp.status === 'fulfilled')
|
||||
.map(resp => resp.value)
|
||||
|
||||
console.log(
|
||||
responses.length,
|
||||
fulfilledResponses.filter(resp => resp.status === 'rejected').length
|
||||
)
|
||||
|
||||
clearTimeout(timeout)
|
||||
|
||||
|
@ -145,6 +157,8 @@ export function getAccessPoints() {
|
|||
)
|
||||
}, TIMEOUT_IN_MS)
|
||||
|
||||
await renewSessionId()
|
||||
|
||||
try {
|
||||
const {
|
||||
data: { Data: accessPoints }
|
||||
|
|
|
@ -10,7 +10,9 @@ async function generateStatsForNetwork(shortName) {
|
|||
|
||||
const dbStats = await prisma.wifiDevice.aggregate({
|
||||
where: {
|
||||
status: 'ONLINE',
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
},
|
||||
network: {
|
||||
shortName
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ async function getDevicesWithUser() {
|
|||
const wifiDevices = await prisma.wifiDevice.findMany({
|
||||
where: {
|
||||
userId: { not: null },
|
||||
status: 'ONLINE',
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
},
|
||||
lastSeen: { gt: timeoutThreshold }
|
||||
},
|
||||
select: {
|
||||
|
|
|
@ -232,7 +232,9 @@ function updateDevicesInfo() {
|
|||
include: {
|
||||
wifiDevices: {
|
||||
where: {
|
||||
status: 'ONLINE'
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@ export const AccessPoint = {
|
|||
async clients(parent, data, context, info) {
|
||||
const clientsCount = await prisma.wifiDevice.count({
|
||||
where: {
|
||||
status: 'ONLINE',
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
},
|
||||
accessPoint: {
|
||||
id: parent.id
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ export async function accessPoint(parent, { id }, context, info) {
|
|||
ip: 'asc'
|
||||
},
|
||||
where: {
|
||||
status: 'ONLINE'
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ export async function accessPoints(_, { networkShortName }) {
|
|||
network: true,
|
||||
wifiDevices: {
|
||||
where: {
|
||||
status: 'ONLINE'
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,13 @@ const Stats = {
|
|||
totalWifiDevices: async () => prisma.wifiDevice.count(),
|
||||
|
||||
onlineWifiDevices: async () =>
|
||||
prisma.wifiDevice.count({ where: { status: 'ONLINE' } })
|
||||
prisma.wifiDevice.count({
|
||||
where: {
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export { Stats }
|
||||
|
|
|
@ -79,7 +79,9 @@ const User = {
|
|||
onlineWifiDevicesCount: (parent, data, { auth }) =>
|
||||
prisma.wifiDevice.count({
|
||||
where: {
|
||||
status: 'ONLINE',
|
||||
status: {
|
||||
in: ['ONLINE', 'RECENT']
|
||||
},
|
||||
user: { id: parent.id }
|
||||
}
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue
Block a user