Reputation: 55
I'm trying to define an alert rule for an Azure Smart Alert, where the trigger should be an action group with a webhook using the Common Alert Schema. I need to include some custom properties to the webhook as well.
I'm currently defining the alert rule using terraform, and the definition looks something like this:
resource "azurerm_monitor_smart_detector_alert_rule" "MemoryLeakDetector" {
enabled = true
name = "MemoryLeakDetector"
resource_group_name = var.resource_group_name
severity = "Sev3"
scope_resource_ids = [var.scope_resource_id]
frequency = "P1D"
detector_type = "MemoryLeakDetector"
action_group {
ids = [var.oncall_action_group_id]
webhook_payload = jsonencode({
CustomProperty1 = "FooBar"
})
}
}
For the custom payload that ends up in the JSON definition of the rule under properties.actionGroups.customWebhookPayload
which is different from when I define regular metric/log search rules. Those also have the action group part of terraform looking slightly different, like this instead:
action {
action_group_id = var.oncall_action_group_id
webhook_properties = {
CustomProperty1 = "FooBar"
}
}
And then it instead ends up in the JSON definition in properties.actions.customProperties
.
For the regular metric/log search rules, when they are triggered the custom payload comes through and is present as described by the common alert schema. However, for the Smart Alert rules, the custom payload isn't present in the body of the call to the webhook at all.
All rules use the same action group with the same webhook, and all of them use the common alert schema.
Is there something wrong with my assumptions here, and how can I get the custom payload onto the body of the call when using smart alert rules?
Upvotes: 0
Views: 126
Reputation: 8018
After exploring on it, I found it is not exactly possible to add the custom payloads for smart alert detector rules in Azure Monitor with common alert schema by default implementation.
As detailed in this MSDoc,
Custom properties are currently only supported by metric alerts according to the recent implementation updates.
It means that the webhook properties are sent in the alert payload under properties.actions.customProperties
for metric and log alerts as you mentioned, which enables custom properties to be directly transferred to the specific webhook you used.
I would suggest you go with the metric or log alerts if you want to achieve the custom properties payload with common alert schema.
Or if you still want to use the smart detection alert rules,
you can use the Logic App
action to adapt the Azure Monitor alert JSON to their format and trigger the alert rather than using a webhook.
Alternatively, you can also follow another scenario. Create a monitor action group with azurerm_monitor_action_group
provider by passing the custom payload properties to the webhook according to the requirement.
Now take that webhook endpoint and pass it in the endpoint URL in the Portal as shown below after selection create Smart Detector alert rule (smartDetectorAlertRules)
signal in the below way.
Note: But the above approach may not work if you have larger amount of payload in the custom properties. Verify it twice and go with this approach. Otherwise, you can use metric or log alerts for better results.
Upvotes: 0