Een definitie van metrische waarschuwingen maken of bijwerken.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/metricAlerts/{ruleName}?api-version=2018-03-01
URI-parameters
Name |
In |
Vereist |
Type |
Description |
resourceGroupName
|
path |
True
|
string
|
De naam van de resourcegroep. De naam is niet hoofdlettergevoelig.
|
ruleName
|
path |
True
|
string
|
De naam van de regel.
|
subscriptionId
|
path |
True
|
string
|
De id van het doelabonnement.
|
api-version
|
query |
True
|
string
|
De API-versie die voor deze bewerking moet worden gebruikt.
|
Aanvraagbody
Name |
Vereist |
Type |
Description |
location
|
True
|
string
|
Resourcelocatie
|
properties.criteria
|
True
|
MetricAlertCriteria:
|
definieert de specifieke informatie over waarschuwingscriteria.
|
properties.enabled
|
True
|
boolean
|
de vlag die aangeeft of de waarschuwing voor metrische gegevens is ingeschakeld.
|
properties.evaluationFrequency
|
True
|
string
|
hoe vaak de metrische waarschuwing wordt geëvalueerd, weergegeven in de ISO 8601-duurnotatie.
|
properties.scopes
|
True
|
string[]
|
de lijst met resource-id's waarop deze metrische waarschuwing is gericht.
|
properties.severity
|
True
|
integer
|
Ernst van waarschuwing {0, 1, 2, 3, 4}
|
properties.windowSize
|
True
|
string
|
de periode (in iso 8601-duurnotatie) die wordt gebruikt voor het bewaken van waarschuwingsactiviteiten op basis van de drempelwaarde.
|
properties.actions
|
|
MetricAlertAction[]
|
de matrix met acties die worden uitgevoerd wanneer de waarschuwingsregel actief wordt en wanneer een waarschuwingsvoorwaarde is opgelost.
|
properties.autoMitigate
|
|
boolean
|
de vlag die aangeeft of de waarschuwing automatisch moet worden opgelost of niet. De standaardwaarde is true.
|
properties.description
|
|
string
|
de beschrijving van de metrische waarschuwing die wordt opgenomen in de waarschuwings-e-mail.
|
properties.targetResourceRegion
|
|
string
|
de regio van de doelresource(s) waarop de waarschuwing wordt gemaakt/bijgewerkt. Verplicht als het bereik een abonnement, resourcegroep of meer dan één resource bevat.
|
properties.targetResourceType
|
|
string
|
het resourcetype van de doelresource(s) waarop de waarschuwing wordt gemaakt/bijgewerkt. Verplicht als het bereik een abonnement, resourcegroep of meer dan één resource bevat.
|
tags
|
|
object
|
Resourcetags
|
Antwoorden
Beveiliging
azure_auth
Azure Active Directory OAuth2-stroom
Type:
oauth2
Stroom:
implicit
Autorisatie-URL:
https://login.microsoftonline.com/common/oauth2/authorize
Bereiken
Name |
Description |
user_impersonation
|
Uw gebruikersaccount imiteren
|
Voorbeelden
Create or update a dynamic alert rule for Multiple Resources
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/MetricAlertOnMultipleResources?api-version=2018-03-01
{
"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"
}
}
]
}
}
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.AggregationTypeEnum;
import com.azure.resourcemanager.monitor.models.DynamicMetricCriteria;
import com.azure.resourcemanager.monitor.models.DynamicThresholdFailingPeriods;
import com.azure.resourcemanager.monitor.models.DynamicThresholdOperator;
import com.azure.resourcemanager.monitor.models.DynamicThresholdSensitivity;
import com.azure.resourcemanager.monitor.models.MetricAlertAction;
import com.azure.resourcemanager.monitor.models.MetricAlertMultipleResourceMultipleMetricCriteria;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for MetricAlerts CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/
* createOrUpdateDynamicMetricAlertMultipleResource.json
*/
/**
* Sample code: Create or update a dynamic alert rule for Multiple Resources.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createOrUpdateADynamicAlertRuleForMultipleResources(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getMetricAlerts().createOrUpdateWithResponse("gigtest",
"MetricAlertOnMultipleResources",
new MetricAlertResourceInner().withLocation("global").withTags(mapOf())
.withDescription("This is the description of the rule1").withSeverity(3).withEnabled(true)
.withScopes(Arrays.asList(
"/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"))
.withEvaluationFrequency(Duration.parse("PT1M")).withWindowSize(Duration.parse("PT15M"))
.withTargetResourceType("Microsoft.Compute/virtualMachines").withTargetResourceRegion("southcentralus")
.withCriteria(new MetricAlertMultipleResourceMultipleMetricCriteria()
.withAllOf(Arrays.asList(new DynamicMetricCriteria().withName("High_CPU_80")
.withMetricName("Percentage CPU").withMetricNamespace("microsoft.compute/virtualmachines")
.withTimeAggregation(AggregationTypeEnum.AVERAGE).withDimensions(Arrays.asList())
.withOperator(DynamicThresholdOperator.GREATER_OR_LESS_THAN)
.withAlertSensitivity(DynamicThresholdSensitivity.MEDIUM)
.withFailingPeriods(new DynamicThresholdFailingPeriods()
.withNumberOfEvaluationPeriods(4f).withMinFailingPeriodsToAlert(4f)))))
.withAutoMitigate(true)
.withActions(Arrays.asList(new MetricAlertAction().withActionGroupId(
"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2")
.withWebhookProperties(mapOf("key11", "fakeTokenPlaceholder", "key12", "fakeTokenPlaceholder")))),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateDynamicMetricAlertMultipleResource.json
func ExampleMetricAlertsClient_CreateOrUpdate_createOrUpdateADynamicAlertRuleForMultipleResources() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewMetricAlertsClient().CreateOrUpdate(ctx, "gigtest", "MetricAlertOnMultipleResources", armmonitor.MetricAlertResource{
Location: to.Ptr("global"),
Tags: map[string]*string{},
Properties: &armmonitor.MetricAlertProperties{
Description: to.Ptr("This is the description of the rule1"),
Actions: []*armmonitor.MetricAlertAction{
{
ActionGroupID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties: map[string]*string{
"key11": to.Ptr("value11"),
"key12": to.Ptr("value12"),
},
}},
AutoMitigate: to.Ptr(true),
Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
AllOf: []armmonitor.MultiMetricCriteriaClassification{
&armmonitor.DynamicMetricCriteria{
Name: to.Ptr("High_CPU_80"),
CriterionType: to.Ptr(armmonitor.CriterionTypeDynamicThresholdCriterion),
Dimensions: []*armmonitor.MetricDimension{},
MetricName: to.Ptr("Percentage CPU"),
MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
AlertSensitivity: to.Ptr(armmonitor.DynamicThresholdSensitivityMedium),
FailingPeriods: &armmonitor.DynamicThresholdFailingPeriods{
MinFailingPeriodsToAlert: to.Ptr[float32](4),
NumberOfEvaluationPeriods: to.Ptr[float32](4),
},
Operator: to.Ptr(armmonitor.DynamicThresholdOperatorGreaterOrLessThan),
}},
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("PT1M"),
Scopes: []*string{
to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1"),
to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2")},
Severity: to.Ptr[int32](3),
TargetResourceRegion: to.Ptr("southcentralus"),
TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
WindowSize: to.Ptr("PT15M"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.MetricAlertResource = armmonitor.MetricAlertResource{
// Type: to.Ptr("Microsoft.Insights/metricAlerts"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/MetricAlertOnMultipleResources"),
// Location: to.Ptr("global"),
// Tags: map[string]*string{
// "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": to.Ptr("Resource"),
// },
// Properties: &armmonitor.MetricAlertProperties{
// Description: to.Ptr("This is the description of the rule1"),
// Actions: []*armmonitor.MetricAlertAction{
// {
// ActionGroupID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
// WebHookProperties: map[string]*string{
// "key11": to.Ptr("value11"),
// "key12": to.Ptr("value12"),
// },
// }},
// AutoMitigate: to.Ptr(true),
// Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
// ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
// AllOf: []armmonitor.MultiMetricCriteriaClassification{
// &armmonitor.DynamicMetricCriteria{
// Name: to.Ptr("High_CPU_80"),
// CriterionType: to.Ptr(armmonitor.CriterionTypeDynamicThresholdCriterion),
// Dimensions: []*armmonitor.MetricDimension{
// },
// MetricName: to.Ptr("Percentage CPU"),
// MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
// TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
// AlertSensitivity: to.Ptr(armmonitor.DynamicThresholdSensitivityMedium),
// FailingPeriods: &armmonitor.DynamicThresholdFailingPeriods{
// MinFailingPeriodsToAlert: to.Ptr[float32](4),
// NumberOfEvaluationPeriods: to.Ptr[float32](4),
// },
// Operator: to.Ptr(armmonitor.DynamicThresholdOperatorGreaterOrLessThan),
// }},
// },
// Enabled: to.Ptr(true),
// EvaluationFrequency: to.Ptr("PT1M"),
// Scopes: []*string{
// to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1"),
// to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2")},
// Severity: to.Ptr[int32](3),
// TargetResourceRegion: to.Ptr("southcentralus"),
// TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
// WindowSize: to.Ptr("PT15M"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update an metric alert definition.
*
* @summary Create or update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateDynamicMetricAlertMultipleResource.json
*/
async function createOrUpdateADynamicAlertRuleForMultipleResources() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "gigtest";
const ruleName = "MetricAlertOnMultipleResources";
const parameters = {
description: "This is the description of the rule1",
actions: [
{
actionGroupId:
"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
webHookProperties: { key11: "value11", key12: "value12" },
},
],
autoMitigate: true,
criteria: {
allOf: [
{
name: "High_CPU_80",
alertSensitivity: "Medium",
criterionType: "DynamicThresholdCriterion",
dimensions: [],
failingPeriods: {
minFailingPeriodsToAlert: 4,
numberOfEvaluationPeriods: 4,
},
metricName: "Percentage CPU",
metricNamespace: "microsoft.compute/virtualmachines",
operator: "GreaterOrLessThan",
timeAggregation: "Average",
},
],
odataType: "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
enabled: true,
evaluationFrequency: "PT1M",
location: "global",
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,
tags: {},
targetResourceRegion: "southcentralus",
targetResourceType: "Microsoft.Compute/virtualMachines",
windowSize: "PT15M",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.createOrUpdate(resourceGroupName, ruleName, parameters);
console.log(result);
}
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.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/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"), XmlConvert.ToTimeSpan("PT15M"), 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",
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
Voorbeeldrespons
{
"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
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/chiricutin?api-version=2018-03-01
{
"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"
}
}
]
}
}
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.AggregationTypeEnum;
import com.azure.resourcemanager.monitor.models.DynamicMetricCriteria;
import com.azure.resourcemanager.monitor.models.DynamicThresholdFailingPeriods;
import com.azure.resourcemanager.monitor.models.DynamicThresholdOperator;
import com.azure.resourcemanager.monitor.models.DynamicThresholdSensitivity;
import com.azure.resourcemanager.monitor.models.MetricAlertAction;
import com.azure.resourcemanager.monitor.models.MetricAlertMultipleResourceMultipleMetricCriteria;
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for MetricAlerts CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/
* createOrUpdateDynamicMetricAlertSingleResource.json
*/
/**
* Sample code: Create or update a dynamic alert rule for Single Resource.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createOrUpdateADynamicAlertRuleForSingleResource(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getMetricAlerts().createOrUpdateWithResponse("gigtest",
"chiricutin",
new MetricAlertResourceInner().withLocation("global").withTags(mapOf())
.withDescription("This is the description of the rule1").withSeverity(3).withEnabled(true)
.withScopes(Arrays.asList(
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme"))
.withEvaluationFrequency(Duration.parse("PT1M")).withWindowSize(Duration.parse("PT15M"))
.withCriteria(new MetricAlertMultipleResourceMultipleMetricCriteria()
.withAllOf(Arrays.asList(new DynamicMetricCriteria().withName("High_CPU_80")
.withMetricName("Percentage CPU").withMetricNamespace("microsoft.compute/virtualmachines")
.withTimeAggregation(AggregationTypeEnum.AVERAGE).withDimensions(Arrays.asList())
.withOperator(DynamicThresholdOperator.GREATER_OR_LESS_THAN)
.withAlertSensitivity(DynamicThresholdSensitivity.MEDIUM)
.withFailingPeriods(new DynamicThresholdFailingPeriods().withNumberOfEvaluationPeriods(4f)
.withMinFailingPeriodsToAlert(4f))
.withIgnoreDataBefore(OffsetDateTime.parse("2019-04-04T21:00:00.000Z")))))
.withAutoMitigate(true)
.withActions(Arrays.asList(new MetricAlertAction().withActionGroupId(
"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2")
.withWebhookProperties(mapOf("key11", "fakeTokenPlaceholder", "key12", "fakeTokenPlaceholder")))),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateDynamicMetricAlertSingleResource.json
func ExampleMetricAlertsClient_CreateOrUpdate_createOrUpdateADynamicAlertRuleForSingleResource() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewMetricAlertsClient().CreateOrUpdate(ctx, "gigtest", "chiricutin", armmonitor.MetricAlertResource{
Location: to.Ptr("global"),
Tags: map[string]*string{},
Properties: &armmonitor.MetricAlertProperties{
Description: to.Ptr("This is the description of the rule1"),
Actions: []*armmonitor.MetricAlertAction{
{
ActionGroupID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties: map[string]*string{
"key11": to.Ptr("value11"),
"key12": to.Ptr("value12"),
},
}},
AutoMitigate: to.Ptr(true),
Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
AllOf: []armmonitor.MultiMetricCriteriaClassification{
&armmonitor.DynamicMetricCriteria{
Name: to.Ptr("High_CPU_80"),
CriterionType: to.Ptr(armmonitor.CriterionTypeDynamicThresholdCriterion),
Dimensions: []*armmonitor.MetricDimension{},
MetricName: to.Ptr("Percentage CPU"),
MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
AlertSensitivity: to.Ptr(armmonitor.DynamicThresholdSensitivityMedium),
FailingPeriods: &armmonitor.DynamicThresholdFailingPeriods{
MinFailingPeriodsToAlert: to.Ptr[float32](4),
NumberOfEvaluationPeriods: to.Ptr[float32](4),
},
IgnoreDataBefore: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-04-04T21:00:00.000Z"); return t }()),
Operator: to.Ptr(armmonitor.DynamicThresholdOperatorGreaterOrLessThan),
}},
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("PT1M"),
Scopes: []*string{
to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme")},
Severity: to.Ptr[int32](3),
WindowSize: to.Ptr("PT15M"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.MetricAlertResource = armmonitor.MetricAlertResource{
// Type: to.Ptr("Microsoft.Insights/metricAlerts"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/chiricutin"),
// Location: to.Ptr("global"),
// Tags: map[string]*string{
// "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": to.Ptr("Resource"),
// },
// Properties: &armmonitor.MetricAlertProperties{
// Description: to.Ptr("This is the description of the rule1"),
// Actions: []*armmonitor.MetricAlertAction{
// {
// ActionGroupID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
// WebHookProperties: map[string]*string{
// "key11": to.Ptr("value11"),
// "key12": to.Ptr("value12"),
// },
// }},
// AutoMitigate: to.Ptr(true),
// Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
// ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
// AllOf: []armmonitor.MultiMetricCriteriaClassification{
// &armmonitor.DynamicMetricCriteria{
// Name: to.Ptr("High_CPU_80"),
// CriterionType: to.Ptr(armmonitor.CriterionTypeDynamicThresholdCriterion),
// Dimensions: []*armmonitor.MetricDimension{
// },
// MetricName: to.Ptr("Percentage CPU"),
// MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
// TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
// AlertSensitivity: to.Ptr(armmonitor.DynamicThresholdSensitivityMedium),
// FailingPeriods: &armmonitor.DynamicThresholdFailingPeriods{
// MinFailingPeriodsToAlert: to.Ptr[float32](4),
// NumberOfEvaluationPeriods: to.Ptr[float32](4),
// },
// IgnoreDataBefore: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2019-04-04T21:00:00.000Z"); return t}()),
// Operator: to.Ptr(armmonitor.DynamicThresholdOperatorGreaterOrLessThan),
// }},
// },
// Enabled: to.Ptr(true),
// EvaluationFrequency: to.Ptr("PT1M"),
// Scopes: []*string{
// to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme")},
// Severity: to.Ptr[int32](3),
// TargetResourceRegion: to.Ptr("southcentralus"),
// TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
// WindowSize: to.Ptr("PT15M"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update an metric alert definition.
*
* @summary Create or update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateDynamicMetricAlertSingleResource.json
*/
async function createOrUpdateADynamicAlertRuleForSingleResource() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "gigtest";
const ruleName = "chiricutin";
const parameters = {
description: "This is the description of the rule1",
actions: [
{
actionGroupId:
"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
webHookProperties: { key11: "value11", key12: "value12" },
},
],
autoMitigate: true,
criteria: {
allOf: [
{
name: "High_CPU_80",
alertSensitivity: "Medium",
criterionType: "DynamicThresholdCriterion",
dimensions: [],
failingPeriods: {
minFailingPeriodsToAlert: 4,
numberOfEvaluationPeriods: 4,
},
ignoreDataBefore: new Date("2019-04-04T21:00:00.000Z"),
metricName: "Percentage CPU",
metricNamespace: "microsoft.compute/virtualmachines",
operator: "GreaterOrLessThan",
timeAggregation: "Average",
},
],
odataType: "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
enabled: true,
evaluationFrequency: "PT1M",
location: "global",
scopes: [
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme",
],
severity: 3,
tags: {},
windowSize: "PT15M",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.createOrUpdate(resourceGroupName, ruleName, parameters);
console.log(result);
}
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.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/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"), XmlConvert.ToTimeSpan("PT15M"), 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",
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
Voorbeeldrespons
{
"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 web test alert rule
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/12345678-1234-1234-1234-123456789101/resourceGroups/rg-example/providers/Microsoft.Insights/metricAlerts/webtest-name-example?api-version=2018-03-01
{
"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"
]
}
}
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.WebtestLocationAvailabilityCriteria;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for MetricAlerts CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/
* createOrUpdateWebTestMetricAlert.json
*/
/**
* Sample code: Create or update a web test alert rule.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createOrUpdateAWebTestAlertRule(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getMetricAlerts().createOrUpdateWithResponse("rg-example",
"webtest-name-example",
new MetricAlertResourceInner().withLocation("global").withTags(mapOf(
"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"))
.withDescription("Automatically created alert rule for availability test \"component-example\" a")
.withSeverity(4).withEnabled(true)
.withScopes(Arrays.asList(
"/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"))
.withEvaluationFrequency(Duration.parse("PT1M")).withWindowSize(Duration.parse("PT15M"))
.withCriteria(new WebtestLocationAvailabilityCriteria().withWebTestId(
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example")
.withComponentId(
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example")
.withFailedLocationCount(2f))
.withActions(Arrays.asList()),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateWebTestMetricAlert.json
func ExampleMetricAlertsClient_CreateOrUpdate_createOrUpdateAWebTestAlertRule() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewMetricAlertsClient().CreateOrUpdate(ctx, "rg-example", "webtest-name-example", armmonitor.MetricAlertResource{
Location: to.Ptr("global"),
Tags: map[string]*string{
"hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example": to.Ptr("Resource"),
"hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example": to.Ptr("Resource"),
},
Properties: &armmonitor.MetricAlertProperties{
Description: to.Ptr("Automatically created alert rule for availability test \"component-example\" a"),
Actions: []*armmonitor.MetricAlertAction{},
Criteria: &armmonitor.WebtestLocationAvailabilityCriteria{
ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorWebtestLocationAvailabilityCriteria),
ComponentID: to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example"),
FailedLocationCount: to.Ptr[float32](2),
WebTestID: to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example"),
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("PT1M"),
Scopes: []*string{
to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example"),
to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example")},
Severity: to.Ptr[int32](4),
WindowSize: to.Ptr("PT15M"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.MetricAlertResource = armmonitor.MetricAlertResource{
// Name: to.Ptr("webtest-name-example"),
// Type: to.Ptr("Microsoft.Insights/metricAlerts"),
// ID: to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/metricalerts/webtest-name-example"),
// Location: to.Ptr("global"),
// Tags: map[string]*string{
// "hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/component-example": to.Ptr("Resource"),
// "hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/webtest-name-example": to.Ptr("Resource"),
// },
// Properties: &armmonitor.MetricAlertProperties{
// Description: to.Ptr("Automatically created alert rule for availability test \"webtest-name-example\" a"),
// Actions: []*armmonitor.MetricAlertAction{
// },
// Criteria: &armmonitor.WebtestLocationAvailabilityCriteria{
// ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorWebtestLocationAvailabilityCriteria),
// ComponentID: to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/component-example"),
// FailedLocationCount: to.Ptr[float32](2),
// WebTestID: to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/webtest-name-example"),
// },
// Enabled: to.Ptr(true),
// EvaluationFrequency: to.Ptr("PT1M"),
// Scopes: []*string{
// to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/webtest-name-example"),
// to.Ptr("/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/component-example")},
// Severity: to.Ptr[int32](4),
// WindowSize: to.Ptr("PT15M"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update an metric alert definition.
*
* @summary Create or update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateWebTestMetricAlert.json
*/
async function createOrUpdateAWebTestAlertRule() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "12345678-1234-1234-1234-123456789101";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "rg-example";
const ruleName = "webtest-name-example";
const parameters = {
description: 'Automatically created alert rule for availability test "component-example" a',
actions: [],
criteria: {
componentId:
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example",
failedLocationCount: 2,
odataType: "Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria",
webTestId:
"/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example",
},
enabled: true,
evaluationFrequency: "PT1M",
location: "global",
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,
tags: {
"hiddenLink:/subscriptions/12345678123412341234123456789101/resourcegroups/rgExample/providers/microsoftInsights/components/webtestNameExample":
"Resource",
"hiddenLink:/subscriptions/12345678123412341234123456789101/resourcegroups/rgExample/providers/microsoftInsights/webtests/componentExample":
"Resource",
},
windowSize: "PT15M",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.createOrUpdate(resourceGroupName, ruleName, parameters);
console.log(result);
}
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.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/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"), XmlConvert.ToTimeSpan("PT15M"), 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",
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
Voorbeeldrespons
{
"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
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/MetricAlertOnMultipleResources?api-version=2018-03-01
{
"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"
}
}
]
}
}
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.AggregationTypeEnum;
import com.azure.resourcemanager.monitor.models.MetricAlertAction;
import com.azure.resourcemanager.monitor.models.MetricAlertMultipleResourceMultipleMetricCriteria;
import com.azure.resourcemanager.monitor.models.MetricCriteria;
import com.azure.resourcemanager.monitor.models.Operator;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for MetricAlerts CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/
* createOrUpdateMetricAlertMultipleResource.json
*/
/**
* Sample code: Create or update an alert rule for Multiple Resource.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createOrUpdateAnAlertRuleForMultipleResource(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getMetricAlerts().createOrUpdateWithResponse("gigtest",
"MetricAlertOnMultipleResources",
new MetricAlertResourceInner().withLocation("global").withTags(mapOf())
.withDescription("This is the description of the rule1").withSeverity(3).withEnabled(true)
.withScopes(Arrays.asList(
"/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"))
.withEvaluationFrequency(Duration.parse("PT1M")).withWindowSize(Duration.parse("PT15M"))
.withTargetResourceType("Microsoft.Compute/virtualMachines").withTargetResourceRegion("southcentralus")
.withCriteria(new MetricAlertMultipleResourceMultipleMetricCriteria()
.withAllOf(Arrays.asList(new MetricCriteria().withName("High_CPU_80")
.withMetricName("Percentage CPU").withMetricNamespace("microsoft.compute/virtualmachines")
.withTimeAggregation(AggregationTypeEnum.AVERAGE).withDimensions(Arrays.asList())
.withOperator(Operator.GREATER_THAN).withThreshold(80.5))))
.withAutoMitigate(true)
.withActions(Arrays.asList(new MetricAlertAction().withActionGroupId(
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2")
.withWebhookProperties(mapOf("key11", "fakeTokenPlaceholder", "key12", "fakeTokenPlaceholder")))),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertMultipleResource.json
func ExampleMetricAlertsClient_CreateOrUpdate_createOrUpdateAnAlertRuleForMultipleResource() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewMetricAlertsClient().CreateOrUpdate(ctx, "gigtest", "MetricAlertOnMultipleResources", armmonitor.MetricAlertResource{
Location: to.Ptr("global"),
Tags: map[string]*string{},
Properties: &armmonitor.MetricAlertProperties{
Description: to.Ptr("This is the description of the rule1"),
Actions: []*armmonitor.MetricAlertAction{
{
ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties: map[string]*string{
"key11": to.Ptr("value11"),
"key12": to.Ptr("value12"),
},
}},
AutoMitigate: to.Ptr(true),
Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
AllOf: []armmonitor.MultiMetricCriteriaClassification{
&armmonitor.MetricCriteria{
Name: to.Ptr("High_CPU_80"),
CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
Dimensions: []*armmonitor.MetricDimension{},
MetricName: to.Ptr("Percentage CPU"),
MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
Operator: to.Ptr(armmonitor.OperatorGreaterThan),
Threshold: to.Ptr[float64](80.5),
}},
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("PT1M"),
Scopes: []*string{
to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1"),
to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2")},
Severity: to.Ptr[int32](3),
TargetResourceRegion: to.Ptr("southcentralus"),
TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
WindowSize: to.Ptr("PT15M"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.MetricAlertResource = armmonitor.MetricAlertResource{
// Type: to.Ptr("Microsoft.Insights/metricAlerts"),
// ID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/MetricAlertOnMultipleResources"),
// Location: to.Ptr("global"),
// Tags: map[string]*string{
// "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": to.Ptr("Resource"),
// },
// Properties: &armmonitor.MetricAlertProperties{
// Description: to.Ptr("This is the description of the rule1"),
// Actions: []*armmonitor.MetricAlertAction{
// {
// ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
// WebHookProperties: map[string]*string{
// "key11": to.Ptr("value11"),
// "key12": to.Ptr("value12"),
// },
// }},
// AutoMitigate: to.Ptr(true),
// Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
// ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
// AllOf: []armmonitor.MultiMetricCriteriaClassification{
// &armmonitor.MetricCriteria{
// Name: to.Ptr("High_CPU_80"),
// CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
// Dimensions: []*armmonitor.MetricDimension{
// },
// MetricName: to.Ptr("Percentage CPU"),
// MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
// TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
// Operator: to.Ptr(armmonitor.OperatorGreaterThan),
// Threshold: to.Ptr[float64](80.5),
// }},
// },
// Enabled: to.Ptr(true),
// EvaluationFrequency: to.Ptr("PT1M"),
// Scopes: []*string{
// to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme1"),
// to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme2")},
// Severity: to.Ptr[int32](3),
// TargetResourceRegion: to.Ptr("southcentralus"),
// TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
// WindowSize: to.Ptr("PT15M"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update an metric alert definition.
*
* @summary Create or update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertMultipleResource.json
*/
async function createOrUpdateAnAlertRuleForMultipleResource() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "gigtest";
const ruleName = "MetricAlertOnMultipleResources";
const parameters = {
description: "This is the description of the rule1",
actions: [
{
actionGroupId:
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
webHookProperties: { key11: "value11", key12: "value12" },
},
],
autoMitigate: true,
criteria: {
allOf: [
{
name: "High_CPU_80",
criterionType: "StaticThresholdCriterion",
dimensions: [],
metricName: "Percentage CPU",
metricNamespace: "microsoft.compute/virtualmachines",
operator: "GreaterThan",
threshold: 80.5,
timeAggregation: "Average",
},
],
odataType: "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
enabled: true,
evaluationFrequency: "PT1M",
location: "global",
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,
tags: {},
targetResourceRegion: "southcentralus",
targetResourceType: "Microsoft.Compute/virtualMachines",
windowSize: "PT15M",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.createOrUpdate(resourceGroupName, ruleName, parameters);
console.log(result);
}
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.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/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"), XmlConvert.ToTimeSpan("PT15M"), 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",
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
Voorbeeldrespons
{
"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
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/chiricutin?api-version=2018-03-01
{
"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"
}
}
]
}
}
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.AggregationTypeEnum;
import com.azure.resourcemanager.monitor.models.MetricAlertAction;
import com.azure.resourcemanager.monitor.models.MetricAlertSingleResourceMultipleMetricCriteria;
import com.azure.resourcemanager.monitor.models.MetricCriteria;
import com.azure.resourcemanager.monitor.models.Operator;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for MetricAlerts CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/
* createOrUpdateMetricAlertSingleResource.json
*/
/**
* Sample code: Create or update an alert rule for Single Resource.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void
createOrUpdateAnAlertRuleForSingleResource(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getMetricAlerts().createOrUpdateWithResponse("gigtest",
"chiricutin",
new MetricAlertResourceInner().withLocation("global").withTags(mapOf())
.withDescription("This is the description of the rule1").withSeverity(3).withEnabled(true)
.withScopes(Arrays.asList(
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme"))
.withEvaluationFrequency(Duration.parse("Pt1m")).withWindowSize(Duration.parse("Pt15m"))
.withCriteria(new MetricAlertSingleResourceMultipleMetricCriteria().withAllOf(Arrays.asList(
new MetricCriteria().withName("High_CPU_80").withMetricName("\\Processor(_Total)\\% Processor Time")
.withTimeAggregation(AggregationTypeEnum.AVERAGE).withDimensions(Arrays.asList())
.withOperator(Operator.GREATER_THAN).withThreshold(80.5))))
.withAutoMitigate(true)
.withActions(Arrays.asList(new MetricAlertAction().withActionGroupId(
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2")
.withWebhookProperties(mapOf("key11", "fakeTokenPlaceholder", "key12", "fakeTokenPlaceholder")))),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertSingleResource.json
func ExampleMetricAlertsClient_CreateOrUpdate_createOrUpdateAnAlertRuleForSingleResource() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewMetricAlertsClient().CreateOrUpdate(ctx, "gigtest", "chiricutin", armmonitor.MetricAlertResource{
Location: to.Ptr("global"),
Tags: map[string]*string{},
Properties: &armmonitor.MetricAlertProperties{
Description: to.Ptr("This is the description of the rule1"),
Actions: []*armmonitor.MetricAlertAction{
{
ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties: map[string]*string{
"key11": to.Ptr("value11"),
"key12": to.Ptr("value12"),
},
}},
AutoMitigate: to.Ptr(true),
Criteria: &armmonitor.MetricAlertSingleResourceMultipleMetricCriteria{
ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorSingleResourceMultipleMetricCriteria),
AllOf: []*armmonitor.MetricCriteria{
{
Name: to.Ptr("High_CPU_80"),
CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
Dimensions: []*armmonitor.MetricDimension{},
MetricName: to.Ptr("\\Processor(_Total)\\% Processor Time"),
TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
Operator: to.Ptr(armmonitor.OperatorGreaterThan),
Threshold: to.Ptr[float64](80.5),
}},
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("Pt1m"),
Scopes: []*string{
to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme")},
Severity: to.Ptr[int32](3),
WindowSize: to.Ptr("Pt15m"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.MetricAlertResource = armmonitor.MetricAlertResource{
// Type: to.Ptr("Microsoft.Insights/metricAlerts"),
// ID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/chiricutin"),
// Location: to.Ptr("global"),
// Tags: map[string]*string{
// "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": to.Ptr("Resource"),
// },
// Properties: &armmonitor.MetricAlertProperties{
// Description: to.Ptr("This is the description of the rule1"),
// Actions: []*armmonitor.MetricAlertAction{
// {
// ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
// WebHookProperties: map[string]*string{
// "key11": to.Ptr("value11"),
// "key12": to.Ptr("value12"),
// },
// }},
// AutoMitigate: to.Ptr(true),
// Criteria: &armmonitor.MetricAlertSingleResourceMultipleMetricCriteria{
// ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorSingleResourceMultipleMetricCriteria),
// AllOf: []*armmonitor.MetricCriteria{
// {
// Name: to.Ptr("High_CPU_80"),
// CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
// Dimensions: []*armmonitor.MetricDimension{
// },
// MetricName: to.Ptr("\\Processor(_Total)\\% Processor Time"),
// TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
// Operator: to.Ptr(armmonitor.OperatorGreaterThan),
// Threshold: to.Ptr[float64](80.5),
// }},
// },
// Enabled: to.Ptr(true),
// EvaluationFrequency: to.Ptr("Pt1m"),
// Scopes: []*string{
// to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme")},
// Severity: to.Ptr[int32](3),
// WindowSize: to.Ptr("Pt15m"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update an metric alert definition.
*
* @summary Create or update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertSingleResource.json
*/
async function createOrUpdateAnAlertRuleForSingleResource() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "gigtest";
const ruleName = "chiricutin";
const parameters = {
description: "This is the description of the rule1",
actions: [
{
actionGroupId:
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
webHookProperties: { key11: "value11", key12: "value12" },
},
],
autoMitigate: true,
criteria: {
allOf: [
{
name: "High_CPU_80",
criterionType: "StaticThresholdCriterion",
dimensions: [],
metricName: "\\Processor(_Total)\\% Processor Time",
operator: "GreaterThan",
threshold: 80.5,
timeAggregation: "Average",
},
],
odataType: "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
},
enabled: true,
evaluationFrequency: "Pt1m",
location: "global",
scopes: [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Compute/virtualMachines/gigwadme",
],
severity: 3,
tags: {},
windowSize: "Pt15m",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.createOrUpdate(resourceGroupName, ruleName, parameters);
console.log(result);
}
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.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/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"), XmlConvert.ToTimeSpan("Pt15m"), 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",
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
Voorbeeldrespons
{
"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)
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1/providers/Microsoft.Insights/metricAlerts/MetricAlertAtResourceGroupLevel?api-version=2018-03-01
{
"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"
}
}
]
}
}
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.AggregationTypeEnum;
import com.azure.resourcemanager.monitor.models.MetricAlertAction;
import com.azure.resourcemanager.monitor.models.MetricAlertMultipleResourceMultipleMetricCriteria;
import com.azure.resourcemanager.monitor.models.MetricCriteria;
import com.azure.resourcemanager.monitor.models.Operator;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for MetricAlerts CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/
* createOrUpdateMetricAlertResourceGroup.json
*/
/**
* Sample code: Create or update an alert rule on Resource group(s).
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createOrUpdateAnAlertRuleOnResourceGroupS(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getMetricAlerts().createOrUpdateWithResponse("gigtest1",
"MetricAlertAtResourceGroupLevel",
new MetricAlertResourceInner().withLocation("global").withTags(mapOf())
.withDescription("This is the description of the rule1").withSeverity(3).withEnabled(true)
.withScopes(Arrays.asList("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1",
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest2"))
.withEvaluationFrequency(Duration.parse("PT1M")).withWindowSize(Duration.parse("PT15M"))
.withTargetResourceType("Microsoft.Compute/virtualMachines").withTargetResourceRegion("southcentralus")
.withCriteria(new MetricAlertMultipleResourceMultipleMetricCriteria()
.withAllOf(Arrays.asList(new MetricCriteria().withName("High_CPU_80")
.withMetricName("Percentage CPU").withMetricNamespace("microsoft.compute/virtualmachines")
.withTimeAggregation(AggregationTypeEnum.AVERAGE).withDimensions(Arrays.asList())
.withOperator(Operator.GREATER_THAN).withThreshold(80.5))))
.withAutoMitigate(true)
.withActions(Arrays.asList(new MetricAlertAction().withActionGroupId(
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2")
.withWebhookProperties(mapOf("key11", "fakeTokenPlaceholder", "key12", "fakeTokenPlaceholder")))),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertResourceGroup.json
func ExampleMetricAlertsClient_CreateOrUpdate_createOrUpdateAnAlertRuleOnResourceGroupS() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewMetricAlertsClient().CreateOrUpdate(ctx, "gigtest1", "MetricAlertAtResourceGroupLevel", armmonitor.MetricAlertResource{
Location: to.Ptr("global"),
Tags: map[string]*string{},
Properties: &armmonitor.MetricAlertProperties{
Description: to.Ptr("This is the description of the rule1"),
Actions: []*armmonitor.MetricAlertAction{
{
ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties: map[string]*string{
"key11": to.Ptr("value11"),
"key12": to.Ptr("value12"),
},
}},
AutoMitigate: to.Ptr(true),
Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
AllOf: []armmonitor.MultiMetricCriteriaClassification{
&armmonitor.MetricCriteria{
Name: to.Ptr("High_CPU_80"),
CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
Dimensions: []*armmonitor.MetricDimension{},
MetricName: to.Ptr("Percentage CPU"),
MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
Operator: to.Ptr(armmonitor.OperatorGreaterThan),
Threshold: to.Ptr[float64](80.5),
}},
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("PT1M"),
Scopes: []*string{
to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1"),
to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest2")},
Severity: to.Ptr[int32](3),
TargetResourceRegion: to.Ptr("southcentralus"),
TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
WindowSize: to.Ptr("PT15M"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.MetricAlertResource = armmonitor.MetricAlertResource{
// Type: to.Ptr("Microsoft.Insights/metricAlerts"),
// ID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1/providers/providers/microsoft.insights/metricalerts/MetricAlertAtResourceGroupLevel"),
// Location: to.Ptr("global"),
// Tags: map[string]*string{
// "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": to.Ptr("Resource"),
// },
// Properties: &armmonitor.MetricAlertProperties{
// Description: to.Ptr("This is the description of the rule1"),
// Actions: []*armmonitor.MetricAlertAction{
// {
// ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
// WebHookProperties: map[string]*string{
// "key11": to.Ptr("value11"),
// "key12": to.Ptr("value12"),
// },
// }},
// AutoMitigate: to.Ptr(true),
// Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
// ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
// AllOf: []armmonitor.MultiMetricCriteriaClassification{
// &armmonitor.MetricCriteria{
// Name: to.Ptr("High_CPU_80"),
// CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
// Dimensions: []*armmonitor.MetricDimension{
// },
// MetricName: to.Ptr("Percentage CPU"),
// MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
// TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
// Operator: to.Ptr(armmonitor.OperatorGreaterThan),
// Threshold: to.Ptr[float64](80.5),
// }},
// },
// Enabled: to.Ptr(true),
// EvaluationFrequency: to.Ptr("PT1M"),
// Scopes: []*string{
// to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1"),
// to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest2")},
// Severity: to.Ptr[int32](3),
// TargetResourceRegion: to.Ptr("southcentralus"),
// TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
// WindowSize: to.Ptr("PT15M"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update an metric alert definition.
*
* @summary Create or update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertResourceGroup.json
*/
async function createOrUpdateAnAlertRuleOnResourceGroupS() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "gigtest1";
const ruleName = "MetricAlertAtResourceGroupLevel";
const parameters = {
description: "This is the description of the rule1",
actions: [
{
actionGroupId:
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
webHookProperties: { key11: "value11", key12: "value12" },
},
],
autoMitigate: true,
criteria: {
allOf: [
{
name: "High_CPU_80",
criterionType: "StaticThresholdCriterion",
dimensions: [],
metricName: "Percentage CPU",
metricNamespace: "microsoft.compute/virtualmachines",
operator: "GreaterThan",
threshold: 80.5,
timeAggregation: "Average",
},
],
odataType: "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
enabled: true,
evaluationFrequency: "PT1M",
location: "global",
scopes: [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest1",
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest2",
],
severity: 3,
tags: {},
targetResourceRegion: "southcentralus",
targetResourceType: "Microsoft.Compute/virtualMachines",
windowSize: "PT15M",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.createOrUpdate(resourceGroupName, ruleName, parameters);
console.log(result);
}
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.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/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"), XmlConvert.ToTimeSpan("PT15M"), 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",
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
Voorbeeldrespons
{
"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
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/MetricAlertAtSubscriptionLevel?api-version=2018-03-01
{
"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"
}
}
]
}
}
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.AggregationTypeEnum;
import com.azure.resourcemanager.monitor.models.MetricAlertAction;
import com.azure.resourcemanager.monitor.models.MetricAlertMultipleResourceMultipleMetricCriteria;
import com.azure.resourcemanager.monitor.models.MetricCriteria;
import com.azure.resourcemanager.monitor.models.Operator;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for MetricAlerts CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/
* createOrUpdateMetricAlertSubscription.json
*/
/**
* Sample code: Create or update an alert rule on Subscription.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createOrUpdateAnAlertRuleOnSubscription(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getMetricAlerts().createOrUpdateWithResponse("gigtest",
"MetricAlertAtSubscriptionLevel",
new MetricAlertResourceInner().withLocation("global").withTags(mapOf())
.withDescription("This is the description of the rule1").withSeverity(3).withEnabled(true)
.withScopes(Arrays.asList("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7"))
.withEvaluationFrequency(Duration.parse("PT1M")).withWindowSize(Duration.parse("PT15M"))
.withTargetResourceType("Microsoft.Compute/virtualMachines").withTargetResourceRegion("southcentralus")
.withCriteria(new MetricAlertMultipleResourceMultipleMetricCriteria()
.withAllOf(Arrays.asList(new MetricCriteria().withName("High_CPU_80")
.withMetricName("Percentage CPU").withMetricNamespace("microsoft.compute/virtualmachines")
.withTimeAggregation(AggregationTypeEnum.AVERAGE).withDimensions(Arrays.asList())
.withOperator(Operator.GREATER_THAN).withThreshold(80.5))))
.withAutoMitigate(true)
.withActions(Arrays.asList(new MetricAlertAction().withActionGroupId(
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2")
.withWebhookProperties(mapOf("key11", "fakeTokenPlaceholder", "key12", "fakeTokenPlaceholder")))),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertSubscription.json
func ExampleMetricAlertsClient_CreateOrUpdate_createOrUpdateAnAlertRuleOnSubscription() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewMetricAlertsClient().CreateOrUpdate(ctx, "gigtest", "MetricAlertAtSubscriptionLevel", armmonitor.MetricAlertResource{
Location: to.Ptr("global"),
Tags: map[string]*string{},
Properties: &armmonitor.MetricAlertProperties{
Description: to.Ptr("This is the description of the rule1"),
Actions: []*armmonitor.MetricAlertAction{
{
ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties: map[string]*string{
"key11": to.Ptr("value11"),
"key12": to.Ptr("value12"),
},
}},
AutoMitigate: to.Ptr(true),
Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
AllOf: []armmonitor.MultiMetricCriteriaClassification{
&armmonitor.MetricCriteria{
Name: to.Ptr("High_CPU_80"),
CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
Dimensions: []*armmonitor.MetricDimension{},
MetricName: to.Ptr("Percentage CPU"),
MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
Operator: to.Ptr(armmonitor.OperatorGreaterThan),
Threshold: to.Ptr[float64](80.5),
}},
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("PT1M"),
Scopes: []*string{
to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7")},
Severity: to.Ptr[int32](3),
TargetResourceRegion: to.Ptr("southcentralus"),
TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
WindowSize: to.Ptr("PT15M"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.MetricAlertResource = armmonitor.MetricAlertResource{
// Type: to.Ptr("Microsoft.Insights/metricAlerts"),
// ID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/MetricAlertAtSubscriptionLevel"),
// Location: to.Ptr("global"),
// Tags: map[string]*string{
// "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": to.Ptr("Resource"),
// },
// Properties: &armmonitor.MetricAlertProperties{
// Description: to.Ptr("This is the description of the rule1"),
// Actions: []*armmonitor.MetricAlertAction{
// {
// ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
// WebHookProperties: map[string]*string{
// "key11": to.Ptr("value11"),
// "key12": to.Ptr("value12"),
// },
// }},
// AutoMitigate: to.Ptr(true),
// Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
// ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
// AllOf: []armmonitor.MultiMetricCriteriaClassification{
// &armmonitor.MetricCriteria{
// Name: to.Ptr("High_CPU_80"),
// CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
// Dimensions: []*armmonitor.MetricDimension{
// },
// MetricName: to.Ptr("Percentage CPU"),
// MetricNamespace: to.Ptr("microsoft.compute/virtualmachines"),
// TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
// Operator: to.Ptr(armmonitor.OperatorGreaterThan),
// Threshold: to.Ptr[float64](80.5),
// }},
// },
// Enabled: to.Ptr(true),
// EvaluationFrequency: to.Ptr("PT1M"),
// Scopes: []*string{
// to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7")},
// Severity: to.Ptr[int32](3),
// TargetResourceRegion: to.Ptr("southcentralus"),
// TargetResourceType: to.Ptr("Microsoft.Compute/virtualMachines"),
// WindowSize: to.Ptr("PT15M"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update an metric alert definition.
*
* @summary Create or update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertSubscription.json
*/
async function createOrUpdateAnAlertRuleOnSubscription() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "gigtest";
const ruleName = "MetricAlertAtSubscriptionLevel";
const parameters = {
description: "This is the description of the rule1",
actions: [
{
actionGroupId:
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
webHookProperties: { key11: "value11", key12: "value12" },
},
],
autoMitigate: true,
criteria: {
allOf: [
{
name: "High_CPU_80",
criterionType: "StaticThresholdCriterion",
dimensions: [],
metricName: "Percentage CPU",
metricNamespace: "microsoft.compute/virtualmachines",
operator: "GreaterThan",
threshold: 80.5,
timeAggregation: "Average",
},
],
odataType: "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
enabled: true,
evaluationFrequency: "PT1M",
location: "global",
scopes: ["/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7"],
severity: 3,
tags: {},
targetResourceRegion: "southcentralus",
targetResourceType: "Microsoft.Compute/virtualMachines",
windowSize: "PT15M",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.createOrUpdate(resourceGroupName, ruleName, parameters);
console.log(result);
}
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.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/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"), XmlConvert.ToTimeSpan("PT15M"), 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",
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
Voorbeeldrespons
{
"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
Voorbeeldaanvraag
PUT https://management.azure.com/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.Insights/metricAlerts/MetricAlertOnMultipleDimensions?api-version=2018-03-01
{
"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
}
}
import com.azure.resourcemanager.monitor.fluent.models.MetricAlertResourceInner;
import com.azure.resourcemanager.monitor.models.AggregationTypeEnum;
import com.azure.resourcemanager.monitor.models.MetricAlertAction;
import com.azure.resourcemanager.monitor.models.MetricAlertMultipleResourceMultipleMetricCriteria;
import com.azure.resourcemanager.monitor.models.MetricCriteria;
import com.azure.resourcemanager.monitor.models.MetricDimension;
import com.azure.resourcemanager.monitor.models.Operator;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Samples for MetricAlerts CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/
* createOrUpdateMetricAlertWithDimensions.json
*/
/**
* Sample code: Create or update an alert rules with dimensions.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void createOrUpdateAnAlertRulesWithDimensions(com.azure.resourcemanager.AzureResourceManager azure) {
azure.diagnosticSettings().manager().serviceClient().getMetricAlerts().createOrUpdateWithResponse("gigtest",
"MetricAlertOnMultipleDimensions",
new MetricAlertResourceInner().withLocation("global").withTags(mapOf())
.withDescription("This is the description of the rule1").withSeverity(3).withEnabled(true)
.withScopes(Arrays.asList(
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.KeyVault/vaults/keyVaultResource"))
.withEvaluationFrequency(Duration.parse("PT1H")).withWindowSize(Duration.parse("P1D"))
.withCriteria(new MetricAlertMultipleResourceMultipleMetricCriteria()
.withAllOf(Arrays.asList(new MetricCriteria().withName("Metric1").withMetricName("Availability")
.withMetricNamespace("Microsoft.KeyVault/vaults")
.withTimeAggregation(AggregationTypeEnum.AVERAGE)
.withDimensions(Arrays.asList(
new MetricDimension().withName("ActivityName").withOperator("Include")
.withValues(Arrays.asList("*")),
new MetricDimension().withName("StatusCode").withOperator("Include")
.withValues(Arrays.asList("200"))))
.withOperator(Operator.GREATER_THAN).withThreshold(55.0))))
.withAutoMitigate(true)
.withActions(Arrays.asList(new MetricAlertAction().withActionGroupId(
"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2")
.withWebhookProperties(mapOf("key11", "fakeTokenPlaceholder", "key12", "fakeTokenPlaceholder")))),
com.azure.core.util.Context.NONE);
}
// Use "Map.of" if available
@SuppressWarnings("unchecked")
private static <T> Map<String, T> mapOf(Object... inputs) {
Map<String, T> map = new HashMap<>();
for (int i = 0; i < inputs.length; i += 2) {
String key = (String) inputs[i];
T value = (T) inputs[i + 1];
map.put(key, value);
}
return map;
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armmonitor_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/monitor/armmonitor"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/969fd0c2634fbcc1975d7abe3749330a5145a97c/specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertWithDimensions.json
func ExampleMetricAlertsClient_CreateOrUpdate_createOrUpdateAnAlertRulesWithDimensions() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armmonitor.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewMetricAlertsClient().CreateOrUpdate(ctx, "gigtest", "MetricAlertOnMultipleDimensions", armmonitor.MetricAlertResource{
Location: to.Ptr("global"),
Tags: map[string]*string{},
Properties: &armmonitor.MetricAlertProperties{
Description: to.Ptr("This is the description of the rule1"),
Actions: []*armmonitor.MetricAlertAction{
{
ActionGroupID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
WebHookProperties: map[string]*string{
"key11": to.Ptr("value11"),
"key12": to.Ptr("value12"),
},
}},
AutoMitigate: to.Ptr(true),
Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
AllOf: []armmonitor.MultiMetricCriteriaClassification{
&armmonitor.MetricCriteria{
Name: to.Ptr("Metric1"),
CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
Dimensions: []*armmonitor.MetricDimension{
{
Name: to.Ptr("ActivityName"),
Operator: to.Ptr("Include"),
Values: []*string{
to.Ptr("*")},
},
{
Name: to.Ptr("StatusCode"),
Operator: to.Ptr("Include"),
Values: []*string{
to.Ptr("200")},
}},
MetricName: to.Ptr("Availability"),
MetricNamespace: to.Ptr("Microsoft.KeyVault/vaults"),
TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
Operator: to.Ptr(armmonitor.OperatorGreaterThan),
Threshold: to.Ptr[float64](55),
}},
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("PT1H"),
Scopes: []*string{
to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.KeyVault/vaults/keyVaultResource")},
Severity: to.Ptr[int32](3),
WindowSize: to.Ptr("P1D"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.MetricAlertResource = armmonitor.MetricAlertResource{
// Type: to.Ptr("Microsoft.Insights/metricAlerts"),
// ID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/providers/microsoft.insights/metricalerts/MetricAlertWithDimensions"),
// Location: to.Ptr("global"),
// Tags: map[string]*string{
// "hidden-link:/subscriptions/b67f7fec-69fc-4974-9099-a26bd6ffeda3/resourceGroups/Rac46PostSwapRG/providers/Microsoft.Web/sites/leoalerttest": to.Ptr("Resource"),
// },
// Properties: &armmonitor.MetricAlertProperties{
// Description: to.Ptr("This is the description of the rule1"),
// Actions: []*armmonitor.MetricAlertAction{
// {
// ActionGroupID: to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2"),
// WebHookProperties: map[string]*string{
// "key11": to.Ptr("value11"),
// "key12": to.Ptr("value12"),
// },
// }},
// AutoMitigate: to.Ptr(true),
// Criteria: &armmonitor.MetricAlertMultipleResourceMultipleMetricCriteria{
// ODataType: to.Ptr(armmonitor.OdatatypeMicrosoftAzureMonitorMultipleResourceMultipleMetricCriteria),
// AllOf: []armmonitor.MultiMetricCriteriaClassification{
// &armmonitor.MetricCriteria{
// Name: to.Ptr("Metric1"),
// CriterionType: to.Ptr(armmonitor.CriterionTypeStaticThresholdCriterion),
// Dimensions: []*armmonitor.MetricDimension{
// {
// Name: to.Ptr("ActivityName"),
// Operator: to.Ptr("Include"),
// Values: []*string{
// to.Ptr("*")},
// },
// {
// Name: to.Ptr("StatusCode"),
// Operator: to.Ptr("Include"),
// Values: []*string{
// to.Ptr("200")},
// }},
// MetricName: to.Ptr("Availability"),
// MetricNamespace: to.Ptr("Microsoft.KeyVault/vaults"),
// TimeAggregation: to.Ptr(armmonitor.AggregationTypeEnumAverage),
// Operator: to.Ptr(armmonitor.OperatorGreaterThan),
// Threshold: to.Ptr[float64](55),
// }},
// },
// Enabled: to.Ptr(true),
// EvaluationFrequency: to.Ptr("PT1H"),
// Scopes: []*string{
// to.Ptr("/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.KeyVault/vaults/keyVaultResource")},
// Severity: to.Ptr[int32](3),
// TargetResourceRegion: to.Ptr("southcentralus"),
// TargetResourceType: to.Ptr("Microsoft.KeyVault/vaults"),
// WindowSize: to.Ptr("P1D"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { MonitorClient } = require("@azure/arm-monitor");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Create or update an metric alert definition.
*
* @summary Create or update an metric alert definition.
* x-ms-original-file: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/examples/createOrUpdateMetricAlertWithDimensions.json
*/
async function createOrUpdateAnAlertRulesWithDimensions() {
const subscriptionId =
process.env["MONITOR_SUBSCRIPTION_ID"] || "14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7";
const resourceGroupName = process.env["MONITOR_RESOURCE_GROUP"] || "gigtest";
const ruleName = "MetricAlertOnMultipleDimensions";
const parameters = {
description: "This is the description of the rule1",
actions: [
{
actionGroupId:
"/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/gigtest/providers/microsoft.insights/actiongroups/group2",
webHookProperties: { key11: "value11", key12: "value12" },
},
],
autoMitigate: true,
criteria: {
allOf: [
{
name: "Metric1",
criterionType: "StaticThresholdCriterion",
dimensions: [
{ name: "ActivityName", operator: "Include", values: ["*"] },
{ name: "StatusCode", operator: "Include", values: ["200"] },
],
metricName: "Availability",
metricNamespace: "Microsoft.KeyVault/vaults",
operator: "GreaterThan",
threshold: 55,
timeAggregation: "Average",
},
],
odataType: "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria",
},
enabled: true,
evaluationFrequency: "PT1H",
location: "global",
scopes: [
"/subscriptions/14ddf0c5-77c5-4b53-84f6-e1fa43ad68f7/resourceGroups/gigtest/providers/Microsoft.KeyVault/vaults/keyVaultResource",
],
severity: 3,
tags: {},
windowSize: "P1D",
};
const credential = new DefaultAzureCredential();
const client = new MonitorClient(credential, subscriptionId);
const result = await client.metricAlerts.createOrUpdate(resourceGroupName, ruleName, parameters);
console.log(result);
}
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.Monitor.Models;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager.Monitor;
// Generated from example definition: specification/monitor/resource-manager/Microsoft.Insights/stable/2018-03-01/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"), XmlConvert.ToTimeSpan("P1D"), 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",
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
Voorbeeldrespons
{
"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"
}
}
]
}
}
Definities
AggregationTypeEnum
de aggregatietypen voor criteria.
Name |
Type |
Description |
Average
|
string
|
|
Count
|
string
|
|
Maximum
|
string
|
|
Minimum
|
string
|
|
Total
|
string
|
|
DynamicMetricCriteria
Criterium voor dynamische drempelwaarde.
Name |
Type |
Description |
alertSensitivity
|
DynamicThresholdSensitivity
|
De mate van afwijking die is vereist om een waarschuwing te activeren. Dit is van invloed op hoe nauw de drempelwaarde is voor het patroon voor metrische reeksen.
|
criterionType
|
string:
DynamicThresholdCriterion
|
Hiermee geeft u het type drempelwaardecriteria op
|
dimensions
|
MetricDimension[]
|
Lijst met dimensievoorwaarden.
|
failingPeriods
|
DynamicThresholdFailingPeriods
|
Het minimale aantal schendingen dat is vereist binnen het geselecteerde tijdvenster voor lookback dat is vereist om een waarschuwing te genereren.
|
ignoreDataBefore
|
string
|
Gebruik deze optie om de datum in te stellen vanaf waarop u de metrische historische gegevens wilt leren en de dynamische drempelwaarden wilt berekenen (in ISO8601 indeling)
|
metricName
|
string
|
Naam van het metrische gegeven.
|
metricNamespace
|
string
|
Naamruimte van het metrische gegeven.
|
name
|
string
|
Naam van de criteria.
|
operator
|
DynamicThresholdOperator
|
De operator die wordt gebruikt om de metrische waarde te vergelijken met de drempelwaarde.
|
skipMetricValidation
|
boolean
|
Hiermee kunt u een waarschuwingsregel maken op basis van een aangepast metrisch gegeven dat nog niet is verzonden, door ervoor te zorgen dat de metrische validatie wordt overgeslagen.
|
timeAggregation
|
AggregationTypeEnum
|
de aggregatietypen voor criteria.
|
DynamicThresholdFailingPeriods
Het minimale aantal schendingen dat is vereist binnen het geselecteerde tijdvenster voor lookback dat is vereist om een waarschuwing te genereren.
Name |
Type |
Description |
minFailingPeriodsToAlert
|
number
|
Het aantal schendingen dat een waarschuwing moet activeren. Moet kleiner of gelijk zijn aan numberOfEvaluationPeriods.
|
numberOfEvaluationPeriods
|
number
|
Het aantal geaggregeerde lookbackpunten. Het tijdvenster voor lookback wordt berekend op basis van de aggregatiegranulariteit (windowSize) en het geselecteerde aantal geaggregeerde punten.
|
DynamicThresholdOperator
De operator die wordt gebruikt om de metrische waarde te vergelijken met de drempelwaarde.
Name |
Type |
Description |
GreaterOrLessThan
|
string
|
|
GreaterThan
|
string
|
|
LessThan
|
string
|
|
DynamicThresholdSensitivity
De mate van afwijking die is vereist om een waarschuwing te activeren. Dit is van invloed op hoe nauw de drempelwaarde is voor het patroon voor metrische reeksen.
Name |
Type |
Description |
High
|
string
|
|
Low
|
string
|
|
Medium
|
string
|
|
ErrorResponse
Beschrijft de indeling van foutreactie.
Name |
Type |
Description |
code
|
string
|
Foutcode
|
message
|
string
|
Foutbericht dat aangeeft waarom de bewerking is mislukt.
|
MetricAlertAction
Een waarschuwingsactie.
Name |
Type |
Description |
actionGroupId
|
string
|
de id van de actiegroep die moet worden gebruikt.
|
webHookProperties
|
object
|
Met dit veld kunt u aangepaste eigenschappen opgeven, die worden toegevoegd aan de nettolading van de waarschuwing die als invoer naar de webhook wordt verzonden.
|
MetricAlertMultipleResourceMultipleMetricCriteria
Hiermee geeft u de metrische waarschuwingscriteria voor meerdere resources met meerdere metrische criteria.
Name |
Type |
Description |
allOf
|
MultiMetricCriteria[]:
|
de lijst met meerdere metrische criteria voor deze 'all-of'-bewerking.
|
odata.type
|
string:
Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria
|
hiermee geeft u het type van de waarschuwingscriteria op.
|
MetricAlertResource
De resource voor metrische waarschuwingen.
Name |
Type |
Description |
id
|
string
|
Azure-resource-id
|
location
|
string
|
Resourcelocatie
|
name
|
string
|
Naam van Azure-resource
|
properties.actions
|
MetricAlertAction[]
|
de matrix met acties die worden uitgevoerd wanneer de waarschuwingsregel actief wordt en wanneer een waarschuwingsvoorwaarde is opgelost.
|
properties.autoMitigate
|
boolean
|
de vlag die aangeeft of de waarschuwing automatisch moet worden opgelost of niet. De standaardwaarde is true.
|
properties.criteria
|
MetricAlertCriteria:
|
definieert de specifieke informatie over waarschuwingscriteria.
|
properties.description
|
string
|
de beschrijving van de metrische waarschuwing die wordt opgenomen in de waarschuwings-e-mail.
|
properties.enabled
|
boolean
|
de vlag die aangeeft of de waarschuwing voor metrische gegevens is ingeschakeld.
|
properties.evaluationFrequency
|
string
|
hoe vaak de metrische waarschuwing wordt geëvalueerd, weergegeven in de ISO 8601-duurnotatie.
|
properties.isMigrated
|
boolean
|
de waarde die aangeeft of deze waarschuwingsregel wordt gemigreerd.
|
properties.lastUpdatedTime
|
string
|
De laatste keer dat de regel is bijgewerkt in ISO8601-indeling.
|
properties.scopes
|
string[]
|
de lijst met resource-id's waarop deze metrische waarschuwing is gericht.
|
properties.severity
|
integer
|
Ernst van waarschuwing {0, 1, 2, 3, 4}
|
properties.targetResourceRegion
|
string
|
de regio van de doelresource(s) waarop de waarschuwing wordt gemaakt/bijgewerkt. Verplicht als het bereik een abonnement, resourcegroep of meer dan één resource bevat.
|
properties.targetResourceType
|
string
|
het resourcetype van de doelresource(s) waarop de waarschuwing wordt gemaakt/bijgewerkt. Verplicht als het bereik een abonnement, resourcegroep of meer dan één resource bevat.
|
properties.windowSize
|
string
|
de periode (in iso 8601-duurnotatie) die wordt gebruikt voor het bewaken van waarschuwingsactiviteiten op basis van de drempelwaarde.
|
tags
|
object
|
Resourcetags
|
type
|
string
|
Azure-resourcetype
|
MetricAlertSingleResourceMultipleMetricCriteria
Hiermee geeft u de metrische waarschuwingscriteria voor één resource met meerdere metrische criteria.
Name |
Type |
Description |
allOf
|
MetricCriteria[]
|
De lijst met metrische criteria voor deze 'all-of'-bewerking.
|
odata.type
|
string:
Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria
|
hiermee geeft u het type van de waarschuwingscriteria op.
|
MetricCriteria
Criterium voor het filteren van metrische gegevens.
Name |
Type |
Description |
criterionType
|
string:
StaticThresholdCriterion
|
Hiermee geeft u het type drempelwaardecriteria op
|
dimensions
|
MetricDimension[]
|
Lijst met dimensievoorwaarden.
|
metricName
|
string
|
Naam van het metrische gegeven.
|
metricNamespace
|
string
|
Naamruimte van het metrische gegeven.
|
name
|
string
|
Naam van de criteria.
|
operator
|
Operator
|
de criteriumoperator.
|
skipMetricValidation
|
boolean
|
Hiermee kunt u een waarschuwingsregel maken op basis van een aangepast metrisch gegeven dat nog niet is verzonden, door ervoor te zorgen dat de metrische validatie wordt overgeslagen.
|
threshold
|
number
|
de drempelwaarde voor criteria waarmee de waarschuwing wordt geactiveerd.
|
timeAggregation
|
AggregationTypeEnum
|
de aggregatietypen voor criteria.
|
MetricDimension
Hiermee geeft u een metrische dimensie op.
Name |
Type |
Description |
name
|
string
|
Naam van de dimensie.
|
operator
|
string
|
de dimensieoperator. Alleen 'Opnemen' en 'Uitsluiten' worden ondersteund
|
values
|
string[]
|
lijst met dimensiewaarden.
|
Operator
de criteriumoperator.
Name |
Type |
Description |
Equals
|
string
|
|
GreaterThan
|
string
|
|
GreaterThanOrEqual
|
string
|
|
LessThan
|
string
|
|
LessThanOrEqual
|
string
|
|
WebtestLocationAvailabilityCriteria
Hiermee geeft u de metrische waarschuwingsregelcriteria voor een webtestresource op.
Name |
Type |
Description |
componentId
|
string
|
De Application Insights-resource-id.
|
failedLocationCount
|
number
|
Het aantal mislukte locaties.
|
odata.type
|
string:
Microsoft.Azure.Monitor.WebtestLocationAvailabilityCriteria
|
hiermee geeft u het type van de waarschuwingscriteria op.
|
webTestId
|
string
|
De webtest-id van Application Insights.
|