mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-07 00:39:53 +00:00
@@ -1,12 +1,8 @@
|
||||
import { MessageHandler } from "@server/routers/ws";
|
||||
import {
|
||||
db,
|
||||
Newt,
|
||||
sites
|
||||
} from "@server/db";
|
||||
import { db, Newt, sites } from "@server/db";
|
||||
import { eq } from "drizzle-orm";
|
||||
import logger from "@server/logger";
|
||||
import { fireSiteOfflineAlert } from "#dynamic/lib/alerts";
|
||||
import { fireSiteOfflineAlert } from "@server/lib/alerts";
|
||||
|
||||
/**
|
||||
* Handles disconnecting messages from sites to show disconnected in the ui
|
||||
@@ -38,7 +34,13 @@ export const handleNewtDisconnectingMessage: MessageHandler = async (
|
||||
.where(eq(sites.siteId, newt.siteId!))
|
||||
.returning();
|
||||
|
||||
await fireSiteOfflineAlert(site.orgId, site.siteId, site.name, undefined, trx);
|
||||
await fireSiteOfflineAlert(
|
||||
site.orgId,
|
||||
site.siteId,
|
||||
site.name,
|
||||
undefined,
|
||||
trx
|
||||
);
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error("Error handling disconnecting message", { error });
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import {
|
||||
db,
|
||||
newts,
|
||||
sites
|
||||
} from "@server/db";
|
||||
import { db, newts, sites } from "@server/db";
|
||||
import { hasActiveConnections } from "#dynamic/routers/ws";
|
||||
import { eq, lt, isNull, and, or, ne, not, inArray } from "drizzle-orm";
|
||||
import logger from "@server/logger";
|
||||
import { fireSiteOfflineAlert, fireSiteOnlineAlert } from "#dynamic/lib/alerts";
|
||||
import { fireSiteOfflineAlert, fireSiteOnlineAlert } from "@server/lib/alerts";
|
||||
|
||||
// Track if the offline checker interval is running
|
||||
let offlineCheckerInterval: NodeJS.Timeout | null = null;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { db } from "@server/db";
|
||||
import { sites, clients, olms } from "@server/db";
|
||||
import { and, eq, inArray } from "drizzle-orm";
|
||||
import logger from "@server/logger";
|
||||
import { fireSiteOnlineAlert } from "#dynamic/lib/alerts";
|
||||
import { fireSiteOnlineAlert } from "@server/lib/alerts";
|
||||
|
||||
/**
|
||||
* Ping Accumulator
|
||||
@@ -127,7 +127,11 @@ async function flushSitePingsToDb(): Promise<void> {
|
||||
eq(sites.online, false)
|
||||
)
|
||||
)
|
||||
.returning({ siteId: sites.siteId, orgId: sites.orgId, name: sites.name });
|
||||
.returning({
|
||||
siteId: sites.siteId,
|
||||
orgId: sites.orgId,
|
||||
name: sites.name
|
||||
});
|
||||
|
||||
// Update lastPing for sites that were already online.
|
||||
// After the update above, the newly-online sites now have
|
||||
@@ -148,7 +152,13 @@ async function flushSitePingsToDb(): Promise<void> {
|
||||
|
||||
for (const site of newlyOnlineSites) {
|
||||
await db.transaction(async (trx) => {
|
||||
await fireSiteOnlineAlert(site.orgId, site.siteId, site.name, undefined, trx);
|
||||
await fireSiteOnlineAlert(
|
||||
site.orgId,
|
||||
site.siteId,
|
||||
site.name,
|
||||
undefined,
|
||||
trx
|
||||
);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
fireHealthCheckHealthyAlert,
|
||||
fireHealthCheckUnhealthyAlert,
|
||||
fireHealthCheckUnknownAlert
|
||||
} from "#dynamic/lib/alerts";
|
||||
} from "@server/lib/alerts";
|
||||
|
||||
const createTargetParamsSchema = z.strictObject({
|
||||
resourceId: z.string().transform(Number).pipe(z.int().positive())
|
||||
|
||||
@@ -6,7 +6,7 @@ import logger from "@server/logger";
|
||||
import {
|
||||
fireHealthCheckHealthyAlert,
|
||||
fireHealthCheckUnhealthyAlert
|
||||
} from "#dynamic/lib/alerts";
|
||||
} from "@server/lib/alerts";
|
||||
|
||||
interface TargetHealthStatus {
|
||||
status: string;
|
||||
|
||||
@@ -10,7 +10,11 @@ import logger from "@server/logger";
|
||||
import { fromError } from "zod-validation-error";
|
||||
import { addPeer } from "../gerbil/peers";
|
||||
import { addTargets } from "../newt/targets";
|
||||
import { fireHealthCheckHealthyAlert, fireHealthCheckUnknownAlert, fireHealthCheckUnhealthyAlert } from "#dynamic/lib/alerts";
|
||||
import {
|
||||
fireHealthCheckHealthyAlert,
|
||||
fireHealthCheckUnknownAlert,
|
||||
fireHealthCheckUnhealthyAlert
|
||||
} from "@server/lib/alerts";
|
||||
import { pickPort } from "./helpers";
|
||||
import { isTargetValid } from "@server/lib/validators";
|
||||
import { OpenAPITags, registry } from "@server/openApi";
|
||||
@@ -169,7 +173,7 @@ export async function updateTarget(
|
||||
let updatedTarget: any;
|
||||
let updatedHc: any;
|
||||
await db.transaction(async (trx) => {
|
||||
[updatedTarget] = await trx
|
||||
[updatedTarget] = await trx
|
||||
.update(targets)
|
||||
.set({
|
||||
siteId: parsedBody.data.siteId,
|
||||
@@ -181,8 +185,12 @@ export async function updateTarget(
|
||||
path: parsedBody.data.path,
|
||||
pathMatchType: parsedBody.data.pathMatchType,
|
||||
priority: parsedBody.data.priority,
|
||||
rewritePath: pathMatchTypeRemoved ? null : parsedBody.data.rewritePath,
|
||||
rewritePathType: pathMatchTypeRemoved ? null : parsedBody.data.rewritePathType
|
||||
rewritePath: pathMatchTypeRemoved
|
||||
? null
|
||||
: parsedBody.data.rewritePath,
|
||||
rewritePathType: pathMatchTypeRemoved
|
||||
? null
|
||||
: parsedBody.data.rewritePathType
|
||||
})
|
||||
.where(eq(targets.targetId, targetId))
|
||||
.returning();
|
||||
@@ -213,7 +221,8 @@ export async function updateTarget(
|
||||
// If hcEnabled is being turned on (was false, now true), set to "unhealthy"
|
||||
// so the target must pass a health check before being considered healthy.
|
||||
const hcEnabledTurnedOn =
|
||||
parsedBody.data.hcEnabled === true && existingHc.hcEnabled === false;
|
||||
parsedBody.data.hcEnabled === true &&
|
||||
existingHc.hcEnabled === false;
|
||||
|
||||
let hcHealthValue: "unknown" | "healthy" | "unhealthy" | undefined;
|
||||
if (
|
||||
@@ -253,7 +262,10 @@ export async function updateTarget(
|
||||
.where(eq(targetHealthCheck.targetId, targetId))
|
||||
.returning();
|
||||
|
||||
if (updatedHc.hcHealth === "unhealthy" && existingHc.hcHealth !== "unhealthy") {
|
||||
if (
|
||||
updatedHc.hcHealth === "unhealthy" &&
|
||||
existingHc.hcHealth !== "unhealthy"
|
||||
) {
|
||||
logger.debug(
|
||||
`Health check ${updatedHc.targetHealthCheckId} for target ${targetId} is now unhealthy, firing alert`
|
||||
);
|
||||
@@ -266,7 +278,10 @@ export async function updateTarget(
|
||||
false, // dont send the alert because we just want to create the alert, not notify users yet
|
||||
trx
|
||||
);
|
||||
} else if (updatedHc.hcHealth === "unknown" && existingHc.hcHealth !== "unknown") {
|
||||
} else if (
|
||||
updatedHc.hcHealth === "unknown" &&
|
||||
existingHc.hcHealth !== "unknown"
|
||||
) {
|
||||
logger.debug(
|
||||
`Health check ${updatedHc.targetHealthCheckId} for target ${targetId} is now unknown, firing alert`
|
||||
);
|
||||
@@ -280,7 +295,10 @@ export async function updateTarget(
|
||||
false, // dont send the alert because we just want to create the alert, not notify users yet
|
||||
trx
|
||||
);
|
||||
} else if (updatedHc.hcHealth === "healthy" && existingHc.hcHealth !== "healthy") {
|
||||
} else if (
|
||||
updatedHc.hcHealth === "healthy" &&
|
||||
existingHc.hcHealth !== "healthy"
|
||||
) {
|
||||
logger.debug(
|
||||
`Health check ${updatedHc.targetHealthCheckId} for target ${targetId} is now healthy, firing alert`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user