Skip to content
betterstack-alchemyUnofficial

Incidents.GrafanaIntegration

Kind ResourceType id BetterStack.Incidents.GrafanaIntegrationSource src/Incidents/GrafanaIntegration.tsLive test gated Lifecycle test runs against the offline mock; a live run exists but is gated behind BETTERSTACK_TEST_PAID_INTEGRATIONS=1 because the test account's plan refuses this integration (test/Incidents/GrafanaIntegration.test.ts).

A Grafana integration turns alerts from Grafana into Better Stack incidents. Better Stack gives you a webhookUrl (a secret, Redacted): in Grafana, create a contact point of type Webhook with that URL and route your alert rules’ notification policy to it. Firing alerts open an incident, resolved alerts resolve it.

Every prop updates in place except teamId, which replaces the integration (and gives it a new webhookUrl). name defaults to a generated unique name. Removing escalationPolicyId or teamWait clears them. Without an escalation policy, call/sms/email/push/ criticalAlert decide how the current on-call person is alerted.

Alert through an escalation policy

const grafana = yield* BetterStack.Incidents.GrafanaIntegration("grafana", {
name: "Grafana alerts",
escalationPolicyId: policyId,
});

The URL is a secret: export it from the stack (return { grafanaWebhookUrl: grafana.webhookUrl }) or hand it to whatever provisions Grafana.

A Grafana contact point provisioning file from the deployed URL

const contactPoint = (url: string) => ({
apiVersion: 1,
contactPoints: [
{
orgId: 1,
name: "Better Stack",
receivers: [{ uid: "better-stack", type: "webhook", settings: { url, httpMethod: "POST" } }],
},
],
});
const provisioning = contactPoint(Redacted.value(webhookUrl));

Stop opening incidents during maintenance

yield* BetterStack.Incidents.GrafanaIntegration("grafana", { name: "Grafana alerts", paused: true });

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.

name string

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

paused boolean

Whether the integration is paused. A paused integration opens no incidents.

push boolean

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

recoveryPeriod number | null

Seconds a resolved alert must hold before the incident resolves. Has no effect for this integration, since an incident resolves as soon as Grafana reports the alert as resolved.

sms boolean

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

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 incidents_grafana_integration's id.

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.

name string | null

Integration name.

paused boolean

Whether the integration is paused. A paused integration opens no incidents.

push boolean

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

recoveryPeriod number | null

Seconds a resolved alert must hold before the incident resolves. Has no effect for this integration, since an incident resolves as soon as Grafana reports the alert as resolved.

sms boolean

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

teamId string

Team that owns this integration, such as t123.

teamName string

Name of the team that owns this integration.

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.

webhookUrl string | Redacted<string>

The URL to paste into Grafana. Alerts Grafana sends to it open incidents.

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

id string required

The integration's id.

teamId string

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