fix(api): исключить выключенные серверы из мониторинга
This commit is contained in:
1 parent
f3e205950f
commit
4c12c55c9d
10 files changed
+160
-18
No files matched your search
@@ -0,0 +1,11 @@
|
||||
import { eq } from "drizzle-orm"
|
||||
import { db } from "../db/index.js"
|
||||
import { servers } from "../db/schema.js"
|
||||
|
||||
export async function listEnabledMonitoringServers() {
|
||||
return db.select().from(servers).where(eq(servers.enabled, true))
|
||||
}
|
||||
|
||||
export function assertMonitoringServersEnabled(...targets: { enabled: boolean }[]): void {
|
||||
if (targets.some(server => !server.enabled)) throw new Error("Сервер отключён: включите его перед запуском теста")
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { eq, or } from "drizzle-orm"
|
||||
import { eq } from "drizzle-orm"
|
||||
import { listEnabledMonitoringServers } from "./monitoring-server-catalog.js"
|
||||
import { db, dbAll, dbQuery } from "../db/index.js"
|
||||
import { servers, serversApiPingSettings, serversRestPingSamples } from "../db/schema.js"
|
||||
import { serversApiPingSettings, serversRestPingSamples } from "../db/schema.js"
|
||||
import type { ServersRestPingRunSnapshot } from "../types/scheduler-run-snapshot.js"
|
||||
import { SCHEDULER_RUN_SNAPSHOT_VERSION } from "../types/scheduler-run-snapshot.js"
|
||||
import { MikrotikClient } from "./mikrotik.js"
|
||||
@@ -21,12 +22,9 @@ async function getSettingsRow() {
|
||||
return (await db.select().from(serversApiPingSettings).where(eq(serversApiPingSettings.id, 1)).limit(1))[0]
|
||||
}
|
||||
|
||||
/** Как uptime: включённые в каталоге или Home Router (часто «выкл.» при доступе только из LAN). */
|
||||
/** Same enabled-only policy as uptime. */
|
||||
async function serversForRestProbe() {
|
||||
return await db
|
||||
.select()
|
||||
.from(servers)
|
||||
.where(or(eq(servers.enabled, true), eq(servers.type, "home-router")))
|
||||
return listEnabledMonitoringServers()
|
||||
}
|
||||
|
||||
export async function getServersApiPingSettings() {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { replacePingProbes } from "./ping-probe-replacement.js"
|
||||
import type { PingProbeWrite } from "@mmapp/contracts"
|
||||
import { and, asc, eq, gte, inArray, max, or, sql } from "drizzle-orm"
|
||||
import { and, asc, eq, gte, inArray, max, sql } from "drizzle-orm"
|
||||
import { listEnabledMonitoringServers } from "./monitoring-server-catalog.js"
|
||||
import { db } from "../db/index.js"
|
||||
import {
|
||||
servers,
|
||||
uptimeProbeSamples,
|
||||
uptimeProbes,
|
||||
uptimeResourceSamples,
|
||||
@@ -95,12 +95,9 @@ export function parsePing(results: Array<{ time?: string; status?: string; sent?
|
||||
return { avgRtt, loss, status }
|
||||
}
|
||||
|
||||
/** Узлы с REST-опросом для uptime: включённые в каталоге или любой Home Router (см. /servers — HR часто «выкл.» при доступе только из LAN). */
|
||||
/** Disabled excludes every server type from resource and ping collection. */
|
||||
async function serversForUptimeRosPoll() {
|
||||
return await db
|
||||
.select()
|
||||
.from(servers)
|
||||
.where(or(eq(servers.enabled, true), eq(servers.type, "home-router")))
|
||||
return listEnabledMonitoringServers()
|
||||
}
|
||||
|
||||
async function lastProbeSampleTimes(): Promise<Map<string, string>> {
|
||||
|
||||
@@ -87,6 +87,7 @@ export async function executeBandwidthSpeedTestInner(params: SpeedTestRunParams)
|
||||
const src = (await db.select().from(servers).where(eq(servers.id, srcId)).limit(1))[0]
|
||||
const dst = (await db.select().from(servers).where(eq(servers.id, dstId)).limit(1))[0]
|
||||
if (!src || !dst) throw new Error("Server not found")
|
||||
assertMonitoringServersEnabled(src, dst)
|
||||
|
||||
const protocol = params.protocol === "udp" ? "udp" : "tcp"
|
||||
const direction = params.direction === "transmit" || params.direction === "receive" ? params.direction : "both"
|
||||
@@ -284,7 +285,9 @@ export async function runScheduledSpeedProbesOnce(): Promise<SpeedScheduledRunSn
|
||||
const sampledAt = new Date().toISOString()
|
||||
const runs: SpeedRunSnapshot[] = []
|
||||
const rows = await db.select().from(uptimeSpeedProbes).orderBy(asc(uptimeSpeedProbes.sortOrder))
|
||||
const enabled = rows.filter((r) => r.enabled !== false && r.srcServerId !== r.dstServerId)
|
||||
const enabledIds = new Set((await listEnabledMonitoringServers()).map(server => server.id))
|
||||
const enabled = rows.filter((r) => r.enabled !== false && r.srcServerId !== r.dstServerId
|
||||
&& enabledIds.has(r.srcServerId) && enabledIds.has(r.dstServerId))
|
||||
const protocol = (p: (typeof enabled)[number]) => (p.protocol === "udp" ? "udp" : "tcp")
|
||||
const direction = (p: (typeof enabled)[number]) =>
|
||||
p.direction === "transmit" || p.direction === "receive" ? p.direction : "both"
|
||||
@@ -356,3 +359,4 @@ export async function runScheduledSpeedProbesOnce(): Promise<SpeedScheduledRunSn
|
||||
runs,
|
||||
}
|
||||
}
|
||||
import { assertMonitoringServersEnabled, listEnabledMonitoringServers } from "./monitoring-server-catalog.js"
|
||||
Reference in new issue
Block a user