创建或更新指标警报定义。
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}?api-version=2024-03-01-preview
URI 参数
| 名称 |
在 |
必需 |
类型 |
说明 |
|
resourceGroupName
|
path |
True
|
string
minLength: 1 maxLength: 90
|
资源组的名称。 此名称不区分大小写。
|
|
ruleName
|
path |
True
|
string
|
规则的名称。
|
|
subscriptionId
|
path |
True
|
string
minLength: 1
|
目标订阅的 ID。
|
|
api-version
|
query |
True
|
string
minLength: 1
|
要用于此操作的 API 版本。
|
请求正文
| 名称 |
必需 |
类型 |
说明 |
|
location
|
True
|
string
|
资源位置
|
|
properties.criteria
|
True
|
MetricAlertCriteria:
|
定义特定的警报条件信息。
|
|
properties.enabled
|
True
|
boolean
|
指示是否启用指标警报的标志。
|
|
properties.evaluationFrequency
|
True
|
string
(duration)
|
以 ISO 8601 持续时间格式表示衡量指标警报的评估频率。
|
|
properties.scopes
|
True
|
string[]
|
此指标警报的范围所针对的资源 ID 列表。 不能根据日志更改指标规则的范围。
|
|
properties.severity
|
True
|
integer
(int32)
|
警报严重性 {0, 1, 2, 3, 4}
|
|
identity
|
|
Identity
|
资源的标识。
|
|
properties.actionProperties
|
|
object
|
操作属性的属性。
|
|
properties.actions
|
|
MetricAlertAction[]
|
警报规则处于活动状态以及解决警报条件时执行的操作数组。
|
|
properties.autoMitigate
|
|
boolean
|
指示是否应自动解决警报的标志。 默认值为 true。
|
|
properties.customProperties
|
|
object
|
警报有效负载的属性。
|
|
properties.description
|
|
string
|
警报电子邮件中将包含的指标警报的说明。
|
|
properties.resolveConfiguration
|
|
ResolveConfiguration
|
如何解决警示的配置。 适用于 PromQLCriteria。
|
|
properties.targetResourceRegion
|
|
string
|
在其上创建/更新警报的目标资源的区域。 如果范围包含订阅、资源组或多个资源,则是必需的。
|
|
properties.targetResourceType
|
|
string
|
在其上创建/更新警报的目标资源的资源类型。 如果范围包含订阅、资源组或多个资源,则是必需的。
|
|
properties.windowSize
|
|
string
(duration)
|
用于根据阈值监视警报活动的时间段(采用 ISO 8601 持续时间格式)。
|
|
tags
|
|
object
|
资源标记
|
响应
安全性
azure_auth
Azure Active Directory OAuth2 流
类型:
oauth2
流向:
implicit
授权 URL:
https://login.microsoftonline.com/common/oauth2/authorize
作用域
| 名称 |
说明 |
|
user_impersonation
|
模拟用户帐户
|
示例
Create or update a dynamic alert rule for Multiple Resources
示例请求
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/MetricAlertOnMultipleResources?api-version=2024-03-01-preview
{
"location": "global",
"tags": {},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1",
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "DynamicThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"operator": "GreaterOrLessThan",
"timeAggregation": "Average",
"dimensions": [],
"alertSensitivity": "Medium",
"failingPeriods": {
"numberOfEvaluationPeriods": 4,
"minFailingPeriodsToAlert": 4
}
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_dynamic_metric_alert_multiple_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="MetricAlertOnMultipleResources",
parameters={
"location": "global",
"properties": {
"actions": [
{
"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {"key11": "value11", "key12": "value12"},
}
],
"autoMitigate": True,
"criteria": {
"allOf": [
{
"alertSensitivity": "Medium",
"criterionType": "DynamicThresholdCriterion",
"dimensions": [],
"failingPeriods": {"minFailingPeriodsToAlert": 4, "numberOfEvaluationPeriods": 4},
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"name": "High_CPU_80",
"operator": "GreaterOrLessThan",
"timeAggregation": "Average",
}
],
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"scopes": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1",
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2",
],
"severity": 3,
"targetResourceRegion": "southcentralus",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"windowSize": "PT15M",
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateDynamicMetricAlertMultipleResource.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateDynamicMetricAlertMultipleResource.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "MetricAlertOnMultipleResources";
MetricAlertData data = new MetricAlertData(
new AzureLocation("global"),
3,
true,
new string[] { "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1", "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2" },
XmlConvert.ToTimeSpan("PT1M"),
new MetricAlertMultipleResourceMultipleMetricCriteria
{
AllOf = {new DynamicMetricCriteria(
"High_CPU_80",
"Percentage CPU",
MetricCriteriaTimeAggregationType.Average,
DynamicThresholdOperator.GreaterOrLessThan,
DynamicThresholdSensitivity.Medium,
new DynamicThresholdFailingPeriods(4, 4))
{
MetricNamespace = "microsoft.compute/virtualmachines",
Dimensions = {},
}},
})
{
Description = "This is the description of the rule1",
MonitorWindowSize = XmlConvert.ToTimeSpan("PT15M"),
TargetResourceType = new ResourceType("Microsoft.Compute/virtualMachines"),
TargetResourceRegion = new AzureLocation("southcentralus"),
IsAutoMitigateEnabled = true,
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
}},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/MetricAlertOnMultipleResources",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1",
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "DynamicThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"operator": "GreaterOrLessThan",
"timeAggregation": "Average",
"dimensions": [],
"alertSensitivity": "Medium",
"failingPeriods": {
"numberOfEvaluationPeriods": 4,
"minFailingPeriodsToAlert": 4
}
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
Create or update a dynamic alert rule for Single Resource
示例请求
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/chiricutin?api-version=2024-03-01-preview
{
"location": "global",
"tags": {},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "DynamicThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"operator": "GreaterOrLessThan",
"timeAggregation": "Average",
"dimensions": [],
"alertSensitivity": "Medium",
"failingPeriods": {
"numberOfEvaluationPeriods": 4,
"minFailingPeriodsToAlert": 4
},
"ignoreDataBefore": "2019-04-04T21:00:00.000Z"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_dynamic_metric_alert_single_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="chiricutin",
parameters={
"location": "global",
"properties": {
"actions": [
{
"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {"key11": "value11", "key12": "value12"},
}
],
"autoMitigate": True,
"criteria": {
"allOf": [
{
"alertSensitivity": "Medium",
"criterionType": "DynamicThresholdCriterion",
"dimensions": [],
"failingPeriods": {"minFailingPeriodsToAlert": 4, "numberOfEvaluationPeriods": 4},
"ignoreDataBefore": "2019-04-04T21:00:00.000Z",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"name": "High_CPU_80",
"operator": "GreaterOrLessThan",
"timeAggregation": "Average",
}
],
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"scopes": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme"
],
"severity": 3,
"windowSize": "PT15M",
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateDynamicMetricAlertSingleResource.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateDynamicMetricAlertSingleResource.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "chiricutin";
MetricAlertData data = new MetricAlertData(
new AzureLocation("global"),
3,
true,
new string[] { "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme" },
XmlConvert.ToTimeSpan("PT1M"),
new MetricAlertMultipleResourceMultipleMetricCriteria
{
AllOf = {new DynamicMetricCriteria(
"High_CPU_80",
"Percentage CPU",
MetricCriteriaTimeAggregationType.Average,
DynamicThresholdOperator.GreaterOrLessThan,
DynamicThresholdSensitivity.Medium,
new DynamicThresholdFailingPeriods(4, 4))
{
IgnoreDataBefore = DateTimeOffset.Parse("2019-04-04T21:00:00.000Z"),
MetricNamespace = "microsoft.compute/virtualmachines",
Dimensions = {},
}},
})
{
Description = "This is the description of the rule1",
MonitorWindowSize = XmlConvert.ToTimeSpan("PT15M"),
IsAutoMitigateEnabled = true,
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
}},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/chiricutin",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "DynamicThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"operator": "GreaterOrLessThan",
"timeAggregation": "Average",
"dimensions": [],
"alertSensitivity": "Medium",
"failingPeriods": {
"numberOfEvaluationPeriods": 4,
"minFailingPeriodsToAlert": 4
},
"ignoreDataBefore": "2019-04-04T21:00:00.000Z"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
Create or update a query based alert rule
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/chiricutin?api-version=2024-03-01-preview
{
"location": "eastus",
"tags": {},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {}
}
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.monitor/accounts/gigwadme"
],
"evaluationFrequency": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
"failingPeriods": {
"for": "PT5M"
},
"allOf": [
{
"name": "Metric1",
"criterionType": "StaticThresholdCriterion",
"query": "avg({\"system.cpu.utilization\"}) > 90"
}
]
},
"resolveConfiguration": {
"autoResolved": true,
"timeToResolve": "PT10M"
},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"actionProperties": {
"Email.Sujbect": "my custom email subject"
},
"customProperties": {
"key11": "value11",
"key12": "value12"
}
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_query.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="chiricutin",
parameters={
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {}
},
},
"location": "eastus",
"properties": {
"actionProperties": {"Email.Sujbect": "my custom email subject"},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"criteria": {
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "Metric1",
"query": 'avg({"system.cpu.utilization"}) > 90',
}
],
"failingPeriods": {"for": "PT5M"},
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
},
"customProperties": {"key11": "value11", "key12": "value12"},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"resolveConfiguration": {"autoResolved": True, "timeToResolve": "PT10M"},
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.monitor/accounts/gigwadme"
],
"severity": 3,
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertQuery.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertQuery.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "chiricutin";
MetricAlertData data = new MetricAlertData(
new AzureLocation("eastus"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.monitor/accounts/gigwadme" },
XmlConvert.ToTimeSpan("PT1M"),
new PromQLCriteria
{
FailingPeriodsFor = XmlConvert.ToTimeSpan("PT5M"),
AllOf = { new StaticPromQLCriteria("Metric1", "avg({\"system.cpu.utilization\"}) > 90") },
})
{
Description = "This is the description of the rule1",
ResolveConfiguration = new ResolveConfiguration(true)
{
TimeToResolve = XmlConvert.ToTimeSpan("PT10M"),
},
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
}},
CustomProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
ActionProperties =
{
["Email.Sujbect"] = "my custom email subject"
},
Identity = new ManagedServiceIdentity("UserAssigned")
{
UserAssignedIdentities =
{
[new ResourceIdentifier("/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap")] = new UserAssignedIdentity()
},
},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/chiricutin",
"type": "Microsoft.Insights/metricAlerts",
"location": "eastus",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"identity": {
"type": "UserAssigned",
"tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {
"clientId": "778f4d04-3c60-4622-a839-5cf05866c983",
"principalId": "669dd76d-cde8-4dc3-b882-1de566b0c628"
}
}
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.monitor/accounts/gigwadme"
],
"evaluationFrequency": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
"failingPeriods": {
"for": "PT2M"
},
"allOf": [
{
"name": "Metric1",
"criterionType": "StaticThresholdCriterion",
"query": "avg({\"system.cpu.utilization\"}) > 90"
}
]
},
"resolveConfiguration": {
"autoResolved": true,
"timeToResolve": "PT10M"
},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"actionProperties": {
"Email.Sujbect": "my custom email subject"
},
"customProperties": {
"key11": "value11",
"key12": "value12"
}
}
}
Create or update a query based alert rule with dynamic threshold
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/chiricutin?api-version=2024-03-01-preview
{
"location": "eastus",
"tags": {},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {}
}
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.monitor/accounts/gigwadme"
],
"evaluationFrequency": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
"failingPeriods": {
"for": "PT5M"
},
"allOf": [
{
"name": "Metric1",
"criterionType": "DynamicThresholdCriterion",
"query": "avg({\"system.cpu.utilization\"})",
"operator": "LessThan",
"alertSensitivity": "Medium",
"ignoreDataBefore": "2019-04-04T21:00:00.000Z"
}
]
},
"resolveConfiguration": {
"autoResolved": true,
"timeToResolve": "PT10M"
},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"actionProperties": {
"Email.Sujbect": "my custom email subject"
},
"customProperties": {
"key11": "value11",
"key12": "value12"
}
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_query_dt.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="chiricutin",
parameters={
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {}
},
},
"location": "eastus",
"properties": {
"actionProperties": {"Email.Sujbect": "my custom email subject"},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"criteria": {
"allOf": [
{
"alertSensitivity": "Medium",
"criterionType": "DynamicThresholdCriterion",
"ignoreDataBefore": "2019-04-04T21:00:00.000Z",
"name": "Metric1",
"operator": "LessThan",
"query": 'avg({"system.cpu.utilization"})',
}
],
"failingPeriods": {"for": "PT5M"},
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
},
"customProperties": {"key11": "value11", "key12": "value12"},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"resolveConfiguration": {"autoResolved": True, "timeToResolve": "PT10M"},
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.monitor/accounts/gigwadme"
],
"severity": 3,
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertQueryDT.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertQueryDT.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "chiricutin";
MetricAlertData data = new MetricAlertData(
new AzureLocation("eastus"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.monitor/accounts/gigwadme" },
XmlConvert.ToTimeSpan("PT1M"),
new PromQLCriteria
{
FailingPeriodsFor = XmlConvert.ToTimeSpan("PT5M"),
AllOf = {new DynamicPromQLCriteria("Metric1", "avg({\"system.cpu.utilization\"})", DynamicThresholdOperator.LessThan, DynamicThresholdSensitivity.Medium)
{
IgnoreDataBefore = DateTimeOffset.Parse("2019-04-04T21:00:00.000Z"),
}},
})
{
Description = "This is the description of the rule1",
ResolveConfiguration = new ResolveConfiguration(true)
{
TimeToResolve = XmlConvert.ToTimeSpan("PT10M"),
},
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
}},
CustomProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
ActionProperties =
{
["Email.Sujbect"] = "my custom email subject"
},
Identity = new ManagedServiceIdentity("UserAssigned")
{
UserAssignedIdentities =
{
[new ResourceIdentifier("/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap")] = new UserAssignedIdentity()
},
},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/chiricutin",
"type": "Microsoft.Insights/metricAlerts",
"location": "eastus",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"identity": {
"type": "UserAssigned",
"tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {
"clientId": "778f4d04-3c60-4622-a839-5cf05866c983",
"principalId": "669dd76d-cde8-4dc3-b882-1de566b0c628"
}
}
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.monitor/accounts/gigwadme"
],
"evaluationFrequency": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
"failingPeriods": {
"for": "PT2M"
},
"allOf": [
{
"name": "Metric1",
"criterionType": "DynamicThresholdCriterion",
"query": "avg({\"system.cpu.utilization\"})",
"operator": "LessThan",
"alertSensitivity": "Medium",
"ignoreDataBefore": "2019-04-04T21:00:00.000Z"
}
]
},
"resolveConfiguration": {
"autoResolved": true,
"timeToResolve": "PT10M"
},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"actionProperties": {
"Email.Sujbect": "my custom email subject"
},
"customProperties": {
"key11": "value11",
"key12": "value12"
}
}
}
Create or update a resource centric query based alert rule
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/chiricutin?api-version=2024-03-01-preview
{
"location": "eastus",
"tags": {},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {}
}
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.compute/virtualMachines/myVmName"
],
"evaluationFrequency": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
"failingPeriods": {
"for": "PT5M"
},
"allOf": [
{
"name": "Metric1",
"criterionType": "StaticThresholdCriterion",
"query": "avg({\"system.cpu.utilization\"}) > 90"
}
]
},
"resolveConfiguration": {
"autoResolved": true,
"timeToResolve": "PT10M"
},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"actionProperties": {
"Email.Sujbect": "my custom email subject"
},
"customProperties": {
"key11": "value11",
"key12": "value12"
}
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_query_resource_centric.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="chiricutin",
parameters={
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {}
},
},
"location": "eastus",
"properties": {
"actionProperties": {"Email.Sujbect": "my custom email subject"},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"criteria": {
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "Metric1",
"query": 'avg({"system.cpu.utilization"}) > 90',
}
],
"failingPeriods": {"for": "PT5M"},
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
},
"customProperties": {"key11": "value11", "key12": "value12"},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"resolveConfiguration": {"autoResolved": True, "timeToResolve": "PT10M"},
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.compute/virtualMachines/myVmName"
],
"severity": 3,
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertQueryResourceCentric.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertQueryResourceCentric.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "chiricutin";
MetricAlertData data = new MetricAlertData(
new AzureLocation("eastus"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.compute/virtualMachines/myVmName" },
XmlConvert.ToTimeSpan("PT1M"),
new PromQLCriteria
{
FailingPeriodsFor = XmlConvert.ToTimeSpan("PT5M"),
AllOf = { new StaticPromQLCriteria("Metric1", "avg({\"system.cpu.utilization\"}) > 90") },
})
{
Description = "This is the description of the rule1",
ResolveConfiguration = new ResolveConfiguration(true)
{
TimeToResolve = XmlConvert.ToTimeSpan("PT10M"),
},
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
}},
CustomProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
ActionProperties =
{
["Email.Sujbect"] = "my custom email subject"
},
Identity = new ManagedServiceIdentity("UserAssigned")
{
UserAssignedIdentities =
{
[new ResourceIdentifier("/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap")] = new UserAssignedIdentity()
},
},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/chiricutin",
"type": "Microsoft.Insights/metricAlerts",
"location": "eastus",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"identity": {
"type": "UserAssigned",
"tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {
"clientId": "778f4d04-3c60-4622-a839-5cf05866c983",
"principalId": "669dd76d-cde8-4dc3-b882-1de566b0c628"
}
}
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/microsoft.compute/virtualMachines/myVmName"
],
"evaluationFrequency": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
"failingPeriods": {
"for": "PT2M"
},
"allOf": [
{
"name": "Metric1",
"criterionType": "StaticThresholdCriterion",
"query": "avg({\"system.cpu.utilization\"}) > 90"
}
]
},
"resolveConfiguration": {
"autoResolved": true,
"timeToResolve": "PT10M"
},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"actionProperties": {
"Email.Sujbect": "my custom email subject"
},
"customProperties": {
"key11": "value11",
"key12": "value12"
}
}
}
Create or update a resource centric query based alert rule for Multiple Resources
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/chiricutin?api-version=2024-03-01-preview
{
"location": "eastus",
"tags": {},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {}
}
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7"
],
"evaluationFrequency": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
"failingPeriods": {
"for": "PT5M"
},
"allOf": [
{
"name": "Metric1",
"criterionType": "StaticThresholdCriterion",
"query": "avg({\"system.cpu.utilization\"}) by (\"microsoft.resourceid\") > 90"
}
]
},
"resolveConfiguration": {
"autoResolved": true,
"timeToResolve": "PT10M"
},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"actionProperties": {
"Email.Sujbect": "my custom email subject"
},
"customProperties": {
"key11": "value11",
"key12": "value12"
}
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_query_multi_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="chiricutin",
parameters={
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {}
},
},
"location": "eastus",
"properties": {
"actionProperties": {"Email.Sujbect": "my custom email subject"},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"criteria": {
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "Metric1",
"query": 'avg({"system.cpu.utilization"}) by ("microsoft.resourceid") > 90',
}
],
"failingPeriods": {"for": "PT5M"},
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
},
"customProperties": {"key11": "value11", "key12": "value12"},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"resolveConfiguration": {"autoResolved": True, "timeToResolve": "PT10M"},
"scopes": ["/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7"],
"severity": 3,
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertQueryMultiResource.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertQueryMultiResource.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "chiricutin";
MetricAlertData data = new MetricAlertData(
new AzureLocation("eastus"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7" },
XmlConvert.ToTimeSpan("PT1M"),
new PromQLCriteria
{
FailingPeriodsFor = XmlConvert.ToTimeSpan("PT5M"),
AllOf = { new StaticPromQLCriteria("Metric1", "avg({\"system.cpu.utilization\"}) by (\"microsoft.resourceid\") > 90") },
})
{
Description = "This is the description of the rule1",
ResolveConfiguration = new ResolveConfiguration(true)
{
TimeToResolve = XmlConvert.ToTimeSpan("PT10M"),
},
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
}},
CustomProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
ActionProperties =
{
["Email.Sujbect"] = "my custom email subject"
},
Identity = new ManagedServiceIdentity("UserAssigned")
{
UserAssignedIdentities =
{
[new ResourceIdentifier("/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap")] = new UserAssignedIdentity()
},
},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/chiricutin",
"type": "Microsoft.Insights/metricAlerts",
"location": "eastus",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"identity": {
"type": "UserAssigned",
"tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47",
"userAssignedIdentities": {
"/subscriptions/2f1a501a-6e1d-4f37-a445-462d7f8a563d/resourceGroups/AdisTest/providers/Microsoft.ManagedIdentity/userAssignedIdentities/msi-test-euap": {
"clientId": "778f4d04-3c60-4622-a839-5cf05866c983",
"principalId": "669dd76d-cde8-4dc3-b882-1de566b0c628"
}
}
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7"
],
"evaluationFrequency": "PT1M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.PromQLCriteria",
"failingPeriods": {
"for": "PT2M"
},
"allOf": [
{
"name": "Metric1",
"criterionType": "StaticThresholdCriterion",
"query": "avg({\"system.cpu.utilization\"}) by (\"microsoft.resourceid\") > 90"
}
]
},
"resolveConfiguration": {
"autoResolved": true,
"timeToResolve": "PT10M"
},
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"
}
],
"actionProperties": {
"Email.Sujbect": "my custom email subject"
},
"customProperties": {
"key11": "value11",
"key12": "value12"
}
}
}
Create or update a web test alert rule
示例请求
PUT https://management.azure.com/subscriptions/12345678-1234-1234-1234-123456789101/resourceGroups/rg-example/providers/Microsoft.Insights/metricAlerts/webtest-name-example?api-version=2024-03-01-preview
{
"location": "global",
"tags": {
"hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example": "Resource",
"hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example": "Resource"
},
"properties": {
"description": "Automatically created alert rule for availability test \"component-example\" a",
"enabled": true,
"severity": 4,
"windowSize": "PT15M",
"evaluationFrequency": "PT1M",
"criteria": {
"failedLocationCount": 2,
"webTestId": "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example",
"componentId": "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example",
"odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria"
},
"actions": [],
"scopes": [
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example",
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example"
]
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_web_test_metric_alert.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="12345678-1234-1234-1234-123456789101",
)
response = client.metric_alerts.create_or_update(
resource_group_name="rg-example",
rule_name="webtest-name-example",
parameters={
"location": "global",
"properties": {
"actions": [],
"criteria": {
"componentId": "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example",
"failedLocationCount": 2,
"odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria",
"webTestId": "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example",
},
"description": 'Automatically created alert rule for availability test "component-example" a',
"enabled": True,
"evaluationFrequency": "PT1M",
"scopes": [
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example",
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example",
],
"severity": 4,
"windowSize": "PT15M",
},
"tags": {
"hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example": "Resource",
"hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example": "Resource",
},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateWebTestMetricAlert.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateWebTestMetricAlert.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "12345678-1234-1234-1234-123456789101";
string resourceGroupName = "rg-example";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "webtest-name-example";
MetricAlertData data = new MetricAlertData(
new AzureLocation("global"),
4,
true,
new string[] { "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example", "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example" },
XmlConvert.ToTimeSpan("PT1M"),
new WebtestLocationAvailabilityCriteria(new ResourceIdentifier("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example"), new ResourceIdentifier("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example"), 2))
{
Description = "Automatically created alert rule for availability test \"component-example\" a",
MonitorWindowSize = XmlConvert.ToTimeSpan("PT15M"),
Actions = { },
Tags =
{
["hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example"] = "Resource",
["hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example"] = "Resource"
},
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"location": "global",
"type": "Microsoft.Insights/metricAlerts",
"name": "webtest-name-example",
"id": "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/metricalerts/webtest-name-example",
"tags": {
"hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/component-example": "Resource",
"hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/webtest-name-example": "Resource"
},
"properties": {
"description": "Automatically created alert rule for availability test \"webtest-name-example\" a",
"severity": 4,
"enabled": true,
"scopes": [
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/webtest-name-example",
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/component-example"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"criteria": {
"webTestId": "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/webtest-name-example",
"componentId": "/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/component-example",
"failedLocationCount": 2,
"odata.type": "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria"
},
"actions": []
}
}
Create or update an alert rule for Multiple Resource
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/MetricAlertOnMultipleResources?api-version=2024-03-01-preview
{
"location": "global",
"tags": {},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1",
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_multiple_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="MetricAlertOnMultipleResources",
parameters={
"location": "global",
"properties": {
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {"key11": "value11", "key12": "value12"},
}
],
"autoMitigate": True,
"criteria": {
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"dimensions": [],
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"name": "High_CPU_80",
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average",
}
],
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1",
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2",
],
"severity": 3,
"targetResourceRegion": "southcentralus",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"windowSize": "PT15M",
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertMultipleResource.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertMultipleResource.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "MetricAlertOnMultipleResources";
MetricAlertData data = new MetricAlertData(
new AzureLocation("global"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1", "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2" },
XmlConvert.ToTimeSpan("PT1M"),
new MetricAlertMultipleResourceMultipleMetricCriteria
{
AllOf = {new MetricCriteria("High_CPU_80", "Percentage CPU", MetricCriteriaTimeAggregationType.Average, MetricCriteriaOperator.GreaterThan, 80.5)
{
MetricNamespace = "microsoft.compute/virtualmachines",
Dimensions = {},
}},
})
{
Description = "This is the description of the rule1",
MonitorWindowSize = XmlConvert.ToTimeSpan("PT15M"),
TargetResourceType = new ResourceType("Microsoft.Compute/virtualMachines"),
TargetResourceRegion = new AzureLocation("southcentralus"),
IsAutoMitigateEnabled = true,
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
}},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/MetricAlertOnMultipleResources",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1",
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
Create or update an alert rule for Single Resource
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/chiricutin?api-version=2024-03-01-preview
{
"location": "global",
"tags": {},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "High_CPU_80",
"metricName": "\\Processor(_Total)\\% Processor Time",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_single_resource.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="chiricutin",
parameters={
"location": "global",
"properties": {
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {"key11": "value11", "key12": "value12"},
}
],
"autoMitigate": True,
"criteria": {
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"dimensions": [],
"metricName": "\\Processor(_Total)\\% Processor Time",
"name": "High_CPU_80",
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average",
}
],
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme"
],
"severity": 3,
"windowSize": "PT15M",
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertSingleResource.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertSingleResource.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "chiricutin";
MetricAlertData data = new MetricAlertData(
new AzureLocation("global"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme" },
XmlConvert.ToTimeSpan("PT1M"),
new MetricAlertSingleResourceMultipleMetricCriteria
{
AllOf = {new MetricCriteria("High_CPU_80", "\\Processor(_Total)\\% Processor Time", MetricCriteriaTimeAggregationType.Average, MetricCriteriaOperator.GreaterThan, 80.5)
{
Dimensions = {},
}},
})
{
Description = "This is the description of the rule1",
MonitorWindowSize = XmlConvert.ToTimeSpan("PT15M"),
IsAutoMitigateEnabled = true,
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
}},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/chiricutin",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "High_CPU_80",
"metricName": "\\Processor(_Total)\\% Processor Time",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
Create or update an alert rule on Resource group(s)
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1/providers/Microsoft.Insights/metricAlerts/MetricAlertAtResourceGroupLevel?api-version=2024-03-01-preview
{
"location": "global",
"tags": {},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1",
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest2"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_resource_group.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest1",
rule_name="MetricAlertAtResourceGroupLevel",
parameters={
"location": "global",
"properties": {
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {"key11": "value11", "key12": "value12"},
}
],
"autoMitigate": True,
"criteria": {
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"dimensions": [],
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"name": "High_CPU_80",
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average",
}
],
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1",
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest2",
],
"severity": 3,
"targetResourceRegion": "southcentralus",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"windowSize": "PT15M",
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertResourceGroup.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertResourceGroup.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest1";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "MetricAlertAtResourceGroupLevel";
MetricAlertData data = new MetricAlertData(
new AzureLocation("global"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1", "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest2" },
XmlConvert.ToTimeSpan("PT1M"),
new MetricAlertMultipleResourceMultipleMetricCriteria
{
AllOf = {new MetricCriteria("High_CPU_80", "Percentage CPU", MetricCriteriaTimeAggregationType.Average, MetricCriteriaOperator.GreaterThan, 80.5)
{
MetricNamespace = "microsoft.compute/virtualmachines",
Dimensions = {},
}},
})
{
Description = "This is the description of the rule1",
MonitorWindowSize = XmlConvert.ToTimeSpan("PT15M"),
TargetResourceType = new ResourceType("Microsoft.Compute/virtualMachines"),
TargetResourceRegion = new AzureLocation("southcentralus"),
IsAutoMitigateEnabled = true,
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
}},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1/providers/providers/microsoft.insights/metricalerts/MetricAlertAtResourceGroupLevel",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1",
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest2"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
Create or update an alert rule on Subscription
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/MetricAlertAtSubscriptionLevel?api-version=2024-03-01-preview
{
"location": "global",
"tags": {},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_subscription.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="MetricAlertAtSubscriptionLevel",
parameters={
"location": "global",
"properties": {
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {"key11": "value11", "key12": "value12"},
}
],
"autoMitigate": True,
"criteria": {
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"dimensions": [],
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"name": "High_CPU_80",
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average",
}
],
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1M",
"scopes": ["/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7"],
"severity": 3,
"targetResourceRegion": "southcentralus",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"windowSize": "PT15M",
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertSubscription.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertSubscription.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "MetricAlertAtSubscriptionLevel";
MetricAlertData data = new MetricAlertData(
new AzureLocation("global"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7" },
XmlConvert.ToTimeSpan("PT1M"),
new MetricAlertMultipleResourceMultipleMetricCriteria
{
AllOf = {new MetricCriteria("High_CPU_80", "Percentage CPU", MetricCriteriaTimeAggregationType.Average, MetricCriteriaOperator.GreaterThan, 80.5)
{
MetricNamespace = "microsoft.compute/virtualmachines",
Dimensions = {},
}},
})
{
Description = "This is the description of the rule1",
MonitorWindowSize = XmlConvert.ToTimeSpan("PT15M"),
TargetResourceType = new ResourceType("Microsoft.Compute/virtualMachines"),
TargetResourceRegion = new AzureLocation("southcentralus"),
IsAutoMitigateEnabled = true,
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
}},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/MetricAlertAtSubscriptionLevel",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7"
],
"evaluationFrequency": "PT1M",
"windowSize": "PT15M",
"targetResourceType": "Microsoft.Compute/virtualMachines",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"name": "High_CPU_80",
"metricName": "Percentage CPU",
"metricNamespace": "microsoft.compute/virtualmachines",
"dimensions": [],
"operator": "GreaterThan",
"threshold": 80.5,
"timeAggregation": "Average"
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
Create or update an alert rules with dimensions
示例请求
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/MetricAlertOnMultipleDimensions?api-version=2024-03-01-preview
{
"location": "global",
"tags": {},
"properties": {
"description": "This is the description of the rule1",
"enabled": true,
"severity": 3,
"windowSize": "P1D",
"evaluationFrequency": "PT1H",
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.KeyVault/vaults/keyVaultResource"
],
"criteria": {
"allOf": [
{
"metricName": "Availability",
"metricNamespace": "Microsoft.KeyVault/vaults",
"operator": "GreaterThan",
"timeAggregation": "Average",
"name": "Metric1",
"dimensions": [
{
"name": "ActivityName",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "StatusCode",
"operator": "Include",
"values": [
"200"
]
}
],
"criterionType": "StaticThresholdCriterion",
"threshold": 55
}
],
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria"
},
"actions": [
{
"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
],
"autoMitigate": true
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.monitor import MonitorManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-monitor
# USAGE
python create_or_update_metric_alert_with_dimensions.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = MonitorManagementClient(
credential=DefaultAzureCredential(),
subscription_id="14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7",
)
response = client.metric_alerts.create_or_update(
resource_group_name="gigtest",
rule_name="MetricAlertOnMultipleDimensions",
parameters={
"location": "global",
"properties": {
"actions": [
{
"actionGroupId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {"key11": "value11", "key12": "value12"},
}
],
"autoMitigate": True,
"criteria": {
"allOf": [
{
"criterionType": "StaticThresholdCriterion",
"dimensions": [
{"name": "ActivityName", "operator": "Include", "values": ["*"]},
{"name": "StatusCode", "operator": "Include", "values": ["200"]},
],
"metricName": "Availability",
"metricNamespace": "Microsoft.KeyVault/vaults",
"name": "Metric1",
"operator": "GreaterThan",
"threshold": 55,
"timeAggregation": "Average",
}
],
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
"description": "This is the description of the rule1",
"enabled": True,
"evaluationFrequency": "PT1H",
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.KeyVault/vaults/keyVaultResource"
],
"severity": 3,
"windowSize": "P1D",
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertWithDimensions.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using System.Xml;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.Models;
using Azure.ResourceManager.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/preview/2024-03-01-preview/examples/createOrUpdateMetricAlertWithDimensions.json
// this example is just showing the usage of "MetricAlerts_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
string resourceGroupName = "gigtest";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this MetricAlertResource
MetricAlertCollection collection = resourceGroupResource.GetMetricAlerts();
// invoke the operation
string ruleName = "MetricAlertOnMultipleDimensions";
MetricAlertData data = new MetricAlertData(
new AzureLocation("global"),
3,
true,
new string[] { "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.KeyVault/vaults/keyVaultResource" },
XmlConvert.ToTimeSpan("PT1H"),
new MetricAlertMultipleResourceMultipleMetricCriteria
{
AllOf = {new MetricCriteria("Metric1", "Availability", MetricCriteriaTimeAggregationType.Average, MetricCriteriaOperator.GreaterThan, 55)
{
MetricNamespace = "Microsoft.KeyVault/vaults",
Dimensions = {new MetricDimension("ActivityName", "Include", new string[]{"*"}), new MetricDimension("StatusCode", "Include", new string[]{"200"})},
}},
})
{
Description = "This is the description of the rule1",
MonitorWindowSize = XmlConvert.ToTimeSpan("P1D"),
IsAutoMitigateEnabled = true,
Actions = {new MetricAlertAction
{
ActionGroupId = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties =
{
["key11"] = "value11",
["key12"] = "value12"
},
}},
Tags = { },
};
ArmOperation<MetricAlertResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, ruleName, data);
MetricAlertResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
MetricAlertData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
示例响应
{
"id": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/MetricAlertWithDimensions",
"type": "Microsoft.Insights/metricAlerts",
"location": "global",
"tags": {
"hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": "Resource"
},
"properties": {
"description": "This is the description of the rule1",
"severity": 3,
"enabled": true,
"scopes": [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.KeyVault/vaults/keyVaultResource"
],
"evaluationFrequency": "PT1H",
"windowSize": "P1D",
"targetResourceType": "Microsoft.KeyVault/vaults",
"targetResourceRegion": "southcentralus",
"criteria": {
"odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
"allOf": [
{
"metricName": "Availability",
"metricNamespace": "Microsoft.KeyVault/vaults",
"operator": "GreaterThan",
"timeAggregation": "Average",
"name": "Metric1",
"dimensions": [
{
"name": "ActivityName",
"operator": "Include",
"values": [
"*"
]
},
{
"name": "StatusCode",
"operator": "Include",
"values": [
"200"
]
}
],
"criterionType": "StaticThresholdCriterion",
"threshold": 55
}
]
},
"autoMitigate": true,
"actions": [
{
"actionGroupId": "/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
"webHookProperties": {
"key11": "value11",
"key12": "value12"
}
}
]
}
}
定义
AdditionalInfo
对象
一组具有“类型”和“信息”属性的对象。 “info”的模式是服务特定的,并且依赖于“类型”字符串。
| 名称 |
类型 |
说明 |
|
info
|
|
针对该类型的额外信息。
|
|
type
|
string
|
附加信息的类型。
|
AggregationTypeEnum
枚举
条件时间聚合类型。 可能会返回以前未记录的值
| 值 |
说明 |
|
Average
|
|
|
Count
|
|
|
Minimum
|
|
|
Maximum
|
|
|
Total
|
|
DynamicMetricCriteria
对象
动态阈值的判准标准。
| 名称 |
类型 |
说明 |
|
alertSensitivity
|
DynamicThresholdSensitivity
|
触发警报所需的偏差范围。 这会影响阈值对指标系列模式的严格程度。 可能会返回以前未记录的值
|
|
criterionType
|
string:
DynamicThresholdCriterion
|
指定阈值条件的类型。 可能会返回以前未记录的值
|
|
dimensions
|
MetricDimension[]
|
维度条件列表。
|
|
failingPeriods
|
DynamicThresholdFailingPeriods
|
在引发警报所需的所选回溯时间范围内所需的最小冲突数。
|
|
ignoreDataBefore
|
string
(date-time)
|
使用此选项可设置开始学习指标历史数据的日期并计算动态阈值(ISO8601格式)
|
|
metricName
|
string
|
指标的名称。
|
|
metricNamespace
|
string
|
指标Namespace。
|
|
name
|
string
|
条件的名称。
|
|
operator
|
DynamicThresholdOperator
|
用于将指标值与阈值进行比较的运算符。 可能会返回以前未记录的值
|
|
skipMetricValidation
|
boolean
|
允许尚未发出的自定义指标创建警报规则,方式是使跳过指标验证。
|
|
timeAggregation
|
AggregationTypeEnum
|
条件时间聚合类型。 可能会返回以前未记录的值
|
DynamicPromQLCriteria
对象
动态舞会查询的标准。
| 名称 |
类型 |
说明 |
|
alertSensitivity
|
DynamicThresholdSensitivity
|
触发警报所需的偏差范围。 这会影响阈值对指标系列模式的严格程度。 可能会返回以前未记录的值
|
|
criterionType
|
string:
DynamicThresholdCriterion
|
指定阈值条件的类型。 可能会返回以前未记录的值
|
|
ignoreDataBefore
|
string
(date-time)
|
使用此选项可设置开始学习指标历史数据的日期并计算动态阈值(ISO8601格式)
|
|
name
|
string
|
条件的名称。
|
|
operator
|
DynamicThresholdOperator
|
用于将指标值与阈值进行比较的运算符。 可能会返回以前未记录的值
|
|
query
|
string
|
用于评估警报规则的查询
|
DynamicThresholdFailingPeriods
对象
在引发警报所需的所选回溯时间范围内所需的最小冲突数。
| 名称 |
类型 |
说明 |
|
minFailingPeriodsToAlert
|
number
|
触发警报的冲突数。 应小于或等于 numberOfEvaluationPeriods。
|
|
numberOfEvaluationPeriods
|
number
|
聚合回溯点数。 回溯时间窗口是根据聚合粒度(windowSize)和所选聚合点数计算的。
|
DynamicThresholdOperator
枚举
用于将指标值与阈值进行比较的运算符。 可能会返回以前未记录的值
| 值 |
说明 |
|
GreaterThan
|
|
|
LessThan
|
|
|
GreaterOrLessThan
|
|
DynamicThresholdSensitivity
枚举
触发警报所需的偏差范围。 这会影响阈值对指标系列模式的严格程度。 可能会返回以前未记录的值
Error
对象
| 名称 |
类型 |
说明 |
|
additionalInfo
|
AdditionalInfo[]
|
一组具有“类型”和“信息”属性的对象。 “info”的模式是服务特定的,并且依赖于“类型”字符串。
|
|
code
|
string
|
未局域字符串,可用于程序识别错误。
|
|
details
|
ErrorDetail[]
|
其他嵌套错误响应信息对象数组,如此协定所述。
|
|
message
|
string
|
详细描述错误并提供调试信息。 如果请求中设置了 Accept-Language,则必须本地化到该语言。
|
|
target
|
string
|
特定错误的目标(例如,出错的属性的名称)。
|
ErrorDetail
对象
描述错误响应的细节。
| 名称 |
类型 |
说明 |
|
additionalInfo
|
AdditionalInfo[]
|
一组具有“类型”和“信息”属性的对象。 “info”的模式是服务特定的,并且依赖于“类型”字符串。
|
|
code
|
string
|
未局域字符串,可用于程序识别错误。
|
|
message
|
string
|
详细描述错误并提供调试信息。
|
|
target
|
string
|
特定错误的目标(例如,出错的属性的名称)。
|
ErrorResponse
对象
描述错误响应的格式。
Identity
对象
资源的标识。
| 名称 |
类型 |
说明 |
|
principalId
|
string
|
资源标识的主体 ID。
|
|
tenantId
|
string
|
资源的租户 ID。
|
|
type
|
IdentityType
|
托管服务标识的类型。 可能会返回以前未记录的值
|
|
userAssignedIdentities
|
<string,
UserIdentityProperties>
|
与资源关联的用户标识列表。 用户标识字典键引用将是 Azure 资源 ID,格式为:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。
|
IdentityType
枚举
托管服务标识的类型。 可能会返回以前未记录的值
| 值 |
说明 |
|
SystemAssigned
|
|
|
UserAssigned
|
|
|
None
|
|
MetricAlertAction
对象
警报作。
| 名称 |
类型 |
说明 |
|
actionGroupId
|
string
|
要使用的作组的 ID。
|
|
webHookProperties
|
object
|
此字段允许指定自定义属性,这些属性将追加到作为输入发送到 Webhook 的警报有效负载中。
|
MetricAlertMultipleResourceMultipleMetricCriteria
对象
指定具有多个指标标准的多资源的指标警报标准。
| 名称 |
类型 |
说明 |
|
allOf
|
MultiMetricCriteria[]:
|
此“全部”作的多个指标条件的列表。
|
|
odata.type
|
string:
Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria
|
指定警报条件的类型。 可能会返回以前未记录的值
|
MetricAlertResource
对象
指标警报资源。
| 名称 |
类型 |
说明 |
|
id
|
string
|
Azure 资源 ID
|
|
identity
|
Identity
|
资源的标识。
|
|
location
|
string
|
资源位置
|
|
name
|
string
|
Azure 资源名称
|
|
properties.actionProperties
|
object
|
操作属性的属性。
|
|
properties.actions
|
MetricAlertAction[]
|
警报规则处于活动状态以及解决警报条件时执行的操作数组。
|
|
properties.autoMitigate
|
boolean
|
指示是否应自动解决警报的标志。 默认值为 true。
|
|
properties.criteria
|
MetricAlertCriteria:
|
定义特定的警报条件信息。
|
|
properties.customProperties
|
object
|
警报有效负载的属性。
|
|
properties.description
|
string
|
警报电子邮件中将包含的指标警报的说明。
|
|
properties.enabled
|
boolean
|
指示是否启用指标警报的标志。
|
|
properties.evaluationFrequency
|
string
(duration)
|
以 ISO 8601 持续时间格式表示衡量指标警报的评估频率。
|
|
properties.isMigrated
|
boolean
|
该值表示该警报规则是否被迁移。
|
|
properties.lastUpdatedTime
|
string
(date-time)
|
上次规则更新为ISO8601格式。
|
|
properties.resolveConfiguration
|
ResolveConfiguration
|
如何解决警示的配置。 适用于 PromQLCriteria。
|
|
properties.scopes
|
string[]
|
此指标警报的范围所针对的资源 ID 列表。 不能根据日志更改指标规则的范围。
|
|
properties.severity
|
integer
(int32)
|
警报严重性 {0, 1, 2, 3, 4}
|
|
properties.targetResourceRegion
|
string
|
在其上创建/更新警报的目标资源的区域。 如果范围包含订阅、资源组或多个资源,则是必需的。
|
|
properties.targetResourceType
|
string
|
在其上创建/更新警报的目标资源的资源类型。 如果范围包含订阅、资源组或多个资源,则是必需的。
|
|
properties.windowSize
|
string
(duration)
|
用于根据阈值监视警报活动的时间段(采用 ISO 8601 持续时间格式)。
|
|
tags
|
object
|
资源标记
|
|
type
|
string
|
Azure 资源类型
|
MetricAlertSingleResourceMultipleMetricCriteria
对象
指定具有多个指标标准的单一资源的指标警报标准。
| 名称 |
类型 |
说明 |
|
allOf
|
MetricCriteria[]
|
此“全部”操作的指标条件列表。
|
|
odata.type
|
string:
Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria
|
指定警报条件的类型。 可能会返回以前未记录的值
|
MetricCriteria
对象
标准用于过滤指标。
| 名称 |
类型 |
说明 |
|
criterionType
|
string:
StaticThresholdCriterion
|
指定阈值条件的类型。 可能会返回以前未记录的值
|
|
dimensions
|
MetricDimension[]
|
维度条件列表。
|
|
metricName
|
string
|
指标的名称。
|
|
metricNamespace
|
string
|
指标Namespace。
|
|
name
|
string
|
条件的名称。
|
|
operator
|
Operator
|
条件运算符。 可能会返回以前未记录的值
|
|
skipMetricValidation
|
boolean
|
允许尚未发出的自定义指标创建警报规则,方式是使跳过指标验证。
|
|
threshold
|
number
(double)
|
激活警报的条件阈值。
|
|
timeAggregation
|
AggregationTypeEnum
|
条件时间聚合类型。 可能会返回以前未记录的值
|
MetricDimension
对象
指定一个度量维度。
| 名称 |
类型 |
说明 |
|
name
|
string
|
维度的名称。
|
|
operator
|
string
|
维度运算符。 仅支持“Include”和“Exclude”
|
|
values
|
string[]
|
维度值列表。
|
Operator
枚举
条件运算符。 可能会返回以前未记录的值
| 值 |
说明 |
|
Equals
|
|
|
GreaterThan
|
|
|
GreaterThanOrEqual
|
|
|
LessThan
|
|
|
LessThanOrEqual
|
|
PromQLCriteria
对象
指定了度量警报资源的PromQL标准。
| 名称 |
类型 |
说明 |
|
allOf
|
MultiPromQLCriteria[]:
|
promQL 标准列表。 当满足所有条件时,将发出警报。
|
|
failingPeriods
|
QueryFailingPeriods
|
基于查询的警报中失败周期的配置。
|
|
odata.type
|
string:
Microsoft.Azure.Monitor.PromQLCriteria
|
指定警报条件的类型。 可能会返回以前未记录的值
|
QueryFailingPeriods
对象
基于查询的警报中失败周期的配置。
| 名称 |
类型 |
说明 |
|
for
|
string
(duration)
|
触发前必须激活时间量(以 ISO 8601 持续时间格式)警报。
|
ResolveConfiguration
对象
| 名称 |
类型 |
说明 |
|
autoResolved
|
boolean
|
指示是否应自动解决警报
|
|
timeToResolve
|
string
(duration)
|
警报应自动解决的时间(以 ISO 8601 持续时间格式)
|
StaticPromQLCriteria
对象
静态舞会查询的标准。
| 名称 |
类型 |
说明 |
|
criterionType
|
string:
StaticThresholdCriterion
|
指定阈值条件的类型。 可能会返回以前未记录的值
|
|
name
|
string
|
条件的名称。
|
|
query
|
string
|
用于评估警报规则的查询
|
UserIdentityProperties
对象
用户分配身份的属性。
| 名称 |
类型 |
说明 |
|
clientId
|
string
|
资源身份的客户端ID。
|
|
principalId
|
string
|
资源标识的主体 ID。
|
WebtestLocationAvailabilityCriteria
对象
规定了网络测试资源的指标警报规则标准。
| 名称 |
类型 |
说明 |
|
componentId
|
string
|
Application Insights 资源 ID。
|
|
failedLocationCount
|
number
|
失败的位置数。
|
|
odata.type
|
string:
Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria
|
指定警报条件的类型。 可能会返回以前未记录的值
|
|
webTestId
|
string
|
Application Insights Web 测试 ID。
|