diff --git a/app/src/pkg/utils/notify.ts b/app/src/pkg/utils/notify.ts new file mode 100644 index 0000000..3418c91 --- /dev/null +++ b/app/src/pkg/utils/notify.ts @@ -0,0 +1,45 @@ +import type { Log } from "../db/schema/logs.js"; +import { validateEnv } from "../utils/envValidator.js"; + +const env = validateEnv(process.env); + +export async function sendNotify(log: any) { + const webhookUrl = process.env.WEBHOOK_URL!; + let payload = { + embeds: [ + { + title: `🚨 ${env.PROD_PLANT_TOKEN}: encounter a critical error `, + description: `Where was the error: ${log.module}${ + log.subModule ? `-${log.subModule}` : "" + }`, + color: 0xff0000, // red + fields: [ + { + name: "Message", + value: log.message, + inline: false, + }, + { + name: "Hostname", + value: log.hostname, + inline: false, + }, + { + name: "Stack", + value: "```" + (log.stack ?? "no stack") + "```", + }, + ], + footer: { + text: "LST Logger 💀", + }, + timestamp: new Date().toISOString(), + }, + ], + }; + + await fetch(webhookUrl, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(payload), + }); +} diff --git a/migrations/0002_mean_nuke.sql b/migrations/0002_mean_nuke.sql new file mode 100644 index 0000000..381f15f --- /dev/null +++ b/migrations/0002_mean_nuke.sql @@ -0,0 +1,2 @@ +ALTER TABLE "logs" ALTER COLUMN "stack" SET DATA TYPE jsonb;--> statement-breakpoint +ALTER TABLE "logs" ALTER COLUMN "stack" SET DEFAULT '[]'::jsonb; \ No newline at end of file diff --git a/migrations/meta/0002_snapshot.json b/migrations/meta/0002_snapshot.json new file mode 100644 index 0000000..ca3091b --- /dev/null +++ b/migrations/meta/0002_snapshot.json @@ -0,0 +1,192 @@ +{ + "id": "922093ba-6949-4d30-9c17-007257754cf2", + "prevId": "5eac3348-eeab-4210-b686-29e570f87911", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.logs": { + "name": "logs", + "schema": "", + "columns": { + "log_id": { + "name": "log_id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "module": { + "name": "module", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subModule": { + "name": "subModule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "stack": { + "name": "stack", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + }, + "checked": { + "name": "checked", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "hostname": { + "name": "hostname", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.settings": { + "name": "settings", + "schema": "", + "columns": { + "settings_id": { + "name": "settings_id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "moduleName": { + "name": "moduleName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "roles": { + "name": "roles", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[\"systemAdmin\"]'::jsonb" + }, + "add_User": { + "name": "add_User", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'LST_System'" + }, + "add_Date": { + "name": "add_Date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "upd_User": { + "name": "upd_User", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'LST_System'" + }, + "upd_date": { + "name": "upd_date", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "name": { + "name": "name", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/migrations/meta/_journal.json b/migrations/meta/_journal.json index b503dbf..1509705 100644 --- a/migrations/meta/_journal.json +++ b/migrations/meta/_journal.json @@ -15,6 +15,13 @@ "when": 1756693049476, "tag": "0001_solid_kronos", "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1756843987534, + "tag": "0002_mean_nuke", + "breakpoints": true } ] } \ No newline at end of file