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):
URLS— A variable: the pages to check, comma-separated, e.g.https://example.com,https://api.example.com/health.SLACK_WEBHOOK_URL— Slack → Apps → Incoming Webhooks → Add to a channel.
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
- Each run checks all URLs in parallel with a 10-second timeout.
- The last state per URL lives in key-value storage, so alerts fire only on changes.
- Status 5xx or a network error counts as down; 4xx counts as up (the server answered).
Variations
- Require two failures in a row before alerting, to avoid blips.
- Check that the page contains a word, not just the status code.
- Keep response times in a table and chart them.
- Expose a GET endpoint that returns the current status for a status page.
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