繁体   English   中英

使用 Terraform 在 Azure 上为 ServiceBus 创建 azurerm_monitor_metric_alert 时出错

[英]Error creating azurerm_monitor_metric_alert for ServiceBus on Azure with Terraform

我无法创建azurerm_monitor_metric_alert 我需要它来监视服务总线的死信消息。 我在 Linux 和 azurerm v2.88.1 上使用 Terraform 1.0.11。

我得到的错误是:

azurerm_monitor_metric_alert.sb_dlq_example: Creating...

Error: creating or updating Monitor Metric Alert: (Name "DLQ Alert owashoh" / Resource Group "SharedienDevelopment"): insights.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ResourceNotFound" Message="{\"code\":\"BadRequest\",\"message\":\"Detect invalid value: Microsoft.ServiceBus/namespaces for query parameter: 'metricnamespace', the value must be: Microsoft.ServiceBus/namespaces/queues if the query parameter is provided, you can also skip this optional query parameter.\"} Activity ID: 1cc2c166-ffaf-4fbc-bd07-bc49b04e9f1e."

  with azurerm_monitor_metric_alert.sb_dlq_example,
  on service_bus.tf line 118, in resource "azurerm_monitor_metric_alert" "sb_dlq_example":
 118: resource "azurerm_monitor_metric_alert" "sb_dlq_example" {

检测无效值:Microsoft.ServiceBus/namespaces 查询参数:'metricnamespace',值必须是:Microsoft.ServiceBus/namespaces/queues

data "azurerm_resource_group" "this" {
  name = "Example"
}

resource "azurerm_monitor_action_group" "example" {
  name                = "Error Alerts Action owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  short_name          = "p4action"

  email_receiver {
    name                    = "sendtodevops"
    email_address           = "devops@contoso.com"
    use_common_alert_schema = true
  }
}

resource "azurerm_servicebus_namespace" "example" {
  name                = "tfex-servicebus-namespace-owashoh"
  location            = data.azurerm_resource_group.this.location
  resource_group_name = data.azurerm_resource_group.this.name
  sku                 = "Standard"
}

resource "azurerm_servicebus_queue" "example" {
  name                = "tfex_servicebus_queue_owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  namespace_name      = azurerm_servicebus_namespace.example.name
  enable_partitioning = true
}

resource "azurerm_monitor_metric_alert" "sb_dlq_example" {

  scopes = [ azurerm_servicebus_queue.example.id ]

  name                = "DLQ Alert owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  description         = "DLQ Alert."
  severity            = 4

  criteria {
    metric_namespace = "Microsoft.ServiceBus/namespaces" #### <====

    metric_name = "DeadletteredMessages"
    aggregation = "Average"
    operator    = "GreaterThanOrEqual"
    threshold   = 5
  }

  action {
    action_group_id    = azurerm_monitor_action_group.example.id
  }
}

错误在标记的行中: metric_namespace = "Microsoft.ServiceBus/namespaces"

我用metric_namespace = "Microsoft.ServiceBus/namespaces/queues"替换了它,但它仍然失败。 错误:

Error: creating or updating Monitor Metric Alert: (Name "DLQ Alert owashoh" / Resource Group "SharedienDevelopment"): insights.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ResourceNotFound" Message="{\"code\":\"BadRequest\",\"message\":\"Microsoft.ServiceBus/namespaces/queues is not a supported platform metric namespace, supported ones are Microsoft.AnalysisServices/servers,Microsoft.Web/staticSites,Microsoft.Web/serverFarms,Microsoft.Web/sites,Microsoft.Web/sites/slots,Microsoft.Web/hostingEnvironments,Microsoft.Web/hostingEnvironments/multiRolePools,Microsoft.Web/hostingEnvironments/workerPools,Microsoft.Web/connections,Microsoft.IoTCentral/IoTApps,Microsoft.ServiceBus/namespaces,Microsoft.HealthcareApis/services,Microsoft.HealthcareApis/workspaces/iotconnectors,Microsoft.Network/virtualNetworks,Microsoft.Network/natGateways,Microsoft.Network/publicIPAddresses,Microsoft.Network/networkInterfaces,Microsoft.Network/privateEndpoints,Microsoft.Network/loadBalancers,Microsoft.Network/networkWatchers/connectionMonitors,Microsoft.Network/virtualNetworkGateways,Microsoft.Network/connections,Microsoft.Network/applicationGateways,Microsoft.Network/dnszones,Microsoft.Network/privateDnsZones,Microsoft.Network/trafficmanagerprofiles,Microsoft.Network/expressRouteCircuits,Microsoft.Network/vpnGateways,Microsoft.Network/p2sVpnGateways,Microsoft.Network/expressRouteGateways,Microsoft.Network/expressRoutePorts,Microsoft.Network/azureFirewalls,Microsoft.Network/privateLinkServices,Microsoft.Network/frontdoors,Microsoft.Network/virtualRouters,Microsoft.DBforMySQL/servers,Microsoft.DBforMySQL/flexibleServers,microsoft.insights/components,microsoft.insights/autoscalesettings,Microsoft.Sql/servers,Microsoft.Sql/servers/databases,Microsoft.Sql/servers/elasticpools,Microsoft.Sql/managedInstances,Microsoft.KeyVault/vaults,Microsoft.Cache/Redis,Microsoft.Cache/redisEnterprise,Microsoft.ContainerRegistry/registries,Microsoft.DocumentDB/databaseAccounts,Microsoft.VMwareCloudSimple/virtualMachines,Microsoft.ContainerInstance/containerGroups,Microsoft.Devices/IotHubs,Microsoft.Devices/ElasticPools,Microsoft.Devices/ElasticPools/IotHubTenants,Microsoft.Devices/ProvisioningServices,Microsoft.Compute/virtualMachines,Microsoft.Compute/virtualMachineScaleSets,Microsoft.Compute/virtualMachineScaleSets/virtualMachines,Microsoft.Compute/cloudServices,Microsoft.Compute/cloudServices/roles,Microsoft.Synapse/workspaces,Microsoft.Synapse/workspaces/bigDataPools,Microsoft.Synapse/workspaces/sqlPools,Microsoft.Synapse/workspaces/kustoPools,Microsoft.ClassicCompute/domainNames/slots/roles,Microsoft.ClassicCompute/virtualMachines,Microsoft.SignalRService/SignalR,Microsoft.SignalRService/WebPubSub,Microsoft.DataBoxEdge/DataBoxEdgeDevices,Microsoft.StorageCache/caches,Microsoft.Search/searchServices,Microsoft.Logic/workflows,Microsoft.Logic/integrationServiceEnvironments,Microsoft.HDInsight/clusters,Microsoft.MachineLearningServices/workspaces,Microsoft.DataCollaboration/workspaces,Microsoft.Purview/accounts,Microsoft.Relay/namespaces,Microsoft.DigitalTwins/digitalTwinsInstances,Microsoft.EventHub/namespaces,Microsoft.EventHub/clusters,Microsoft.Kusto/clusters,Microsoft.OperationalInsights/workspaces,Microsoft.Maps/accounts,Microsoft.DBforMariaDB/servers,Microsoft.TimeSeriesInsights/environments,Microsoft.TimeSeriesInsights/environments/eventsources,Microsoft.AppPlatform/Spring,Microsoft.DBforPostgreSQL/servers,Microsoft.DBforPostgreSQL/serversv2,Microsoft.DBforPostgreSQL/singleServers,Microsoft.DBforPostgreSQL/flexibleServers,Microsoft.StreamAnalytics/streamingjobs,Microsoft.Cdn/profiles,Microsoft.Cdn/CdnWebApplicationFirewallPolicies,Microsoft.AVS/privateClouds,Microsoft.NotificationHubs/namespaces/notificationHubs,Microsoft.ApiManagement/service,Microsoft.Storage/storageAccounts,Microsoft.Storage/storageAccounts/blobServices,Microsoft.Storage/storageAccounts/tableServices,Microsoft.Storage/storageAccounts/queueServices,Microsoft.Storage/storageAccounts/fileServices,Microsoft.Media/mediaservices,Microsoft.Media/mediaservices/streamingEndpoints,Microsoft.Media/mediaservices/liveEvents,Microsoft.DataLakeAnalytics/accounts,Microsoft.ServiceFabricMesh/applications,Microsoft.PowerBIDedicated/capacities,Microsoft.ClassicStorage/storageAccounts,Microsoft.ClassicStorage/storageAccounts/blobServices,Microsoft.ClassicStorage/storageAccounts/tableServices,Microsoft.ClassicStorage/storageAccounts/fileServices,Microsoft.ClassicStorage/storageAccounts/queueServices,microsoft.aadiam/azureADMetrics,Microsoft.AppConfiguration/configurationStores,Microsoft.Automation/automationAccounts,Microsoft.DataLakeStore/accounts,Microsoft.DataFactory/dataFactories,Microsoft.DataFactory/factories,Microsoft.NetApp/netAppAccounts/capacityPools,Microsoft.NetApp/netAppAccounts/capacityPools/volumes,Microsoft.DataShare/accounts,Microsoft.Peering/peerings,Microsoft.Peering/peeringServices,Microsoft.StorageSync/storageSyncServices,Microsoft.MixedReality/spatialAnchorsAccounts,Microsoft.MixedReality/remoteRenderingAccounts,Microsoft.ContainerService/managedClusters,Microsoft.Blockchain/blockchainMembers,Microsoft.Batch/batchAccounts,Microsoft.EventGrid/eventSubscriptions,Microsoft.EventGrid/topics,Microsoft.EventGrid/domains,Microsoft.EventGrid/extensionTopics,Microsoft.EventGrid/systemTopics,Microsoft.EventGrid/partnerNamespaces,Microsoft.EventGrid/partnerTopics,Microsoft.CognitiveServices/accounts,Microsoft.Media/videoanalyzers,Microsoft.MachineLearningServices/workspaces/onlineEndpoints,Microsoft.MachineLearningServices/workspaces/onlineEndpoints/deployments,microsoft.keyvault/managedhsms,microsoft.network/vpngateways,microsoft.network/bastionHosts,Microsoft.Network/applicationgateways,microsoft.network/virtualnetworkgateways,Microsoft.Network/virtualHubs,microsoft.network/p2svpngateways,Microsoft.Cloudtest/pools,Microsoft.Cloudtest/hostedpools,microsoft.avs/privateClouds,microsoft.compute/disks,Microsoft.Compute/virtualmachineScaleSets,Microsoft.Logic/IntegrationServiceEnvironments,Microsoft.Logic/Workflows,Microsoft.Cdn/cdnwebapplicationfirewallpolicies,Microsoft.DocumentDB/cassandraClusters,Microsoft.DocumentDB/DatabaseAccounts,Wandisco.Fusion/migrators/liveDataMigrations,Wandisco.Fusion/migrators/metadataMigrations,Wandisco.Fusion/migrators,Microsoft.ConnectedVehicle/platformAccounts,Microsoft.Communication/CommunicationServices,microsoft.hybridnetwork/networkfunctions,microsoft.purview/accounts,Microsoft.Cache/redis,microsoft.kubernetes/connectedClusters,Microsoft.DBForPostgreSQL/serverGroupsv2,Microsoft.RecoveryServices/Vaults. TraceId: {996569c7-cdfe-429c-ba2f-86bba2b1cfb1}\"} Activity ID: 5694bf32-c589-4587-8cb1-1b80f7a571ea."

  with azurerm_monitor_metric_alert.sb_dlq_example,
  on service_bus.tf line 118, in resource "azurerm_monitor_metric_alert" "sb_dlq_example":
 118: resource "azurerm_monitor_metric_alert" "sb_dlq_example" {

⸘嗯……‽你如何创建这样的警报?

除了Metric Alert资源块中的scope参数之外,您的代码似乎很好。 您应该使用scopes =[azurerm_servicebus_namespace.example.id]而不是scopes = [azurerm_servicebus_queue.example.id ] ,因为deadletteredmessages可用于命名空间,它将监控命名空间内存在的队列/主题的死信消息的平均数量,也可以作为Metric_NamespaceMicrosoft.ServiceBus/namespaces scope 应该是命名空间的 ID。

我通过进行上述更改使用您的代码对其进行了测试:

provider "azurerm"{
    features{}
}
data "azurerm_resource_group" "this" {
  name = "myrg"
}

resource "azurerm_monitor_action_group" "example" {
  name                = "Error Alerts Action owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  short_name          = "p4action"

  email_receiver {
    name                    = "sendtodevops"
    email_address           = "myemailid"
    use_common_alert_schema = true
  }
}

resource "azurerm_servicebus_namespace" "example" {
  name                = "ansuman-servicebus-namespace-owashoh"
  location            = data.azurerm_resource_group.this.location
  resource_group_name = data.azurerm_resource_group.this.name
  sku                 = "Standard"
}

resource "azurerm_servicebus_queue" "example" {
  name                = "ansuman_servicebus_queue_owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  namespace_name      = azurerm_servicebus_namespace.example.name
  enable_partitioning = true
}

resource "azurerm_monitor_metric_alert" "sb_dlq_example" {
  name                = "DLQ Alert owashoh"
  resource_group_name = data.azurerm_resource_group.this.name
  scopes = [ azurerm_servicebus_namespace.example.id] ##changed to namespace resourceid instead of queue resourceid.
  description         = "DLQ Alert."
  severity            = 4

  criteria {
    metric_namespace = "Microsoft.ServiceBus/namespaces"

    metric_name = "DeadletteredMessages"
    aggregation = "Average"
    operator    = "GreaterThanOrEqual"
    threshold   = 5
  }

  action {
    action_group_id    = azurerm_monitor_action_group.example.id
  }
}

Output:

在此处输入图像描述

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM