Readme

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.

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
29
30
31
32
33
34
35
36
37
38
39
import { email } from "https://esm.town/v/std/email";
const URLS = [
"https://think.ing.com",
"https://terralemon.nl",
];
const isMyWebsiteDown = async (URL) => {
// Replace this URL with the website you want to track
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}, ${URL} was down (reason: ${reason}).`;
console.log(subject, text);
await email({ subject, text });
} else {
console.log(`${URL} is up!`);
}
};
const main = async () => {
for (const URL of URLS) {
await isMyWebsiteDown(URL);
}
};
export default main;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 24, 2024