There are two main uses for webhooks: pushing data into metricly (inbound) and pulling data like notifications out (outbound).

  • Inbound: Achieved via POST URL that can be found on the Webhook integration card.
  • Outbound: Used by several of our notification integrations and accessible through the Webhook GET API endpoint.

For a great example of an inbound webhook usecase, see how we pushed CloudWatch Logs into Metricly.

When using the outbound method, you can customize the JSON payload using the freemarker markup language from Account > Notifications > Webhook.

Configuration


Add a Webhook Notification
  1. In Metricly, navigate to the Policy Editor.
  2. Click tab 3, Notifications.
  3. Click Add Notification and select Webhook as the Notification Type.
  4. Provide a name for the webhook notification.
  5. Choose your re-notification frequency.
  6. Click New Webhook.
  7. Name the Webhook.
  8. For URL, copy and paste the webhook’s payload URL that should receive notifications.
  9. Click Test to test the webhook. The endpoint URL must return an HTTP code 200 to pass the validation.
  10. Click Save.

Optional Configuration


Headers

Add one or more headers (key-value pairs) to the webhook notification.


Custom Payloads

Select Custom from the Payload drop-down menu. A text field will open after selecting Custom. Create a custom JSON payload in the textbox. You can use the following variables to make your notification more dynamic. To test your template, go here or visit the GitHub page.

PagerDuty Example

{
  "service_key": "<your service key here from pager duty>",
  "incident_key": "${policyName} ",
  "event_type": "trigger",
  "description": "${category}: ${elementFqn} : ${policyName}",
  "client": "Metricly Cloud Service",
  "client_url": "https://app.Metricly.com",
  "details": {
    "category": "${category}",
    "elementFqn":"${elementFqn}",
    "elementType": "${elementType}"
  },
  "contexts": [{
    "type": "link",
    "href": "https://app.Metricly.com/#/element/${elementId}/events"
  }]
}

Microsoft Teams Example

{
    "@context": "http://schema.org/extensions",
    "@type": "MessageCard",
    "summary": "**Metricly Policy Violation <#if payloadType == "event_cleared">CLEARED<#else>${eventCategory.name}</#if>:**",
    "themeColor": "${color}",
    "title": "<#if payloadType == "event_cleared">CLEARED<#else>${eventCategory.name}</#if> Metricly Event:",
    "sections": [
        {
            "activityTitle": "**Metricly Policy Violation:**",
            "activitySubtitle": "${timestamp?datetime?string.iso} UTC",
            "activityImage": "https://s3-us-west-2.amazonaws.com/com-netuitive-app-usw2-slack/metricly_teams_icon.png",
            "facts": [
                {
                    "name": "Title:",
                    "value": "${policyName}"
                },
                {
                    "name": "Element:",
                    "value": "${elementName}"
                },
                {
                    "name": "Type:",
                    "value": "${elementType}"
                },
                {
                    "name": "Category:",
                    "value": "${eventCategory.name}"
                },
                {
                    "name": "Description:",
                    "value": "<#if policyDescription?has_content>${policyDescription?json_string}<#else>No description provided</#if>"
                }
            ],
            "text": "**Violation:**  <#if event.data??><#if event.data.results??><#assign results = event.data.results?eval><#if results.conditions??><#list results.conditions as condition><#if condition?counter <= 5>${condition.expression}</#if></#list></#if></#if></#if>",
            "potentialAction": [
                {
                    "@type": "OpenUri",
                    "name": "Browse Metrics",
                    "targets": [
                        {
                            "os": "default",
                            "uri": "${baseUrl}/metrics?event_id=<#if event.id??>${event.id}</#if>&timeRangeDuration=14400&endTime=${timestamp?datetime?string.iso}"
                        }
                    ]
                },
                {
                    "@type": "OpenUri",
                    "name": "Edit Policy",
                    "targets": [
                        {
                            "os": "default",
                            "uri": "${baseUrl}/policies/${policyId}"
                        }
                    ]
                }

            ]
        }
        <#if images?has_content && (images?size == 1)>
        , {
            "text": "![${images[0].elementFqn} - ${images[0].metricFqn} Metric Graph](${images[0].url})"
        }
         </#if>         
        <#if images?has_content && (images?size > 1)>
          <#list images as image>
        , {
            "text": "![${image.elementFqn} - ${image.metricFqn} Metric Graph](${image.url})"
        }
          </#list>
      </#if>
    ]
}
Slack Example
{
   <#if iconEmoji??>
      "icon_emoji":"${iconEmoji}",
   <#else>
      <#if iconUrl??>
         "icon_url":"${iconUrl}",
      <#else>
         "icon_url":"url.png",
      </#if>
   </#if>
   <#if username??>
      "username": "${username}",
   <#else>
      "username": "Event",
   </#if>
   <#if channel??>
      "channel":"${channel}",
   </#if>
   "attachments":[
      {
         "fallback":"Netuitive Policy Violation:",
         "pretext":"*Netuitive Policy Violation:*",
         "title_link":"https://www.netuitive.com",
         "color":"${color}",
         "mrkdwn_in":[
            "fields",
            "pretext"
         ],
         "fields":[
            {
               "title":"${policyName}",
               "value":"*Element*: ${elementName} \n *Type:* ${elementType}\n *Category:* ${eventCategory.name}",
               "short":true
            },
            {
               "title":"Click here to modify the Policy:",
               "value":"<${baseUrl}/policies/${policyId}|${policyName}>  \n *Click here to browse the Metrics:* \n <${baseUrl}/metrics?event_id=<#if event.id??>${event.id}</#if>&timeRangeDuration=14400&endTime=${timestamp?datetime?string.iso}|Metric Details>",
               "short":true
            },
            {
               "title":" ",
               "value":"\n *Violation:*  <#if event.data??><#if event.data.results??><#assign results = event.data.results?eval><#if results.conditions??><#list results.conditions as condition><#if condition?counter <= 5>${condition.expression}</#if></#list></#if></#if></#if>",
               "short":false
            },
            {
              "title": " ",
              "value":"\n *Description:*   ${policyDescription!"No description provided"}",
              "short":false
            }
         ],
         "footer": "Netuitive Event Message",
         "footer_icon": "url.png",
         "ts": ${timestampSeconds?c} 
      }
   ]
}

 

More About Notifications

For more information about notifications, see them main Notifications page.

capterra

Join other DevOps who love Metricly!

Sign up for a free, fully featured, 21-day trial. No credit card required!