How to send Alerts from New Relic One to Microsoft Teams

4 min read

Like many other people, I’ve been working at home throughout 2020 and 2021. Many customers I work with use Microsoft Teams to collaborate, send messages, and do video calls. But did you know that you can also send alerts from New Relic One directly to channels in Microsoft Teams? When issues come up, you can easily alert teams where they are already working and collaborating. This post shows you how to send alerts to Microsoft Teams, and it only takes about five minutes to set up.

Adding an incoming webhook to Microsoft Teams

To send notifications from New Relic One to Microsoft Teams, you need to add an incoming webhook to the channel where you want the notifications to go. To do so, follow these steps, which are also included in the Microsoft Teams’ documentation on creating an incoming webhook.

  1. In Microsoft Teams, navigate to the channel of your choice and select (...) More Options from the top navigation menu.
  2. Choose Connectors from the menu and search for Incoming Webhook.
  3. Select the Configure button, provide a name for the webhook, and, optionally, upload an image avatar like the New Relic logo for your webhook.
  4. Copy and save the webhook URL that Microsoft Teams generates for you. You'll need to add this URL to New Relic One later in this tutorial.

Once you have a webhook URL, you are ready to configure the notification channel in New Relic One.

Setting up a notification channel in New Relic One

Log in to New Relic One and navigate to Alerts & AI > Notification Channels as shown in the next image.

  1. Choose New notification channel from the top right of the page.
  1. Next, select Webhook from the Select a channel type dropdown menu.
  1. Name your channel in Channel name. This name will appear in the New Relic UI. It doesn’t need to match the channel name in Microsoft Teams.
  2. In the Base Url field, paste the webhook URL you copied from Microsoft Teams’ Incoming Webhook screen.
  3. Next, choose Use Custom Payload and choose JSON as the Payload Type.
  1. In the Payload field, copy the JSON below. Microsoft Teams has a bespoke JSON schema for sending interactive cards that will appear in your channel.
   "summary":"$ACCOUNT_NAME New Relic Alert: $CONDITION_NAME in New Relic Alert - $POLICY_NAME",
   "themeColor":"0076D7",
   "@type":"MessageCard",
   "potentialAction":[
      {
         "@type":"openUri",
         "name":"Go To Incident",
         "targets":[
            {
               "os":"default",
               "uri":"$INCIDENT_URL"
            }
         ]
      },
      {
         "@type":"openUri",
         "name":"Go To Policy",
         "targets":[
            {
               "os":"default",
               "uri":"$POLICY_URL"
            }
         ]
      }
   ],
   "@context":"http://schema.org/extensions",
   "sections":[
      {
         "activitySubtitle":"$SEVERITY violation $EVENT_STATE at $TIMESTAMP_UTC_STRING",
         "activityTitle":"New Relic Alert: $POLICY_NAME - $CONDITION_NAME"
      },
      {
         "images":[
            {
               "image":"$VIOLATION_CHART_URL"
            }
         ]
      },
      {
         "markdown":true,
         "facts":[
            {
               "name":"Assigned to",
               "value":"Unassigned"
            },
            {
               "name":"Runbook",
               "value":"$RUNBOOK_URL"
            },
            {
               "name":"Open Violations",
               "value":"$OPEN_VIOLATIONS_COUNT_CRITICAL critical, $OPEN_VIOLATIONS_COUNT_WARNING warning violations"
            },
            {
               "name":"Status",
               "value":"$EVENT_STATE"
            }
         ]
      }
   ]
}

Note that New Relic Webhook notification channels support templating using variables. In this JSON, we use variables in the format $VARIABLE_NAME for the message template in Microsoft Teams.

Assigning channels to policies

The final step is to add alert policies to your new notification channel. To assign policies to a channel, navigate to Alerts & AI > Policies > Notification channels > Add notification channels as described in the previous link. Choose your new channel, select Alert policies, and then add any alert policies that you’d like to receive alerts for in Microsoft Teams.

Now that you have a new way of alerting your teams, you may want to add more alert policies. Happy alerting!