Send alerts to Microsoft Flow using webhook

I created a webhook for Microsoft Flow in New Relic.

In Microsoft Flow I used Request as a trigger with the following JSON Schema:

{
    "type": "object",
    "properties": {
        "current_state": {
            "type": "string"
        },
        "details": {
            "type": "string"
        },
        "severity": {
            "type": "string"
        },
        "incident_acknowledge_url": {
            "type": "string"
        },
        "incident_api_url": {
            "type": "string"
        },
        "incident_url": {
            "type": "string"
        },
        "owner": {
            "type": "string"
        },
        "policy_url": {
            "type": "string"
        },
        "runbook_url": {
            "type": "string"
        },
        "policy_name": {
            "type": "string"
        },
        "condition_id": {
            "type": "number"
        },
        "condition_name": {
            "type": "string"
        },
        "event_type": {
            "type": "string"
        },
        "incident_id": {
            "type": "number"
        },
        "targets": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "name": {
                        "type": "string"
                    },
                    "link": {
                        "type": "string"
                    },
                    "labels": {
                        "type": "object",
                        "properties": {
                            "Service": {
                                "type": "string"
                            },
                            "Product": {
                                "type": "string"
                            },
                            "Team": {
                                "type": "string"
                            }
                        }
                    },
                    "type": {
                        "type": "string"
                    }
                },
                "required": [
                    "id",
                    "name",
                    "link",
                    "labels",
                    "type"
                ]
            }
        },
        "timestamp": {
            "type": "number"
        },
        "version": {
            "type": "number"
        }
    }
}

That then posts to Microsoft Teams.

Using Postman I can post the following example to Microsoft Flow and it successfully posts to Microsoft Teams. The example is a corrected version of the example in the documentation, as the documented example is formatted incorrectly. Please correct the example in the documentation.

{
	"current_state": "open",
	"details": "Apdex < .80 for at least 10 min",
	"severity": "WARN",
	"incident_api_url": "https://alerts.newrelic.com/api/explore/applications/incidents/1234",
	"incident_url": "https://alerts.newrelic.com/accounts/99999999999/incidents/1234",
	"owner": "user name",
	"policy_url": "https://alerts.newrelic.com/accounts/99999999999/policies/456",
	"runbook_url": "https://localhost/runbook",
	"policy_name": "APM Apdex policy",
	"condition_id": 987654,
	"condition_name": "My APM Apdex condition name",
	"event_type": "INCIDENT",
	"incident_id": 1234,
	"targets": [{
		"id": "23456",
		"name": "My Application",
		"link": "https://alerts.newrelic.com/accounts/99999999999/applications/23456?tw[start]=1425415729&tw[end]=1425417529",
		"labels": {
			"Service": "Account Service",
			"Product": "APM",
			"Team": "APM Team"
		},
		"type": "APM:Application"
	}],
	"timestamp": 1425417514074
}

Using New Relic Alert’s Send a test notification, I get the following error

{
response:200,
Unable to invoke Webhook. Webhook responded with HTTP status code 401.
}

How is New Relic sending the data?

3 Likes

The 401 you’re getting is probably a problem with the authentication you have configured. It would probably be the most helpful to post a link to the channel you’re working on so that we can have a look.

What incorrect formatting did you see in the documentation’s example? I know that there are a couple of notes in there that wouldn’t validate, and it looks like we could correct a couple commas. Was there anything else that you felt was invalid JSON?

3 Likes

@parrott Sorry with this colour scheme it isn’t obvious, but I did have a link in the first line of my previous post: https://alerts.newrelic.com/accounts/313703/channels/442112

Yes a HTTP 401 generally means that there was an authentication issue, although using Postman I didn’t specify any authentication. I only just had the exact example above posted to the URL provided by Microsoft Flow with header Content-Type set to application/json and it works successfully.

I recall that there were a few commas missing, but I think that the example above is an exact copy with the corrections so if you diff that then you should see what I change.

@parrott I found the problem. The URL I provide contains parameters which are already URL encoded, but they is being URL encoded again by New Relic. Once I change the URL to be decoded then the webhook works.

Would it be possible to rather prevent illegal characters that shouldn’t be in a URL, e.g. whitespace, and not encode the URL?

@Trevor_Dearham We are doing the same, post alerts to Teams. However based on my testing and NR supports, any variables inside brackets ([]) will not work in custom JSON payload. So any variables can’t be inside arrays. What’s working for you? could you please post a complete working example? Thanks.

1 Like

@Henry.Cheng Sorry I’m unable to do this at the moment, but check the run history in Flow to see the output to Teams. The post to Teams is HTML, so you might need to process it in your flow, e.g. using an Expression containing Conversion Functions to convert JSON to XML and then extract the data and output in HTML.

Thanks @Trevor_Dearham and @Henry.Cheng - We really appreciate that you two are working this out together and that we all get to learn from you!

@Trevor_Dearham Thanks for the response.