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: {
|
accessPoint: {
|
||||||
mac: accessPoint.mac
|
mac: accessPoint.mac
|
||||||
},
|
},
|
||||||
status: 'ONLINE'
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_count: {
|
_count: {
|
||||||
_all: true
|
_all: true
|
||||||
|
|
|
@ -7,7 +7,7 @@ const TIMEOUT_IN_MS = 120000
|
||||||
const REQUEST_TIMEOUT_IN_MS = 20000
|
const REQUEST_TIMEOUT_IN_MS = 20000
|
||||||
|
|
||||||
const getDevicesUri = (skip = 0, page = 1, take = 50) =>
|
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({
|
const httpsAgent = new https.Agent({
|
||||||
rejectUnauthorized: false
|
rejectUnauthorized: false
|
||||||
|
@ -16,7 +16,6 @@ const httpsAgent = new https.Agent({
|
||||||
const ciscoAxios = create({
|
const ciscoAxios = create({
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
httpsAgent: httpsAgent,
|
httpsAgent: httpsAgent,
|
||||||
baseURL: `https://${process.env.CISCO_HOST}/`,
|
|
||||||
timeout: REQUEST_TIMEOUT_IN_MS,
|
timeout: REQUEST_TIMEOUT_IN_MS,
|
||||||
auth: {
|
auth: {
|
||||||
username: process.env.CISCO_USER,
|
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() {
|
function getDevices() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const source = CancelToken.source()
|
const source = CancelToken.source()
|
||||||
|
@ -43,17 +56,7 @@ function getDevices() {
|
||||||
|
|
||||||
const responsesPromises = []
|
const responsesPromises = []
|
||||||
|
|
||||||
try {
|
await renewSessionId()
|
||||||
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}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const firstResponse = await ciscoAxios.get(getDevicesUri(), {
|
const firstResponse = await ciscoAxios.get(getDevicesUri(), {
|
||||||
|
@ -76,7 +79,16 @@ function getDevices() {
|
||||||
page++
|
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)
|
clearTimeout(timeout)
|
||||||
|
|
||||||
|
@ -145,6 +157,8 @@ export function getAccessPoints() {
|
||||||
)
|
)
|
||||||
}, TIMEOUT_IN_MS)
|
}, TIMEOUT_IN_MS)
|
||||||
|
|
||||||
|
await renewSessionId()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
data: { Data: accessPoints }
|
data: { Data: accessPoints }
|
||||||
|
|
|
@ -10,7 +10,9 @@ async function generateStatsForNetwork(shortName) {
|
||||||
|
|
||||||
const dbStats = await prisma.wifiDevice.aggregate({
|
const dbStats = await prisma.wifiDevice.aggregate({
|
||||||
where: {
|
where: {
|
||||||
status: 'ONLINE',
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
},
|
||||||
network: {
|
network: {
|
||||||
shortName
|
shortName
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,9 @@ async function getDevicesWithUser() {
|
||||||
const wifiDevices = await prisma.wifiDevice.findMany({
|
const wifiDevices = await prisma.wifiDevice.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: { not: null },
|
userId: { not: null },
|
||||||
status: 'ONLINE',
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
},
|
||||||
lastSeen: { gt: timeoutThreshold }
|
lastSeen: { gt: timeoutThreshold }
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
|
|
@ -232,7 +232,9 @@ function updateDevicesInfo() {
|
||||||
include: {
|
include: {
|
||||||
wifiDevices: {
|
wifiDevices: {
|
||||||
where: {
|
where: {
|
||||||
status: 'ONLINE'
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,9 @@ export const AccessPoint = {
|
||||||
async clients(parent, data, context, info) {
|
async clients(parent, data, context, info) {
|
||||||
const clientsCount = await prisma.wifiDevice.count({
|
const clientsCount = await prisma.wifiDevice.count({
|
||||||
where: {
|
where: {
|
||||||
status: 'ONLINE',
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
},
|
||||||
accessPoint: {
|
accessPoint: {
|
||||||
id: parent.id
|
id: parent.id
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,9 @@ export async function accessPoint(parent, { id }, context, info) {
|
||||||
ip: 'asc'
|
ip: 'asc'
|
||||||
},
|
},
|
||||||
where: {
|
where: {
|
||||||
status: 'ONLINE'
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,9 @@ export async function accessPoints(_, { networkShortName }) {
|
||||||
network: true,
|
network: true,
|
||||||
wifiDevices: {
|
wifiDevices: {
|
||||||
where: {
|
where: {
|
||||||
status: 'ONLINE'
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,13 @@ const Stats = {
|
||||||
totalWifiDevices: async () => prisma.wifiDevice.count(),
|
totalWifiDevices: async () => prisma.wifiDevice.count(),
|
||||||
|
|
||||||
onlineWifiDevices: async () =>
|
onlineWifiDevices: async () =>
|
||||||
prisma.wifiDevice.count({ where: { status: 'ONLINE' } })
|
prisma.wifiDevice.count({
|
||||||
|
where: {
|
||||||
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Stats }
|
export { Stats }
|
||||||
|
|
|
@ -79,7 +79,9 @@ const User = {
|
||||||
onlineWifiDevicesCount: (parent, data, { auth }) =>
|
onlineWifiDevicesCount: (parent, data, { auth }) =>
|
||||||
prisma.wifiDevice.count({
|
prisma.wifiDevice.count({
|
||||||
where: {
|
where: {
|
||||||
status: 'ONLINE',
|
status: {
|
||||||
|
in: ['ONLINE', 'RECENT']
|
||||||
|
},
|
||||||
user: { id: parent.id }
|
user: { id: parent.id }
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user