Website Downtime Alert

This val checks the availability of a specified website. If it's down or not returning a 200 OK status, it triggers an email alert. The email includes the date, time (in UTC), and the reason for the downtime, providing a way to monitor website availability.

Fork this val and edit the URL variable to set up downtime notifications for your website.

Readme
Runs every 1 hrs
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { email } from "https://esm.town/v/std/email";
export const isMyWebsiteDown = async () => {
// Replace this URL with the website you want to track
const URL = "https://andreterron.com";
const [date, time] = new Date().toISOString().split("T");
let ok = true;
let reason: string;
try {
const res = await fetch(URL, { redirect: "follow" });
if (res.status !== 200) {
reason = `(status code: ${res.status})`;
ok = false;
}
} catch (e) {
reason = `couldn't fetch: ${e}`;
ok = false;
}
if (!ok) {
const subject = `Website down (${URL})`;
const text = `At ${date} ${time} (UTC), ${URL} was down (reason: ${reason}).`;
console.log(subject, text);
await email({ subject, text });
} else {
console.log("Website ok");
}
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.