A .NETStandard 2.0
library with types and serializing utils for azureMonitorCommonAlertSchema
Work in progress
No type information seems to be provided by Microsoft for handling alert payloads - no JSON Schema and no type libraries. This library is built on guesswork based on various example payloads. Lots of properties are of type string
in this library, but are probably enum
s in reality. How can we find out?
Also overall design principles seem lacking.
- Sometimes properties are camelCase, sometimes PascalCase.
- Compare ServiceHealthAlertContext with ResourceHealthAlertContext - some properties sound like they should be shared, but the types differ.
GreaterThan
ANDGreater Than
- alsoLessThan
ANDLower Than
..?
- ActivityLogAlertContext - example
- LogAlertsV2AlertContext
- LogAnalyticsAlertContext - example
- ResourceHealthAlertContext - example
- ServiceHealthAlertContext - example
- SmartAlertContext - example
See ActionGroupTests for the payloads generated by Azure ActionGroup tester (also this)
The respective unit tests can be found in ActionGroupTests.cs
Example usage in AzureAlerts2Slack or
var alert = Types.AlertJsonSerializerSettings.DeserializeOrThrow(requestBody);
if (ctx is Types.AlertContexts.LogAnalyticsAlertContext ctxLogAnalytics)
{
Console.Log($"{alert.Data.Essentials.AlertRule} - tables:{string.Join(", ", ctxLogAnalytics.SearchResults.Tables.Select(o => o.Name))}");
}
Repo that uses this library in an Azure Function for posting to Slack: AzureAlerts2Slack
Related 3rd-party repos