Skip to content
betterstack-alchemyUnofficial

Incidents.Heartbeat

Kind ResourceType id BetterStack.Incidents.HeartbeatSource src/Incidents/Heartbeat.tsLive test gated Lifecycle test runs against the offline mock; a live run exists but is gated behind BETTERSTACK_TEST_ESCALATION_POLICIES=1 because the main lifecycle runs live, but the cases that need it are gated: escalation policies need a paid plan (test/Incidents/Heartbeat.test.ts).

A Better Stack Uptime heartbeat: watches a cron job or background service. The job requests the heartbeat’s url on a schedule (every period seconds), and Better Stack alerts when a request doesn’t arrive within grace seconds after that.

Every prop updates in place; only teamId replaces the heartbeat. name defaults to a generated unique name. Removing a nullable prop from the config (heartbeatGroupId, escalationPolicyId, sortIndex, teamWait, the maintenance window, serverTimezone) clears it with null; maintenanceDays and metadata keep their last value when removed. Known API gap: the live API ignores heartbeatGroupId: null, so removing heartbeatGroupId does not take the heartbeat out of its group (move it to another group instead, or delete the group). The ping url is a secret and comes back Redacted in the attributes.

metadata here and a separate Metadata resource on the same heartbeat write the same keys: manage a key in one place only.

A nightly backup that must report once a day

const backup = yield* BetterStack.Incidents.Heartbeat("backup", {
name: "Nightly database backup",
period: 86400,
grace: 7200,
email: true,
push: true,
});
// Give the job `backup.url` (Redacted) to request when it finishes.

A queue worker in a HeartbeatGroup, paged through an EscalationPolicy

const workers = yield* BetterStack.Incidents.HeartbeatGroup("workers", { name: "Workers" });
const policy = yield* BetterStack.Incidents.EscalationPolicy("workers-on-call", {
name: "Workers on-call",
steps: [
{ type: "escalation", waitBefore: 0, stepMembers: [{ type: "current_on_call" }] },
],
});
yield* BetterStack.Incidents.Heartbeat("queue-worker", {
name: "Queue worker",
period: 300,
grace: 300,
heartbeatGroupId: workers.id,
escalationPolicyId: policy.id,
maintenanceDays: ["sat", "sun"],
maintenanceFrom: "00:00:00",
maintenanceTo: "06:00:00",
maintenanceTimezone: "London",
});

Reference a heartbeat by id

const existing = BetterStack.Incidents.Heartbeat.lookup({ id: "123456" });

Reference a heartbeat by name (fails with AmbiguousLookup when several share it)

const nightly = BetterStack.Incidents.Heartbeat.lookup({ name: "nightly-backup" });

grace number required

How late a request can arrive after period, in seconds, before it counts as missed. At least 0 and less than a year.

period number required

How often the heartbeat expects a request, in seconds. At least 30 and less than a year.

call boolean

Whether to call the on-call person. Ignored while an escalation policy is set.

criticalAlert boolean

Whether to send a critical push notification that ignores the mute switch and Do Not Disturb mode. Ignored while an escalation policy is set.

email boolean

Whether to send an e-mail to the on-call person. Ignored while an escalation policy is set.

escalationPolicyId string | null

ID of the escalation policy for alerts, or null to alert the current on-call person directly. Get the ID via List escalation policies.

heartbeatGroupId string | null

ID of the heartbeat group this heartbeat belongs to.

maintenanceDays string[]

Days of the week the maintenance window applies to, any of mon, tue, wed, thu, fri, sat and sun. An overnight window counts for the day it starts. Order doesn't matter.

maintenanceFrom string | null

Start time of the daily maintenance window, like 01:00. We don't check the heartbeat during the window. Returned as HH:MM:SS, or null when no window is set.

maintenanceTimezone string | null

Time zone of the maintenance window, as a short name like Amsterdam or an IANA name like Europe/Amsterdam. Returned as the short name. null means UTC.

maintenanceTo string | null

End time of the daily maintenance window, like 03:00. Required with maintenance_from. A window that ends before it starts runs overnight. Returned as HH:MM:SS, or null when no window is set.

metadata CreateHeartbeatRequestMetadataMap

