1. Creating custom Grafana webhook notifications for escalation chains

    TypeScript

    To create custom Grafana webhook notifications for escalation chains using Pulumi, we’ll be utilizing the grafana package which provides support for managing Grafana resources, including setting escalation chains, creating notification policies, and defining contact points for notifications.

    In this use case, I will guide you through creating an escalation chain, defining a notification policy, and setting up a contact point that utilizes a webhook for notifications.

    Here's the general idea:

    1. Escalation Chain (OncallEscalationChain): This resource sets up a sequence of notification steps that are executed when an alert is triggered.

    2. Notification Policy (NotificationPolicy): This configures the conditions under which the escalation chain is triggered.

    3. Contact Point (ContactPoint): This specifies the methods through which notifications are sent out, which in this case will be a webhook.

    4. Webhook (OncallOutgoingWebhook): We design an outgoing webhook that Grafana will hit when an alert triggers the escalation chain.

    Now, let’s see how this might look in a Pulumi program written in TypeScript:

    import * as pulumi from "@pulumi/pulumi"; import * as grafana from "@pulumi/grafana"; // Step 1: Creating the escalation chain const escalationChain = new grafana.OncallEscalationChain("myEscalationChain", { name: "Critical Alerts", // Optional: provide team ID if you want to associate the escalation chain with a specific Grafana team // teamId: "your-team-id", }); // Step 2: Defining a notification policy which utilizes the escalation chain const notificationPolicy = new grafana.NotificationPolicy("myNotificationPolicy", { // Define your policy conditions here policies: [ { // Example condition, adjust `matchers` as necessary for your alerting logic matchers: [ { label: "severity", match: "=", value: "critical", }, ], groupBies: ["severity"], groupWait: "30s", // Adjust the wait period as needed groupInterval: "5m", repeatInterval: "1h", contactPoint: escalationChain.id, // Reference the escalation chain }, ], }); // Step 3: Setting up a contact point using a webhook const contactPoint = new grafana.ContactPoint("myContactPoint", { name: "Webhook Contact Point", // Add additional methods if required, such as email, slack, etc. webhooks: [ { // The actual webhook URL will vary depending on the external service you are using url: "https://external-service.com/webhook", name: "My Webhook", // You can customize further settings as per your requirements }, ], }); // Step 4: Creating the outgoing webhook in Grafana const outgoingWebhook = new grafana.OncallOutgoingWebhook("myOutgoingWebhook", { name: "Grafana to Service", url: contactPoint.webhooks.apply((webhooks) => webhooks[0].url), // Use contact point webhook URL // Optional settings can be defined here }); // Export the Webhook URL for easy access export const webhookUrl = outgoingWebhook.url;

    In the above code:

    • We create an OncallEscalationChain resource to represent the escalation chain.
    • We configure a NotificationPolicy that references our escalation chain and defines when it should be triggered. You should adjust this policy to match your alerting logic.
    • We then create a ContactPoint for a webhook, which is the endpoint that the Grafana will send notifications to.
    • Finally, we define an OncallOutgoingWebhook, which represents the actual outgoing webhook definition in Grafana.

    After running this Pulumi program, you will have configured Grafana to execute an escalation chain that ends with sending a custom webhook notification.

    To run this Pulumi program, save the code in a file called index.ts, install the necessary dependencies, and then run pulumi up to execute it. The Pulumi CLI will take care of translating your TypeScript code into actual cloud resources.

    For detailed documentation on the various properties you can set for these resources, you can refer to the Pulumi documentation for the Grafana provider:

    This is a basic setup. As you become more comfortable with Pulumi and Grafana, you can create more complex automation tailored to your specific monitoring and alerting needs.