Templates / Scheduled jobs

Uptime monitor with Slack alerts, checked every 5 minutes

A scheduled function that checks your URLs every 5 minutes and alerts Slack when a site goes down — and again when it recovers.

A minimal uptime monitor: every five minutes it requests each URL, remembers whether it was up, and only messages Slack when something changes — so you get “down” and “back up”, not a ping every five minutes.

Build it with Wisp

Type this into Wisp, or press Build this — it writes the code below, deploys it and gives you a URL:

Every 5 minutes, check each URL in the URLS variable (comma-separated) with a 10-second timeout. When one changes between up and down, post to Slack via SLACK_WEBHOOK_URL with the status code or error.

The code

*check-uptime · schedule `/5 * * * `*

import { config, kv } from 'wisp';

async function slack(text) {
  await fetch(config.require('SLACK_WEBHOOK_URL'), {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({ text }),
  });
}

async function probe(url) {
  const started = Date.now();
  try {
    const res = await fetch(url, { redirect: 'follow', signal: AbortSignal.timeout(10_000) });
    return { up: res.status < 500, detail: `HTTP ${res.status}`, ms: Date.now() - started };
  } catch (err) {
    return { up: false, detail: err.name === 'TimeoutError' ? 'timed out after 10s' : err.message, ms: Date.now() - started };
  }
}

export async function handler() {
  const urls = config.require('URLS').split(',').map((u) => u.trim()).filter(Boolean);
  const results = await Promise.all(urls.map(async (url) => ({ url, ...(await probe(url)) })));
  for (const r of results) {
    const was = await kv.get(`up:${r.url}`);
    if (was !== null && was !== r.up) {
      await slack(r.up ? `:white_check_mark: ${r.url} is back up (${r.detail}, ${r.ms} ms)` : `:rotating_light: ${r.url} is DOWN — ${r.detail}`);
    }
    await kv.set(`up:${r.url}`, r.up);
  }
  return results;
}

Set it up

Add these in the project’s Variables & secrets (secrets are encrypted and never shown in logs):

Try it

Press Run on the function to check now — the return value lists each URL with its status and response time. Add a URL that doesn’t exist to see the alert, then remove it.

How it works

Variations

Questions

Can it check every minute? Wisp’s shortest schedule is every 5 minutes. For one-minute checks, use a dedicated monitoring service.

Build it with Wisp — free trial

Related