aspnet / WebHooks

[Archived] Libraries to create and consume web hooks on ASP.NET Core. Project moved to https://github.com/aspnet/AspLabs
Apache License 2.0
627 stars 439 forks source link

AzureAlertContext is invalid for application insights alerts #146

Closed michelejohlbs closed 6 years ago

michelejohlbs commented 7 years ago

I created the receiver and used the AzureAlertNotification in order to serialize the context as per the example code. var notification = context.GetDataOrDefault<AzureAlertNotification>();

The issue is that the notification POCO is null.

I created my own serialization class, but removed most of the “Required = Required.Always” on the JsonProperty attributes, except for Id, Name and Description. Using my own class it now works.

This means that the application insights notifications are not compliant with the Microsoft.AspNet.WebHooks.Receivers.Azure library, or that the library is not compliant with the application insights alerts.

dougbu commented 6 years ago

Double-check samples against a live Application Insights rule.

dougbu commented 6 years ago

@michelejohlbs I'm unable to recreate your issue but am probably not testing the class of alert you are. Could you please describe your scenario in more detail? For example, are you seeing problems with metric alerts (what I tested), alerts on activity log events, or a subset of one or the other?

FYI the documentation at https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/insights-webhooks-alerts shows pretty much every field is mandatory.

michelejohlbs commented 6 years ago

@dougbu I got the issue when receiving an alert from an Application Insight Web Test Failure via the web hook.

dougbu commented 6 years ago

Ah, yes. I do see this issue with Web Test alerts. The ASP.NET Core WebHooks workaround is to bind to JObject instead of AzureAlertNotification. For WebHooks 1.1, call context.GetDataOrDefault<JObject>() instead of context.GetDataOrDefault<AzureAlertNotification>(). Testing a quick fix locally…

dougbu commented 6 years ago

Filed #203 about a related issue. We'll track supporting Availability alerts i.e. the AzureAlertContext restrictiveness here.

michelejohlbs commented 6 years ago

Glad you found it @dougbu

dougbu commented 6 years ago

4681759e4c