Back

Version 7

1/9/2025
import { email } from "https://esm.town/v/std/email?v=11";
import { sqlite } from "https://esm.town/v/std/sqlite?v=6";

// Slack notification function
async function notifySlack(url: string, reason?: string, status?: number) {
const slackWebhookUrl = Deno.env.get("SLACK_WEBHOOK_URL");

if (!slackWebhookUrl) {
console.warn("Slack webhook URL not configured");
return;
}

const message = {
text: `:warning: Website Down Alert!
*URL:* ${url}
*Status:* ${status || "Error"}
*Reason:* ${reason || "Unknown error"}`,
};

try {
await fetch(slackWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(message),
});
} catch (error) {
console.error("Failed to send Slack notification:", error);
}
}

await sqlite.execute(
"CREATE TABLE IF NOT EXISTS uptime (id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT, ok INTEGER, reason TEXT, status INTEGER, duration INTEGER, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP);",
);

Updated: January 13, 2025