feat(notification): error monitoring
if there are more than 10 errors in a 15min window sends email to alert someone
This commit is contained in:
50
lstV2/server/services/notifications/routes/tooManyErrors.ts
Normal file
50
lstV2/server/services/notifications/routes/tooManyErrors.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
// an external way to creating logs
|
||||
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../../../database/dbclient.js";
|
||||
import { notifications } from "../../../../database/schema/notifications.js";
|
||||
import { apiHit } from "../../../globalUtils/apiHits.js";
|
||||
import { responses } from "../../../globalUtils/routeDefs/responses.js";
|
||||
import { tryCatch } from "../../../globalUtils/tryCatch.js";
|
||||
import { authMiddleware } from "../../auth/middleware/authMiddleware.js";
|
||||
import hasCorrectRole from "../../auth/middleware/roleCheck.js";
|
||||
import tooManyErrors from "../controller/notifications/tooManyErrors.js";
|
||||
import { getAllJobs } from "../utils/processNotifications.js";
|
||||
|
||||
const app = new OpenAPIHono({ strict: false });
|
||||
|
||||
app.openapi(
|
||||
createRoute({
|
||||
tags: ["server"],
|
||||
summary: "Returns current active notifications.",
|
||||
method: "get",
|
||||
path: "/toomanyerrors",
|
||||
middleware: [authMiddleware, hasCorrectRole(["systemAdmin"], "admin")],
|
||||
responses: responses(),
|
||||
}),
|
||||
async (c) => {
|
||||
apiHit(c, { endpoint: "/toomanyerrors" });
|
||||
|
||||
const { data, error } = await tryCatch(
|
||||
db
|
||||
.select()
|
||||
.from(notifications)
|
||||
.where(eq(notifications.name, "tooManyErrors")),
|
||||
);
|
||||
|
||||
if (error) {
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "Error Getting Notification Settings.",
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
const errorData = await tooManyErrors(data[0]);
|
||||
return c.json({
|
||||
success: true,
|
||||
message: "Current Error log data",
|
||||
data: errorData?.data,
|
||||
});
|
||||
},
|
||||
);
|
||||
export default app;
|
||||
Reference in New Issue
Block a user