Alerting and subscriptions
Alerting turns monitor results into stateful alert decisions and sends the result to configured notification targets. It can also create an incident whose public updates notify people who subscribe to incident events. The system keeps alert state, incident state, message content, and delivery as related but separate concerns.
Alerting model
Alerting has two notification paths. A monitor alert uses alert-specific triggers and sends a message to the target set on each trigger. An incident subscription uses the incident comment timeline and sends updates to active subscribers.
| Path | Starts with | Audience | Main purpose |
|---|---|---|---|
| Alert notification | A TRIGGERED or RESOLVED monitor alert | Recipients or endpoints on linked triggers | Send an immediate alert message |
| Subscriber notification | A comment on an incident | Active subscribers to incidents | Share the incident update with subscribed people |
This split prevents one alert from being treated as two copies of the same event. An alert-created incident uses its comment as the subscriber event, while the alert trigger path sends the alert message.
Alert configuration
An alert configuration defines the condition, the monitors it covers, and the response to a match. The configuration can apply to one or more monitors and can link to several notification triggers. The management page exposes these choices as one unit so that a rule and its recipients remain connected. The first meaningful source is src/…/+page.svelte.
The rule has these main settings:
- Alert type:
STATUS,LATENCY, orUPTIME. - Alert value: A target status, a latency limit in milliseconds, or an uptime percentage.
- Failure threshold: The number of consecutive failing checks before the alert starts.
- Success threshold: The number of consecutive recovering checks before the alert resolves.
- Severity and description: Context added to the alert and incident message.
- Create incident: Whether a new alert also creates an incident.
- Active state: Whether the rule is considered for new alert decisions.
- Notification triggers: The delivery targets used for alert messages.
The rule accepts DOWN or DEGRADED for status alerts. Latency must be positive, uptime must be between 0 and 100, and both thresholds must be positive whole numbers. These limits make the rule meaningful before it reaches the state evaluator.
References: src/…/+page.svelte• L49-80 src/…/monitorAlertConfigController.ts• L35-117 src/…/db.ts• L656-749
Notification triggers
A trigger is a named target with a type and message settings. Alert configurations select triggers by ID, so the same target can serve several alert rules. The supported target types are email, webhook, Discord, and Slack. The trigger page asks for a URL for non-email targets and recipient and sender details for email.
Each trigger stores a message body for its type. A webhook can also store request headers. The trigger can be tested from the management page before it is used by an alert.
References: src/…/+page.svelte• L51-75 src/…/+page.svelte• L138-228 src/…/db.ts• L172-212
State evaluation
The state evaluator receives stored monitoring results after the monitor response path records them. It checks each active configuration for the affected monitor, then changes the alert only when the configured failure or recovery evidence is complete.
This diagram shows how one monitor result moves through storage, rule evaluation, alert state, incident updates, and alert delivery.
flowchart LR
A[Monitor result] --> B[Store monitoring result]
B --> C[Queue alert checks]
C --> D{Rule condition met?}
D -- No --> E[Keep current alert state]
D -- Yes, no active alert --> F[Create TRIGGERED alert]
F --> G{Create incident?}
G -- Yes --> H[Create incident and comment]
G -- No --> I[Send alert notifications]
H --> I
D -- Recovery complete --> J[Mark alert RESOLVED]
J --> K[Resolve linked incident]
K --> I
Monitor result flow
The monitor response path first stores the result and updates the latest monitor value. It then submits an alert job for the monitor. The alert queue loads only active configurations for that monitor and evaluates each configuration separately. The alert job uses a monitor tag and timestamp as its identity, with the configuration ID added so separate rules do not merge.
This order gives the evaluator the stored history that it needs for consecutive checks. It also means a monitor with no active alert configuration has no alert decision to make.
References: src/…/monitorResponseQueue.ts• L33-60 src/…/alertingQueue.ts• L289-349
Alert lifecycle
An alert has two states: TRIGGERED and RESOLVED. For a status rule, the system counts consecutive matches to the selected status. For a latency rule, it checks consecutive values above the limit. For an uptime rule, it checks whether the calculated uptime stays below the limit for the required checks.
The evaluator creates one active alert for a monitor and configuration pair. Later failing checks do not create another alert or send another trigger message. On recovery, the evaluator applies the matching success rule. It leaves the alert active until the success threshold is met, then marks it resolved and sends a resolution message.
References: src/…/alertingQueue.ts• L177-273 src/…/monitorAlertConfigController.ts• L431-512 src/…/monitorAlertConfig.ts• L523-580
Incident linkage
When create_incident is enabled, the first triggered alert creates an incident with source ALERT. The incident receives an opening comment and a monitor link, then the alert stores the incident ID. On resolution, the alert adds a closure comment with the alert duration and marks the incident resolved.
The alert and incident remain separate records. This lets the alert track the rule state while the incident provides a user-facing timeline. If an incident already has a resolved state or cannot be found, the close step does not create another update.
References: src/…/alertingQueue.ts• L59-109 src/…/incidentController.ts• L236-299 src/…/db.ts• L765-801
Notification content
Alert messages use a shared set of alert and site values. The alert values describe the rule and its state. Site values add the site name, links, logo, and status colors. The same values can render as HTML, JSON, Slack blocks, or Discord embeds.
Alert templates
The alert path builds variables before it sends a message. These variables include the alert ID, name, type, value, status, severity, description, timestamp, thresholds, monitor link, and optional incident link. Boolean values identify whether the message describes a trigger or a resolution.
Trigger bodies use Mustache placeholders. The built-in templates provide a useful format for each target, and a trigger can replace that body with a custom template. Email rendering produces HTML and derives plain text when no text body is supplied. Webhook, Slack, and Discord messages render without HTML escaping so their JSON payloads remain usable.
References: src/…/notification_utils.ts• L9-49 src/…/email_alert_template.ts• L81-157 src/…/webhook_alert_template.ts• L1-22 src/…/slack_alert_template.ts• L1-107 src/…/discord_alert_template.ts• L1-64
Incident subscription content
An incident comment is the public update that drives incident subscriptions. The notification includes the incident title, a link to the incident, the rendered comment text, the comment state, and the comment ID. Its event type is incidents, so the subscriber service can select only people who asked for incident updates.
The notification uses the general subscription_update email template rather than an alert trigger template. This keeps the incident timeline format consistent for incidents created by an alert, by the dashboard, or through the API.
References: src/…/incidentController.ts• L424-489 src/…/subscriberQueue.ts• L33-69 src/…/generalTemplateController.ts• L7-32 src/…/db.ts• L31-39
Delivery lifecycle
The system separates the decision to notify from the work of sending. Alert evaluation queues a job and then invokes the selected target senders. Incident subscriber updates pass through a subscriber queue and then create one email job per recipient.
Alert delivery
After an alert changes state, the alert queue loads every trigger linked to the configuration. It renders the selected template with alert and site values, then sends through the matching provider path. An email trigger may address several configured recipients. A webhook, Slack, or Discord trigger sends one rendered request to its configured endpoint.
Provider settings can contain references to environment secrets. The sender replaces those references before it renders the message or builds the request. Email delivery uses either Resend or SMTP, based on the available email setup. The detailed provider behavior belongs on the child page Alert routing and delivery.
References: src/…/alertingQueue.ts• L111-165 src/…/email_notification.ts• L20-75 src/…/webhook_notification.ts• L13-79 src/…/slack_notification.ts• L10-57 src/…/discord_notification.ts• L10-57
Subscriber delivery
When an incident comment is created, the controller sends one subscriber job with a stable comment-based identity. The subscriber worker loads the general email template and finds active email subscribers for the incidents event. It then queues one email job per address so recipients do not share a message recipient list.
The email worker renders the final subject and body and hands them to the email sender. A sender error is raised from the email job so the queue can apply its retry policy. A missing subscription template stops the subscriber job before it queues recipient emails.
References: src/…/incidentController.ts• L430-453 src/…/subscriberQueue.ts• L33-75 src/…/emailQueue.ts• L33-53 src/…/db.ts• L849-919
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to alert states or threshold rules must preserve the per-monitor and per-configuration active-alert lookup. Otherwise one rule can suppress or duplicate another.
- Changes to incident-created alert flow must preserve the single subscriber event from the incident comment. Adding a second alert-side subscriber push causes duplicate incident emails.
- Changes to alert variables must be reflected in the built-in templates and in the custom-template variable help shown on the trigger page.
- Changes to trigger metadata must stay aligned with the trigger editor, the trigger type, and the matching provider sender.
- Changes to subscriber event names or status rules must stay aligned with the subscription records and the subscriber worker's active-recipient query.
- Changes to email template IDs must update both the template management path and every queue that loads the template.
- Changes to queue identity or retry behavior must preserve per-minute monitor alert deduplication and the stable incident-comment subscriber identity.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No active alert configuration matches a monitor | The monitoring result is stored, but no alert or alert message is created | Enable the rule and attach the monitor to it |
| Failure threshold is not reached | A failing check does not start an alert | Set the threshold to the required number of consecutive failures |
| Recovery threshold is not reached | A triggered alert remains active and no resolution message is sent | Wait for the configured consecutive recovery checks |
| A rule has no linked notification triggers | Alert state changes are recorded without a direct target notification | Link at least one trigger to the alert configuration |
| Email is not configured for an email trigger or subscriber | The email sender rejects the job | Configure Resend or SMTP before enabling email delivery |
| A custom JSON body or header value is invalid | The endpoint can reject the rendered request, or the custom header data can be ignored | Validate the custom payload and headers with a test trigger |
The subscription_update template is missing | The subscriber job cannot queue recipient emails | Keep the general subscription template available |
| An alert-created incident sends its own direct subscriber push | Subscribers receive duplicate incident messages | Use the incident comment as the only subscriber event |
| A queue job uses the wrong identity | Repeated monitor checks can merge incorrectly, or one incident update can create duplicate emails | Keep monitor jobs keyed by monitor time and alert jobs keyed by monitor time plus configuration; key subscriber jobs by comment |
Key files
| File | Why to read it |
|---|---|
| src/…/monitorResponseQueue.ts | Shows how stored monitor results enter alert evaluation. |
| src/…/alertingQueue.ts | Shows the alert decision, incident linkage, and direct notification sequence. |
| src/…/monitorAlertConfigController.ts | Defines valid alert settings and alert state changes. |
| src/…/+page.svelte | Shows the product-facing alert rule and monitor configuration. |
| src/…/+page.svelte | Shows target types, endpoint fields, and custom template choices. |
| src/…/incidentController.ts | Shows how incident comments become subscriber events. |
| src/…/subscriberQueue.ts | Shows subscriber selection and the handoff to per-recipient email jobs. |
| src/…/emailQueue.ts | Shows the final queued email send step. |
| src/…/notification_utils.ts | Defines the values shared by alert templates. |
| src/…/email_alert_template.ts | Illustrates the default alert email content and placeholders. |
| src/…/db.ts | Defines the alert, trigger, incident subscription, and template contracts. |