Reputation: 3
It's been a pain when tracking alerts when coming across multi regions and environments. Not only wasting time to find the right resources on the Azure portal but sometime took a while to filter/load all the resources on the portal. Is there a way to embed the resources/objects URL into the metric alert's description so one can just click it on the e.g. Opsgenie and lead to the problematic resources on the Azure portal?
Example:
Take this alert message for instance:
Name: [P2]-[NA]-[prod_v1_SDL_api-async_azure_australiaeast_Commercial]-[sdl-au-prod-async-cosmosdb Cosmosdb Availability is LessThan Threshold]
Description: The availability of Async cosmosdb is less than 100%.
I want to have a link inside the Description that can lead me to the right cosmosDB on the Azure portal.
I'm looking to make the resources/objects URL into a variable then use it inside Terraform monitor_metric_alert or something similar to that. But I didn't see anything similar to what I'm looking for on Terraform monitor_metric_alert.
Upvotes: 0
Views: 486
Reputation: 10831
I tried to reproduce the same in my environment.
I think what you are looking for is Data collection endpoints
and rules in Azure Monitor.
Note: You can define a data collection rule to send data from multiple machines to multiple Log Analytics workspaces, including workspaces in a different region or tenant. Create the data collection rule in the same region as your Log Analytics workspace.
See the steps here
Code:
resource "azurerm_monitor_data_collection_endpoint" "example" {
name = "example-mdce"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
kind = "Windows"
public_network_access_enabled = true
description = "monitor_data_collection_endpoint example"
tags = {
foo = "bar"
}
}
snippet from azurerm_monitor_data_collection_rule | Resources | hashicorp/azurerm | Terraform Registry
Code:
resource "azurerm_storage_account" "to_monitor" {
name = "kavyaexamplestorageaccount"
resource_group_name = data.azurerm_resource_group.example.name
location = data.azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
#Create Log Analytics workspace with contributor rights:
resource "azurerm_log_analytics_workspace" "example" {
name = "example-workspace"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
}
resource "azurerm_log_analytics_solution" "example" {
solution_name = "WindowsEventForwarding"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
workspace_resource_id = azurerm_log_analytics_workspace.example.id
workspace_name = azurerm_log_analytics_workspace.example.name
plan {
publisher = "Microsoft"
product = "OMSGallery/WindowsEventForwarding"
}
}
resource "azurerm_monitor_data_collection_rule" "example" {
name = "kavyaexample-rule"
resource_group_name = data.azurerm_resource_group.example.name
location = data.azurerm_resource_group.example.location
destinations {
log_analytics {
workspace_resource_id = azurerm_log_analytics_workspace.example.id
name = "test-destination-log"
}
azure_monitor_metrics {
name = "test-destination-metrics"
}
}
data_flow {
streams = ["Microsoft-InsightsMetrics"]
destinations = ["test-destination-metrics"]
}
data_flow {
streams = ["Microsoft-InsightsMetrics", "Microsoft-Syslog", "Microsoft-Perf"]
destinations = ["test-destination-log"]
}
data_sources {
syslog {
facility_names = ["*"]
log_levels = ["*"]
name = "test-datasource-syslog"
}
performance_counter {
streams = ["Microsoft-Perf", "Microsoft-InsightsMetrics"]
sampling_frequency_in_seconds = 10
counter_specifiers = ["Processor(*)\\% Processor Time"]
name = "test-datasource-perfcounter"
}
windows_event_log {
streams = ["Microsoft-WindowsEvent"]
x_path_queries = ["*[System/Level=1]"]
name = "test-datasource-wineventlog"
}
extension {
streams = ["Microsoft-WindowsEvent"]
input_data_sources = ["test-datasource-wineventlog"]
extension_name = "test-extension-name"
extension_json = jsonencode({
a = 1
b = "hello"
})
name = "test-datasource-extension"
}
}
description = "data collection rule example"
tags = {
foo = "bar"
}
depends_on = [
azurerm_log_analytics_solution.example
]
}
It worked in azurerm version 3.40.0
azurerm = {
source = "hashicorp/azurerm"
version = "=3.40.0"
}
Terraform apply
ran successfully
Portal view.
Upvotes: 0