Custom metadata. Each key holds a list of values. A value is a string, written as {type: "String", value}, or a catalog reference, written as {type, item_id, name, email}. User references are returned as u123 and team references as t123. Get a user's ID via List team members, and a team's ID via List teams. Values under one key must all be the same type and can't repeat. An update replaces all of the heartbeat's metadata with the object. {} removes it all. Leave metadata out to keep it.

name string

Heartbeat name. Defaults to a unique name generated from the stack, stage and logical id.

paused boolean

Whether the heartbeat is paused. A paused heartbeat doesn't notify you about downtime. Send false to resume it.

push boolean

Whether to send a push notification to the on-call person. Ignored while an escalation policy is set.

serverTimezone string | null

The time zone your job runs in, as an IANA name like Europe/Berlin. Set it so a job scheduled by local time isn't counted as late when the clocks change for daylight saving. Only accepted for a period of at least 3600 seconds, which is 1 hour. Send null or an empty string to clear it.

sms boolean

Whether to send an SMS to the on-call person. Ignored while an escalation policy is set.

sortIndex number | null

A sort value you can set through the API. The dashboard doesn't use it to order heartbeats.

teamId string

Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.

teamWait number | null

Seconds to wait before escalating to the whole team. 0 alerts the whole team right away, and null never escalates to the team. Ignored while an escalation policy is set.

id string always set

The heartbeat's id.

call boolean

Whether to call the on-call person. Ignored while an escalation policy is set.

createdAt string

When the heartbeat was created.

criticalAlert boolean

Whether to send a critical push notification that ignores the mute switch and Do Not Disturb mode. Ignored while an escalation policy is set.

email boolean

Whether to send an e-mail to the on-call person. Ignored while an escalation policy is set.

escalationPolicyId string | null

ID of the escalation policy for alerts, or null to alert the current on-call person directly. Get the ID via List escalation policies.

grace number

How late a request can arrive after period, in seconds, before it counts as missed. At least 0 and less than a year.

heartbeatGroupId string | null

ID of the heartbeat group this heartbeat belongs to.

maintenanceDays string[]

Days of the week the maintenance window applies to, any of mon, tue, wed, thu, fri, sat and sun. An overnight window counts for the day it starts. Order doesn't matter.

maintenanceFrom string | null

Start time of the daily maintenance window, like 01:00. We don't check the heartbeat during the window. Returned as HH:MM:SS, or null when no window is set.

maintenanceTimezone string | null

Time zone of the maintenance window, as a short name like Amsterdam or an IANA name like Europe/Amsterdam. Returned as the short name. null means UTC.

maintenanceTo string | null

End time of the daily maintenance window, like 03:00. Required with maintenance_from. A window that ends before it starts runs overnight. Returned as HH:MM:SS, or null when no window is set.

metadata HeartbeatMetadataMap

Custom metadata. Each key holds a list of values. A value is a string, written as {type: "String", value}, or a catalog reference, written as {type, item_id, name, email}. User references are returned as u123 and team references as t123. Get a user's ID via List team members, and a team's ID via List teams. Values under one key must all be the same type and can't repeat.

name string

Heartbeat name.

paused boolean

Whether the heartbeat is paused. A paused heartbeat doesn't notify you about downtime.

pausedAt string | null

When the heartbeat was paused.

period number

How often the heartbeat expects a request, in seconds. At least 30 and less than a year.

push boolean

Whether to send a push notification to the on-call person. Ignored while an escalation policy is set.

serverTimezone string | null

The time zone your job runs in, as an IANA name like Europe/Berlin. Set it so a job scheduled by local time isn't counted as late when the clocks change for daylight saving.

sms boolean

Whether to send an SMS to the on-call person. Ignored while an escalation policy is set.

sortIndex number | null

A sort value you can set through the API. The dashboard doesn't use it to order heartbeats.

status "paused" | "pending" | "maintenance" | "up" | "validating" | "down"

The heartbeat's current status.

teamId string

Team that owns this heartbeat, such as t123.

teamName string

Name of the team that owns this heartbeat.

teamWait number | null

Seconds to wait before escalating to the whole team. 0 alerts the whole team right away, and null never escalates to the team. Ignored while an escalation policy is set.

updatedAt string

When the heartbeat was last updated.

url string | Redacted<string>

The unique URL your service requests to report a heartbeat.

Heartbeat.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.

teamId string

Team that owns it, such as t123. Defaults to the credentials' team.