Webhooks
A webhook destination gets a JSON POST for every alert notice. Add one in
Settings › Alert destinations with the URL and, optionally, a secret.
The request
Section titled “The request”POST /hooks/bullship HTTP/1.1Content-Type: application/jsonX-Bullship-Signature: sha256=5d1c…
{ "event": "alert.fired", "rule": "Email failing", "connection": "Production", "queue": "email", "value": 73, "threshold": 50, "window": "5 min", "url": "https://bullship.example.com/#/c/production/alerts"}| Field | |
|---|---|
event |
alert.fired, alert.resolved, or alert.test for Send test |
rule |
The rule’s name |
connection |
The connection’s name |
queue |
The queue, or null for rules on the whole Redis (memory, unreachable) |
value |
The reading that fired or resolved it |
threshold |
The rule’s threshold, or null for rules without one |
window |
For failed and stalled jobs, the window counted, such as 5 min or 1 h; otherwise null |
url |
A link to the connection’s Alerts page, or null when Bullship doesn’t know its address |
Bullship counts any 2xx answer as delivered. It doesn’t follow redirects, so a 3xx is a failed
send, and it gives up on a request after 10 seconds. Failed sends are retried with backoff (see
Alerts).
Check the signature
Section titled “Check the signature”With a secret, every request carries X-Bullship-Signature: sha256=<hex>, the HMAC-SHA256 of the
raw request body with the secret as the key. Check it against the body as received, before parsing
it:
import { createHmac, timingSafeEqual } from 'node:crypto'import { createServer } from 'node:http'
const secret = process.env.BULLSHIP_WEBHOOK_SECRET
createServer(async (req, res) => { const chunks = [] for await (const chunk of req) chunks.push(chunk) const body = Buffer.concat(chunks)
const expected = 'sha256=' + createHmac('sha256', secret).update(body).digest('hex') const got = req.headers['x-bullship-signature'] ?? '' const ok = got.length === expected.length && timingSafeEqual(Buffer.from(got), Buffer.from(expected)) if (!ok) return res.writeHead(401).end()
const alert = JSON.parse(body) console.log(alert.event, alert.rule, alert.queue, alert.value) res.writeHead(204).end()}).listen(4999)Answering 401 to a bad signature shows up in Bullship: Send test reports
401 Unauthorized, and alert history lists the send as failed.
Reaching private addresses
Section titled “Reaching private addresses”A webhook can point at a host on your own network. If admins shouldn’t be able to make Bullship
call into its network, set BULLSHIP_BLOCK_PRIVATE_ADDRESSES=true: destinations on loopback,
private, link-local and other non-public addresses are then refused, checked when Bullship sends.