Creare o aggiornare una regola di elaborazione degli avvisi.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement/actionRules/{alertProcessingRuleName}?api-version=2021-08-08
Parametri dell'URI
Nome |
In |
Necessario |
Tipo |
Descrizione |
alertProcessingRuleName
|
path |
True
|
string
|
Nome della regola di elaborazione degli avvisi che deve essere creata/aggiornata.
|
resourceGroupName
|
path |
True
|
string
|
Nome del gruppo di risorse in cui viene creata la risorsa.
|
subscriptionId
|
path |
True
|
string
|
ID della sottoscrizione di destinazione.
|
api-version
|
query |
True
|
api-version
|
Versione API client.
|
Corpo della richiesta
Nome |
Necessario |
Tipo |
Descrizione |
location
|
True
|
string
|
Posizione risorsa
|
properties
|
|
AlertProcessingRuleProperties
|
Proprietà della regola di elaborazione degli avvisi.
|
tags
|
|
object
|
Tag delle risorse
|
Risposte
Nome |
Tipo |
Descrizione |
200 OK
|
AlertProcessingRule
|
OK. Restituisce la regola di elaborazione degli avvisi aggiornata.
Headers
x-ms-request-id: string
|
201 Created
|
AlertProcessingRule
|
Creazione riuscita. Restituisce la regola di elaborazione degli avvisi creata.
Headers
x-ms-request-id: string
|
Other Status Codes
|
errorResponse
|
Risposta di errore che descrive perché l'operazione non è riuscita.
|
Esempio
Create or update a rule that adds an action group to all alerts in a subscription
Sample Request
PUT https://management.azure.com/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/AddActionGroupToSubscription?api-version=2021-08-08
{
"location": "Global",
"tags": {},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"actions": [
{
"actionType": "AddActionGroups",
"actionGroupIds": [
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/ActionGroup1"
]
}
],
"description": "Add ActionGroup1 to all alerts in the subscription",
"enabled": true
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.alertsmanagement import AlertsManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-alertsmanagement
# USAGE
python alert_processing_rules_create_or_update_add_action_group_all_alerts_in_subscription.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AlertsManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId1",
)
response = client.alert_processing_rules.create_or_update(
resource_group_name="alertscorrelationrg",
alert_processing_rule_name="AddActionGroupToSubscription",
alert_processing_rule={
"location": "Global",
"properties": {
"actions": [
{
"actionGroupIds": [
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/ActionGroup1"
],
"actionType": "AddActionGroups",
}
],
"description": "Add ActionGroup1 to all alerts in the subscription",
"enabled": True,
"scopes": ["/subscriptions/subId1"],
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_add_action_group_all_alerts_in_subscription.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armalertsmanagement_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/alertsmanagement/armalertsmanagement"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/6d2438481021a94793b07b226df06d5f3c61d51d/specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_add_action_group_all_alerts_in_subscription.json
func ExampleAlertProcessingRulesClient_CreateOrUpdate_createOrUpdateARuleThatAddsAnActionGroupToAllAlertsInASubscription() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armalertsmanagement.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewAlertProcessingRulesClient().CreateOrUpdate(ctx, "alertscorrelationrg", "AddActionGroupToSubscription", armalertsmanagement.AlertProcessingRule{
Location: to.Ptr("Global"),
Tags: map[string]*string{},
Properties: &armalertsmanagement.AlertProcessingRuleProperties{
Description: to.Ptr("Add ActionGroup1 to all alerts in the subscription"),
Actions: []armalertsmanagement.ActionClassification{
&armalertsmanagement.AddActionGroups{
ActionType: to.Ptr(armalertsmanagement.ActionTypeAddActionGroups),
ActionGroupIDs: []*string{
to.Ptr("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/ActionGroup1")},
}},
Enabled: to.Ptr(true),
Scopes: []*string{
to.Ptr("/subscriptions/subId1")},
},
}, 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.AlertProcessingRule = armalertsmanagement.AlertProcessingRule{
// Name: to.Ptr("AddActionGroupToSubscription"),
// Type: to.Ptr("Microsoft.AlertsManagement/actionRules"),
// ID: to.Ptr("/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/AddActionGroupToSubscription"),
// Location: to.Ptr("Global"),
// Tags: map[string]*string{
// },
// Properties: &armalertsmanagement.AlertProcessingRuleProperties{
// Description: to.Ptr("Add ActionGroup1 to all alerts in the subscription"),
// Actions: []armalertsmanagement.ActionClassification{
// &armalertsmanagement.AddActionGroups{
// ActionType: to.Ptr(armalertsmanagement.ActionTypeAddActionGroups),
// ActionGroupIDs: []*string{
// to.Ptr("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/ActionGroup1")},
// }},
// Enabled: to.Ptr(true),
// Scopes: []*string{
// to.Ptr("/subscriptions/subId1")},
// },
// SystemData: &armalertsmanagement.SystemData{
// CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-02-12T22:05:09.000Z"); return t}()),
// CreatedBy: to.Ptr("abc@microsoft.com"),
// CreatedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-02-13T16:15:34.000Z"); return t}()),
// LastModifiedBy: to.Ptr("xyz@microsoft.com"),
// LastModifiedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.AlertsManagement;
using Azure.ResourceManager.AlertsManagement.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_add_action_group_all_alerts_in_subscription.json
// this example is just showing the usage of "AlertProcessingRules_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 = "subId1";
string resourceGroupName = "alertscorrelationrg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this AlertProcessingRuleResource
AlertProcessingRuleCollection collection = resourceGroupResource.GetAlertProcessingRules();
// invoke the operation
string alertProcessingRuleName = "AddActionGroupToSubscription";
AlertProcessingRuleData data = new AlertProcessingRuleData(new AzureLocation("Global"))
{
Properties = new AlertProcessingRuleProperties(new string[]
{
"/subscriptions/subId1"
}, new AlertProcessingRuleAction[]
{
new AlertProcessingRuleAddGroupsAction(new ResourceIdentifier[]
{
new ResourceIdentifier("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/ActionGroup1")
})
})
{
Description = "Add ActionGroup1 to all alerts in the subscription",
IsEnabled = true,
},
Tags =
{
},
};
ArmOperation<AlertProcessingRuleResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, alertProcessingRuleName, data);
AlertProcessingRuleResource 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
AlertProcessingRuleData 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
Sample Response
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2021-02-12T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2021-02-13T16:15:34Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"actions": [
{
"actionType": "AddActionGroups",
"actionGroupIds": [
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/ActionGroup1"
]
}
],
"description": "Add ActionGroup1 to all alerts in the subscription",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/AddActionGroupToSubscription",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "AddActionGroupToSubscription",
"location": "Global",
"tags": {}
}
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2021-02-12T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2021-02-13T16:15:34Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"actions": [
{
"actionType": "AddActionGroups",
"actionGroupIds": [
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/ActionGroup1"
]
}
],
"description": "Add ActionGroup1 to all alerts in the subscription",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/AddActionGroupToSubscription",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "AddActionGroupToSubscription",
"location": "Global",
"tags": {}
}
Create or update a rule that adds two action groups to all Sev0 and Sev1 alerts in two resource groups
Sample Request
PUT https://management.azure.com/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/AddActionGroupsBySeverity?api-version=2021-08-08
{
"location": "Global",
"tags": {},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1",
"/subscriptions/subId1/resourceGroups/RGId2"
],
"conditions": [
{
"field": "Severity",
"operator": "Equals",
"values": [
"sev0",
"sev1"
]
}
],
"actions": [
{
"actionType": "AddActionGroups",
"actionGroupIds": [
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId1",
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId2"
]
}
],
"description": "Add AGId1 and AGId2 to all Sev0 and Sev1 alerts in these resourceGroups",
"enabled": true
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.alertsmanagement import AlertsManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-alertsmanagement
# USAGE
python alert_processing_rules_create_or_update_add_two_action_groups_all_sev0_sev1_two_resource_groups.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AlertsManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId1",
)
response = client.alert_processing_rules.create_or_update(
resource_group_name="alertscorrelationrg",
alert_processing_rule_name="AddActionGroupsBySeverity",
alert_processing_rule={
"location": "Global",
"properties": {
"actions": [
{
"actionGroupIds": [
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId1",
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId2",
],
"actionType": "AddActionGroups",
}
],
"conditions": [{"field": "Severity", "operator": "Equals", "values": ["sev0", "sev1"]}],
"description": "Add AGId1 and AGId2 to all Sev0 and Sev1 alerts in these resourceGroups",
"enabled": True,
"scopes": ["/subscriptions/subId1/resourceGroups/RGId1", "/subscriptions/subId1/resourceGroups/RGId2"],
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_add_two_action_groups_all_Sev0_Sev1_two_resource_groups.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armalertsmanagement_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/alertsmanagement/armalertsmanagement"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/6d2438481021a94793b07b226df06d5f3c61d51d/specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_add_two_action_groups_all_Sev0_Sev1_two_resource_groups.json
func ExampleAlertProcessingRulesClient_CreateOrUpdate_createOrUpdateARuleThatAddsTwoActionGroupsToAllSev0AndSev1AlertsInTwoResourceGroups() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armalertsmanagement.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewAlertProcessingRulesClient().CreateOrUpdate(ctx, "alertscorrelationrg", "AddActionGroupsBySeverity", armalertsmanagement.AlertProcessingRule{
Location: to.Ptr("Global"),
Tags: map[string]*string{},
Properties: &armalertsmanagement.AlertProcessingRuleProperties{
Description: to.Ptr("Add AGId1 and AGId2 to all Sev0 and Sev1 alerts in these resourceGroups"),
Actions: []armalertsmanagement.ActionClassification{
&armalertsmanagement.AddActionGroups{
ActionType: to.Ptr(armalertsmanagement.ActionTypeAddActionGroups),
ActionGroupIDs: []*string{
to.Ptr("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId1"),
to.Ptr("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId2")},
}},
Conditions: []*armalertsmanagement.Condition{
{
Field: to.Ptr(armalertsmanagement.FieldSeverity),
Operator: to.Ptr(armalertsmanagement.OperatorEquals),
Values: []*string{
to.Ptr("sev0"),
to.Ptr("sev1")},
}},
Enabled: to.Ptr(true),
Scopes: []*string{
to.Ptr("/subscriptions/subId1/resourceGroups/RGId1"),
to.Ptr("/subscriptions/subId1/resourceGroups/RGId2")},
},
}, 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.AlertProcessingRule = armalertsmanagement.AlertProcessingRule{
// Name: to.Ptr("AddActionGroupsBySeverity"),
// Type: to.Ptr("Microsoft.AlertsManagement/actionRules"),
// ID: to.Ptr("/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/AddActionGroupsBySeverity"),
// Location: to.Ptr("Global"),
// Tags: map[string]*string{
// },
// Properties: &armalertsmanagement.AlertProcessingRuleProperties{
// Description: to.Ptr("Add AGId1 and AGId2 to all Sev0 and Sev1 alerts in these resourceGroups"),
// Actions: []armalertsmanagement.ActionClassification{
// &armalertsmanagement.AddActionGroups{
// ActionType: to.Ptr(armalertsmanagement.ActionTypeAddActionGroups),
// ActionGroupIDs: []*string{
// to.Ptr("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId1"),
// to.Ptr("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId2")},
// }},
// Conditions: []*armalertsmanagement.Condition{
// {
// Field: to.Ptr(armalertsmanagement.FieldSeverity),
// Operator: to.Ptr(armalertsmanagement.OperatorEquals),
// Values: []*string{
// to.Ptr("sev0"),
// to.Ptr("sev1")},
// }},
// Enabled: to.Ptr(true),
// Scopes: []*string{
// to.Ptr("/subscriptions/subId1/resourceGroups/RGId1"),
// to.Ptr("/subscriptions/subId1/resourceGroups/RGId2")},
// },
// SystemData: &armalertsmanagement.SystemData{
// CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-12T22:05:09.000Z"); return t}()),
// CreatedBy: to.Ptr("abc@microsoft.com"),
// CreatedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-13T22:05:09.000Z"); return t}()),
// LastModifiedBy: to.Ptr("xyz@microsoft.com"),
// LastModifiedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.AlertsManagement;
using Azure.ResourceManager.AlertsManagement.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_add_two_action_groups_all_Sev0_Sev1_two_resource_groups.json
// this example is just showing the usage of "AlertProcessingRules_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 = "subId1";
string resourceGroupName = "alertscorrelationrg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this AlertProcessingRuleResource
AlertProcessingRuleCollection collection = resourceGroupResource.GetAlertProcessingRules();
// invoke the operation
string alertProcessingRuleName = "AddActionGroupsBySeverity";
AlertProcessingRuleData data = new AlertProcessingRuleData(new AzureLocation("Global"))
{
Properties = new AlertProcessingRuleProperties(new string[]
{
"/subscriptions/subId1/resourceGroups/RGId1","/subscriptions/subId1/resourceGroups/RGId2"
}, new AlertProcessingRuleAction[]
{
new AlertProcessingRuleAddGroupsAction(new ResourceIdentifier[]
{
new ResourceIdentifier("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId1"),new ResourceIdentifier("/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId2")
})
})
{
Conditions =
{
new AlertProcessingRuleCondition()
{
Field = AlertProcessingRuleField.Severity,
Operator = AlertProcessingRuleOperator.EqualsValue,
Values =
{
"sev0","sev1"
},
}
},
Description = "Add AGId1 and AGId2 to all Sev0 and Sev1 alerts in these resourceGroups",
IsEnabled = true,
},
Tags =
{
},
};
ArmOperation<AlertProcessingRuleResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, alertProcessingRuleName, data);
AlertProcessingRuleResource 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
AlertProcessingRuleData 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
Sample Response
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-12T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-13T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1",
"/subscriptions/subId1/resourceGroups/RGId2"
],
"conditions": [
{
"field": "Severity",
"operator": "Equals",
"values": [
"sev0",
"sev1"
]
}
],
"actions": [
{
"actionType": "AddActionGroups",
"actionGroupIds": [
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId1",
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId2"
]
}
],
"description": "Add AGId1 and AGId2 to all Sev0 and Sev1 alerts in these resourceGroups",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/AddActionGroupsBySeverity",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "AddActionGroupsBySeverity",
"location": "Global",
"tags": {}
}
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-12T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-13T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1",
"/subscriptions/subId1/resourceGroups/RGId2"
],
"conditions": [
{
"field": "Severity",
"operator": "Equals",
"values": [
"sev0",
"sev1"
]
}
],
"actions": [
{
"actionType": "AddActionGroups",
"actionGroupIds": [
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId1",
"/subscriptions/subId1/resourcegroups/RGId1/providers/microsoft.insights/actiongroups/AGId2"
]
}
],
"description": "Add AGId1 and AGId2 to all Sev0 and Sev1 alerts in these resourceGroups",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/AddActionGroupsBySeverity",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "AddActionGroupsBySeverity",
"location": "Global",
"tags": {}
}
Create or update a rule that removes all action groups from alerts on a specific VM during a one-off maintenance window (1800-2000 at a specific date, Pacific Standard Time)
Sample Request
PUT https://management.azure.com/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsMaintenanceWindow?api-version=2021-08-08
{
"location": "Global",
"tags": {},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1/providers/Microsoft.Compute/virtualMachines/VMName"
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"effectiveFrom": "2021-04-15T18:00:00",
"effectiveUntil": "2021-04-15T20:00:00",
"timeZone": "Pacific Standard Time"
},
"description": "Removes all ActionGroups from all Alerts on VMName during the maintenance window",
"enabled": true
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.alertsmanagement import AlertsManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-alertsmanagement
# USAGE
python alert_processing_rules_create_or_update_remove_all_action_groups_specific_vm_oneoff_maintenance_window.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AlertsManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId1",
)
response = client.alert_processing_rules.create_or_update(
resource_group_name="alertscorrelationrg",
alert_processing_rule_name="RemoveActionGroupsMaintenanceWindow",
alert_processing_rule={
"location": "Global",
"properties": {
"actions": [{"actionType": "RemoveAllActionGroups"}],
"description": "Removes all ActionGroups from all Alerts on VMName during the maintenance window",
"enabled": True,
"schedule": {
"effectiveFrom": "2021-04-15T18:00:00",
"effectiveUntil": "2021-04-15T20:00:00",
"timeZone": "Pacific Standard Time",
},
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1/providers/Microsoft.Compute/virtualMachines/VMName"
],
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_specific_VM_one-off_maintenance_window.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armalertsmanagement_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/alertsmanagement/armalertsmanagement"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/6d2438481021a94793b07b226df06d5f3c61d51d/specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_specific_VM_one-off_maintenance_window.json
func ExampleAlertProcessingRulesClient_CreateOrUpdate_createOrUpdateARuleThatRemovesAllActionGroupsFromAlertsOnASpecificVmDuringAOneOffMaintenanceWindow18002000AtASpecificDatePacificStandardTime() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armalertsmanagement.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewAlertProcessingRulesClient().CreateOrUpdate(ctx, "alertscorrelationrg", "RemoveActionGroupsMaintenanceWindow", armalertsmanagement.AlertProcessingRule{
Location: to.Ptr("Global"),
Tags: map[string]*string{},
Properties: &armalertsmanagement.AlertProcessingRuleProperties{
Description: to.Ptr("Removes all ActionGroups from all Alerts on VMName during the maintenance window"),
Actions: []armalertsmanagement.ActionClassification{
&armalertsmanagement.RemoveAllActionGroups{
ActionType: to.Ptr(armalertsmanagement.ActionTypeRemoveAllActionGroups),
}},
Enabled: to.Ptr(true),
Schedule: &armalertsmanagement.Schedule{
EffectiveFrom: to.Ptr("2021-04-15T18:00:00"),
EffectiveUntil: to.Ptr("2021-04-15T20:00:00"),
TimeZone: to.Ptr("Pacific Standard Time"),
},
Scopes: []*string{
to.Ptr("/subscriptions/subId1/resourceGroups/RGId1/providers/Microsoft.Compute/virtualMachines/VMName")},
},
}, 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.AlertProcessingRule = armalertsmanagement.AlertProcessingRule{
// Name: to.Ptr("RemoveActionGroupsMaintenanceWindow"),
// Type: to.Ptr("Microsoft.AlertsManagement/actionRules"),
// ID: to.Ptr("/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsMaintenanceWindow"),
// Location: to.Ptr("Global"),
// Tags: map[string]*string{
// },
// Properties: &armalertsmanagement.AlertProcessingRuleProperties{
// Description: to.Ptr("Removes all ActionGroups from all Alerts on VMName during the maintenance window"),
// Actions: []armalertsmanagement.ActionClassification{
// &armalertsmanagement.RemoveAllActionGroups{
// ActionType: to.Ptr(armalertsmanagement.ActionTypeRemoveAllActionGroups),
// }},
// Enabled: to.Ptr(true),
// Schedule: &armalertsmanagement.Schedule{
// EffectiveFrom: to.Ptr("2021-04-15T18:00:00"),
// EffectiveUntil: to.Ptr("2021-04-15T20:00:00"),
// TimeZone: to.Ptr("Pacific Standard Time"),
// },
// Scopes: []*string{
// to.Ptr("/subscriptions/subId1/resourceGroups/RGId1/providers/Microsoft.Compute/virtualMachines/VMName")},
// },
// SystemData: &armalertsmanagement.SystemData{
// CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-12T20:13:29.000Z"); return t}()),
// CreatedBy: to.Ptr("abc@microsoft.com"),
// CreatedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-12T22:05:09.000Z"); return t}()),
// LastModifiedBy: to.Ptr("xyz@microsoft.com"),
// LastModifiedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.AlertsManagement;
using Azure.ResourceManager.AlertsManagement.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_specific_VM_one-off_maintenance_window.json
// this example is just showing the usage of "AlertProcessingRules_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 = "subId1";
string resourceGroupName = "alertscorrelationrg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this AlertProcessingRuleResource
AlertProcessingRuleCollection collection = resourceGroupResource.GetAlertProcessingRules();
// invoke the operation
string alertProcessingRuleName = "RemoveActionGroupsMaintenanceWindow";
AlertProcessingRuleData data = new AlertProcessingRuleData(new AzureLocation("Global"))
{
Properties = new AlertProcessingRuleProperties(new string[]
{
"/subscriptions/subId1/resourceGroups/RGId1/providers/Microsoft.Compute/virtualMachines/VMName"
}, new AlertProcessingRuleAction[]
{
new AlertProcessingRuleRemoveAllGroupsAction()
})
{
Schedule = new AlertProcessingRuleSchedule()
{
EffectiveFrom = DateTimeOffset.Parse("2021-04-15T18:00:00"),
EffectiveUntil = DateTimeOffset.Parse("2021-04-15T20:00:00"),
TimeZone = "Pacific Standard Time",
},
Description = "Removes all ActionGroups from all Alerts on VMName during the maintenance window",
IsEnabled = true,
},
Tags =
{
},
};
ArmOperation<AlertProcessingRuleResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, alertProcessingRuleName, data);
AlertProcessingRuleResource 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
AlertProcessingRuleData 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
Sample Response
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-12T20:13:29Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-12T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1/providers/Microsoft.Compute/virtualMachines/VMName"
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"effectiveFrom": "2021-04-15T18:00:00",
"effectiveUntil": "2021-04-15T20:00:00",
"timeZone": "Pacific Standard Time"
},
"description": "Removes all ActionGroups from all Alerts on VMName during the maintenance window",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsMaintenanceWindow",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "RemoveActionGroupsMaintenanceWindow",
"location": "Global",
"tags": {}
}
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-12T20:13:29Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-12T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1/providers/Microsoft.Compute/virtualMachines/VMName"
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"effectiveFrom": "2021-04-15T18:00:00",
"effectiveUntil": "2021-04-15T20:00:00",
"timeZone": "Pacific Standard Time"
},
"description": "Removes all ActionGroups from all Alerts on VMName during the maintenance window",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsMaintenanceWindow",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "RemoveActionGroupsMaintenanceWindow",
"location": "Global",
"tags": {}
}
Create or update a rule that removes all action groups from all alerts in a subscription coming from a specific alert rule
Sample Request
PUT https://management.azure.com/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsSpecificAlertRule?api-version=2021-08-08
{
"location": "Global",
"tags": {},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"conditions": [
{
"field": "AlertRuleId",
"operator": "Equals",
"values": [
"/subscriptions/suubId1/resourceGroups/Rgid2/providers/microsoft.insights/activityLogAlerts/RuleName"
]
}
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"description": "Removes all ActionGroups from all Alerts that fire on above AlertRule",
"enabled": true
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.alertsmanagement import AlertsManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-alertsmanagement
# USAGE
python alert_processing_rules_create_or_update_remove_all_action_groups_from_specific_alert_rule.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AlertsManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId1",
)
response = client.alert_processing_rules.create_or_update(
resource_group_name="alertscorrelationrg",
alert_processing_rule_name="RemoveActionGroupsSpecificAlertRule",
alert_processing_rule={
"location": "Global",
"properties": {
"actions": [{"actionType": "RemoveAllActionGroups"}],
"conditions": [
{
"field": "AlertRuleId",
"operator": "Equals",
"values": [
"/subscriptions/suubId1/resourceGroups/Rgid2/providers/microsoft.insights/activityLogAlerts/RuleName"
],
}
],
"description": "Removes all ActionGroups from all Alerts that fire on above AlertRule",
"enabled": True,
"scopes": ["/subscriptions/subId1"],
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_from_specific_alert_rule.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armalertsmanagement_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/alertsmanagement/armalertsmanagement"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/6d2438481021a94793b07b226df06d5f3c61d51d/specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_from_specific_alert_rule.json
func ExampleAlertProcessingRulesClient_CreateOrUpdate_createOrUpdateARuleThatRemovesAllActionGroupsFromAllAlertsInASubscriptionComingFromASpecificAlertRule() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armalertsmanagement.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewAlertProcessingRulesClient().CreateOrUpdate(ctx, "alertscorrelationrg", "RemoveActionGroupsSpecificAlertRule", armalertsmanagement.AlertProcessingRule{
Location: to.Ptr("Global"),
Tags: map[string]*string{},
Properties: &armalertsmanagement.AlertProcessingRuleProperties{
Description: to.Ptr("Removes all ActionGroups from all Alerts that fire on above AlertRule"),
Actions: []armalertsmanagement.ActionClassification{
&armalertsmanagement.RemoveAllActionGroups{
ActionType: to.Ptr(armalertsmanagement.ActionTypeRemoveAllActionGroups),
}},
Conditions: []*armalertsmanagement.Condition{
{
Field: to.Ptr(armalertsmanagement.FieldAlertRuleID),
Operator: to.Ptr(armalertsmanagement.OperatorEquals),
Values: []*string{
to.Ptr("/subscriptions/suubId1/resourceGroups/Rgid2/providers/microsoft.insights/activityLogAlerts/RuleName")},
}},
Enabled: to.Ptr(true),
Scopes: []*string{
to.Ptr("/subscriptions/subId1")},
},
}, 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.AlertProcessingRule = armalertsmanagement.AlertProcessingRule{
// Name: to.Ptr("RemoveActionGroupsSpecificAlertRule"),
// Type: to.Ptr("Microsoft.AlertsManagement/actionRules"),
// ID: to.Ptr("/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsSpecificAlertRule"),
// Location: to.Ptr("Global"),
// Tags: map[string]*string{
// },
// Properties: &armalertsmanagement.AlertProcessingRuleProperties{
// Description: to.Ptr("Removes all ActionGroups from all Alerts that fire on above AlertRule"),
// Actions: []armalertsmanagement.ActionClassification{
// &armalertsmanagement.RemoveAllActionGroups{
// ActionType: to.Ptr(armalertsmanagement.ActionTypeRemoveAllActionGroups),
// }},
// Conditions: []*armalertsmanagement.Condition{
// {
// Field: to.Ptr(armalertsmanagement.FieldAlertRuleID),
// Operator: to.Ptr(armalertsmanagement.OperatorEquals),
// Values: []*string{
// to.Ptr("/subscriptions/suubId1/resourceGroups/Rgid2/providers/microsoft.insights/activityLogAlerts/RuleName")},
// }},
// Enabled: to.Ptr(true),
// Scopes: []*string{
// to.Ptr("/subscriptions/subId1")},
// },
// SystemData: &armalertsmanagement.SystemData{
// CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-11T22:05:09.000Z"); return t}()),
// CreatedBy: to.Ptr("abc@microsoft.com"),
// CreatedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-12T22:05:09.000Z"); return t}()),
// LastModifiedBy: to.Ptr("xyz@microsoft.com"),
// LastModifiedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.AlertsManagement;
using Azure.ResourceManager.AlertsManagement.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_from_specific_alert_rule.json
// this example is just showing the usage of "AlertProcessingRules_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 = "subId1";
string resourceGroupName = "alertscorrelationrg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this AlertProcessingRuleResource
AlertProcessingRuleCollection collection = resourceGroupResource.GetAlertProcessingRules();
// invoke the operation
string alertProcessingRuleName = "RemoveActionGroupsSpecificAlertRule";
AlertProcessingRuleData data = new AlertProcessingRuleData(new AzureLocation("Global"))
{
Properties = new AlertProcessingRuleProperties(new string[]
{
"/subscriptions/subId1"
}, new AlertProcessingRuleAction[]
{
new AlertProcessingRuleRemoveAllGroupsAction()
})
{
Conditions =
{
new AlertProcessingRuleCondition()
{
Field = AlertProcessingRuleField.AlertRuleId,
Operator = AlertProcessingRuleOperator.EqualsValue,
Values =
{
"/subscriptions/suubId1/resourceGroups/Rgid2/providers/microsoft.insights/activityLogAlerts/RuleName"
},
}
},
Description = "Removes all ActionGroups from all Alerts that fire on above AlertRule",
IsEnabled = true,
},
Tags =
{
},
};
ArmOperation<AlertProcessingRuleResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, alertProcessingRuleName, data);
AlertProcessingRuleResource 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
AlertProcessingRuleData 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
Sample Response
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-11T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-12T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"conditions": [
{
"field": "AlertRuleId",
"operator": "Equals",
"values": [
"/subscriptions/suubId1/resourceGroups/Rgid2/providers/microsoft.insights/activityLogAlerts/RuleName"
]
}
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"description": "Removes all ActionGroups from all Alerts that fire on above AlertRule",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsSpecificAlertRule",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "RemoveActionGroupsSpecificAlertRule",
"location": "Global",
"tags": {}
}
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-11T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-12T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"conditions": [
{
"field": "AlertRuleId",
"operator": "Equals",
"values": [
"/subscriptions/suubId1/resourceGroups/Rgid2/providers/microsoft.insights/activityLogAlerts/RuleName"
]
}
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"description": "Removes all ActionGroups from all Alerts that fire on above AlertRule",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsSpecificAlertRule",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "RemoveActionGroupsSpecificAlertRule",
"location": "Global",
"tags": {}
}
Create or update a rule that removes all action groups from all alerts on any VM in two resource groups during a recurring maintenance window (2200-0400 every Sat and Sun, India Standard Time)
Sample Request
PUT https://management.azure.com/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsRecurringMaintenance?api-version=2021-08-08
{
"location": "Global",
"tags": {},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1",
"/subscriptions/subId1/resourceGroups/RGId2"
],
"conditions": [
{
"field": "TargetResourceType",
"operator": "Equals",
"values": [
"microsoft.compute/virtualmachines"
]
}
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"timeZone": "India Standard Time",
"recurrences": [
{
"recurrenceType": "Weekly",
"startTime": "22:00:00",
"endTime": "04:00:00",
"daysOfWeek": [
"Saturday",
"Sunday"
]
}
]
},
"description": "Remove all ActionGroups from all Vitual machine Alerts during the recurring maintenance",
"enabled": true
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.alertsmanagement import AlertsManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-alertsmanagement
# USAGE
python alert_processing_rules_create_or_update_remove_all_action_groups_recurring_maintenance_window.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AlertsManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId1",
)
response = client.alert_processing_rules.create_or_update(
resource_group_name="alertscorrelationrg",
alert_processing_rule_name="RemoveActionGroupsRecurringMaintenance",
alert_processing_rule={
"location": "Global",
"properties": {
"actions": [{"actionType": "RemoveAllActionGroups"}],
"conditions": [
{
"field": "TargetResourceType",
"operator": "Equals",
"values": ["microsoft.compute/virtualmachines"],
}
],
"description": "Remove all ActionGroups from all Vitual machine Alerts during the recurring maintenance",
"enabled": True,
"schedule": {
"recurrences": [
{
"daysOfWeek": ["Saturday", "Sunday"],
"endTime": "04:00:00",
"recurrenceType": "Weekly",
"startTime": "22:00:00",
}
],
"timeZone": "India Standard Time",
},
"scopes": ["/subscriptions/subId1/resourceGroups/RGId1", "/subscriptions/subId1/resourceGroups/RGId2"],
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_recurring_maintenance_window.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armalertsmanagement_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/alertsmanagement/armalertsmanagement"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/6d2438481021a94793b07b226df06d5f3c61d51d/specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_recurring_maintenance_window.json
func ExampleAlertProcessingRulesClient_CreateOrUpdate_createOrUpdateARuleThatRemovesAllActionGroupsFromAllAlertsOnAnyVmInTwoResourceGroupsDuringARecurringMaintenanceWindow22000400EverySatAndSunIndiaStandardTime() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armalertsmanagement.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewAlertProcessingRulesClient().CreateOrUpdate(ctx, "alertscorrelationrg", "RemoveActionGroupsRecurringMaintenance", armalertsmanagement.AlertProcessingRule{
Location: to.Ptr("Global"),
Tags: map[string]*string{},
Properties: &armalertsmanagement.AlertProcessingRuleProperties{
Description: to.Ptr("Remove all ActionGroups from all Vitual machine Alerts during the recurring maintenance"),
Actions: []armalertsmanagement.ActionClassification{
&armalertsmanagement.RemoveAllActionGroups{
ActionType: to.Ptr(armalertsmanagement.ActionTypeRemoveAllActionGroups),
}},
Conditions: []*armalertsmanagement.Condition{
{
Field: to.Ptr(armalertsmanagement.FieldTargetResourceType),
Operator: to.Ptr(armalertsmanagement.OperatorEquals),
Values: []*string{
to.Ptr("microsoft.compute/virtualmachines")},
}},
Enabled: to.Ptr(true),
Schedule: &armalertsmanagement.Schedule{
Recurrences: []armalertsmanagement.RecurrenceClassification{
&armalertsmanagement.WeeklyRecurrence{
EndTime: to.Ptr("04:00:00"),
RecurrenceType: to.Ptr(armalertsmanagement.RecurrenceTypeWeekly),
StartTime: to.Ptr("22:00:00"),
DaysOfWeek: []*armalertsmanagement.DaysOfWeek{
to.Ptr(armalertsmanagement.DaysOfWeekSaturday),
to.Ptr(armalertsmanagement.DaysOfWeekSunday)},
}},
TimeZone: to.Ptr("India Standard Time"),
},
Scopes: []*string{
to.Ptr("/subscriptions/subId1/resourceGroups/RGId1"),
to.Ptr("/subscriptions/subId1/resourceGroups/RGId2")},
},
}, 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.AlertProcessingRule = armalertsmanagement.AlertProcessingRule{
// Name: to.Ptr("RemoveActionGroupsRecurringMaintenance"),
// Type: to.Ptr("Microsoft.AlertsManagement/actionRules"),
// ID: to.Ptr("/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsRecurringMaintenance"),
// Location: to.Ptr("Global"),
// Tags: map[string]*string{
// },
// Properties: &armalertsmanagement.AlertProcessingRuleProperties{
// Description: to.Ptr("Remove all ActionGroups from all Vitual machine Alerts during the recurring maintenance"),
// Actions: []armalertsmanagement.ActionClassification{
// &armalertsmanagement.RemoveAllActionGroups{
// ActionType: to.Ptr(armalertsmanagement.ActionTypeRemoveAllActionGroups),
// }},
// Conditions: []*armalertsmanagement.Condition{
// {
// Field: to.Ptr(armalertsmanagement.FieldTargetResourceType),
// Operator: to.Ptr(armalertsmanagement.OperatorEquals),
// Values: []*string{
// to.Ptr("microsoft.compute/virtualmachines")},
// }},
// Enabled: to.Ptr(true),
// Schedule: &armalertsmanagement.Schedule{
// Recurrences: []armalertsmanagement.RecurrenceClassification{
// &armalertsmanagement.WeeklyRecurrence{
// EndTime: to.Ptr("04:00:00"),
// RecurrenceType: to.Ptr(armalertsmanagement.RecurrenceTypeWeekly),
// StartTime: to.Ptr("22:00:00"),
// DaysOfWeek: []*armalertsmanagement.DaysOfWeek{
// to.Ptr(armalertsmanagement.DaysOfWeekSaturday),
// to.Ptr(armalertsmanagement.DaysOfWeekSunday)},
// }},
// TimeZone: to.Ptr("India Standard Time"),
// },
// Scopes: []*string{
// to.Ptr("/subscriptions/subId1/resourceGroups/RGId1"),
// to.Ptr("/subscriptions/subId1/resourceGroups/RGId2")},
// },
// SystemData: &armalertsmanagement.SystemData{
// CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-11T22:05:09.000Z"); return t}()),
// CreatedBy: to.Ptr("abc@microsoft.com"),
// CreatedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-12T22:05:09.000Z"); return t}()),
// LastModifiedBy: to.Ptr("xyz@microsoft.com"),
// LastModifiedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.AlertsManagement;
using Azure.ResourceManager.AlertsManagement.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_recurring_maintenance_window.json
// this example is just showing the usage of "AlertProcessingRules_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 = "subId1";
string resourceGroupName = "alertscorrelationrg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this AlertProcessingRuleResource
AlertProcessingRuleCollection collection = resourceGroupResource.GetAlertProcessingRules();
// invoke the operation
string alertProcessingRuleName = "RemoveActionGroupsRecurringMaintenance";
AlertProcessingRuleData data = new AlertProcessingRuleData(new AzureLocation("Global"))
{
Properties = new AlertProcessingRuleProperties(new string[]
{
"/subscriptions/subId1/resourceGroups/RGId1","/subscriptions/subId1/resourceGroups/RGId2"
}, new AlertProcessingRuleAction[]
{
new AlertProcessingRuleRemoveAllGroupsAction()
})
{
Conditions =
{
new AlertProcessingRuleCondition()
{
Field = AlertProcessingRuleField.TargetResourceType,
Operator = AlertProcessingRuleOperator.EqualsValue,
Values =
{
"microsoft.compute/virtualmachines"
},
}
},
Schedule = new AlertProcessingRuleSchedule()
{
TimeZone = "India Standard Time",
Recurrences =
{
new AlertProcessingRuleWeeklyRecurrence(new AlertsManagementDayOfWeek[]
{
AlertsManagementDayOfWeek.Saturday,AlertsManagementDayOfWeek.Sunday
})
{
StartOn = TimeSpan.Parse("22:00:00"),
EndOn = TimeSpan.Parse("04:00:00"),
}
},
},
Description = "Remove all ActionGroups from all Vitual machine Alerts during the recurring maintenance",
IsEnabled = true,
},
Tags =
{
},
};
ArmOperation<AlertProcessingRuleResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, alertProcessingRuleName, data);
AlertProcessingRuleResource 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
AlertProcessingRuleData 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
Sample Response
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-11T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-12T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1",
"/subscriptions/subId1/resourceGroups/RGId2"
],
"conditions": [
{
"field": "TargetResourceType",
"operator": "Equals",
"values": [
"microsoft.compute/virtualmachines"
]
}
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"timeZone": "India Standard Time",
"recurrences": [
{
"recurrenceType": "Weekly",
"startTime": "22:00:00",
"endTime": "04:00:00",
"daysOfWeek": [
"Saturday",
"Sunday"
]
}
]
},
"description": "Remove all ActionGroups from all Vitual machine Alerts during the recurring maintenance",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsRecurringMaintenance",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "RemoveActionGroupsRecurringMaintenance",
"location": "Global",
"tags": {}
}
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-11T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-12T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1/resourceGroups/RGId1",
"/subscriptions/subId1/resourceGroups/RGId2"
],
"conditions": [
{
"field": "TargetResourceType",
"operator": "Equals",
"values": [
"microsoft.compute/virtualmachines"
]
}
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"timeZone": "India Standard Time",
"recurrences": [
{
"recurrenceType": "Weekly",
"startTime": "22:00:00",
"endTime": "04:00:00",
"daysOfWeek": [
"Saturday",
"Sunday"
]
}
]
},
"description": "Remove all ActionGroups from all Vitual machine Alerts during the recurring maintenance",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsRecurringMaintenance",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "RemoveActionGroupsRecurringMaintenance",
"location": "Global",
"tags": {}
}
Create or update a rule that removes all action groups outside business hours (Mon-Fri 09:00-17:00, Eastern Standard Time)
Sample Request
PUT https://management.azure.com/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsOutsideBusinessHours?api-version=2021-08-08
{
"location": "Global",
"tags": {},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"timeZone": "Eastern Standard Time",
"recurrences": [
{
"recurrenceType": "Daily",
"startTime": "17:00:00",
"endTime": "09:00:00"
},
{
"recurrenceType": "Weekly",
"daysOfWeek": [
"Saturday",
"Sunday"
]
}
]
},
"description": "Remove all ActionGroups outside business hours",
"enabled": true
}
}
from azure.identity import DefaultAzureCredential
from azure.mgmt.alertsmanagement import AlertsManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-alertsmanagement
# USAGE
python alert_processing_rules_create_or_update_remove_all_action_groups_outside_business_hours.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = AlertsManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subId1",
)
response = client.alert_processing_rules.create_or_update(
resource_group_name="alertscorrelationrg",
alert_processing_rule_name="RemoveActionGroupsOutsideBusinessHours",
alert_processing_rule={
"location": "Global",
"properties": {
"actions": [{"actionType": "RemoveAllActionGroups"}],
"description": "Remove all ActionGroups outside business hours",
"enabled": True,
"schedule": {
"recurrences": [
{"endTime": "09:00:00", "recurrenceType": "Daily", "startTime": "17:00:00"},
{"daysOfWeek": ["Saturday", "Sunday"], "recurrenceType": "Weekly"},
],
"timeZone": "Eastern Standard Time",
},
"scopes": ["/subscriptions/subId1"],
},
"tags": {},
},
)
print(response)
# x-ms-original-file: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_outside_business_hours.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armalertsmanagement_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/alertsmanagement/armalertsmanagement"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/6d2438481021a94793b07b226df06d5f3c61d51d/specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_outside_business_hours.json
func ExampleAlertProcessingRulesClient_CreateOrUpdate_createOrUpdateARuleThatRemovesAllActionGroupsOutsideBusinessHoursMonFri09001700EasternStandardTime() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armalertsmanagement.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewAlertProcessingRulesClient().CreateOrUpdate(ctx, "alertscorrelationrg", "RemoveActionGroupsOutsideBusinessHours", armalertsmanagement.AlertProcessingRule{
Location: to.Ptr("Global"),
Tags: map[string]*string{},
Properties: &armalertsmanagement.AlertProcessingRuleProperties{
Description: to.Ptr("Remove all ActionGroups outside business hours"),
Actions: []armalertsmanagement.ActionClassification{
&armalertsmanagement.RemoveAllActionGroups{
ActionType: to.Ptr(armalertsmanagement.ActionTypeRemoveAllActionGroups),
}},
Enabled: to.Ptr(true),
Schedule: &armalertsmanagement.Schedule{
Recurrences: []armalertsmanagement.RecurrenceClassification{
&armalertsmanagement.DailyRecurrence{
EndTime: to.Ptr("09:00:00"),
RecurrenceType: to.Ptr(armalertsmanagement.RecurrenceTypeDaily),
StartTime: to.Ptr("17:00:00"),
},
&armalertsmanagement.WeeklyRecurrence{
RecurrenceType: to.Ptr(armalertsmanagement.RecurrenceTypeWeekly),
DaysOfWeek: []*armalertsmanagement.DaysOfWeek{
to.Ptr(armalertsmanagement.DaysOfWeekSaturday),
to.Ptr(armalertsmanagement.DaysOfWeekSunday)},
}},
TimeZone: to.Ptr("Eastern Standard Time"),
},
Scopes: []*string{
to.Ptr("/subscriptions/subId1")},
},
}, 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.AlertProcessingRule = armalertsmanagement.AlertProcessingRule{
// Name: to.Ptr("RemoveActionGroupsOutsideBusinessHours"),
// Type: to.Ptr("Microsoft.AlertsManagement/actionRules"),
// ID: to.Ptr("/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsOutsideBusinessHours"),
// Location: to.Ptr("Global"),
// Tags: map[string]*string{
// },
// Properties: &armalertsmanagement.AlertProcessingRuleProperties{
// Description: to.Ptr("Remove all ActionGroups outside business hours"),
// Actions: []armalertsmanagement.ActionClassification{
// &armalertsmanagement.RemoveAllActionGroups{
// ActionType: to.Ptr(armalertsmanagement.ActionTypeRemoveAllActionGroups),
// }},
// Enabled: to.Ptr(true),
// Schedule: &armalertsmanagement.Schedule{
// Recurrences: []armalertsmanagement.RecurrenceClassification{
// &armalertsmanagement.DailyRecurrence{
// EndTime: to.Ptr("09:00:00"),
// RecurrenceType: to.Ptr(armalertsmanagement.RecurrenceTypeDaily),
// StartTime: to.Ptr("17:00:00"),
// },
// &armalertsmanagement.WeeklyRecurrence{
// RecurrenceType: to.Ptr(armalertsmanagement.RecurrenceTypeWeekly),
// DaysOfWeek: []*armalertsmanagement.DaysOfWeek{
// to.Ptr(armalertsmanagement.DaysOfWeekSaturday),
// to.Ptr(armalertsmanagement.DaysOfWeekSunday)},
// }},
// TimeZone: to.Ptr("Eastern Standard Time"),
// },
// Scopes: []*string{
// to.Ptr("/subscriptions/subId1")},
// },
// SystemData: &armalertsmanagement.SystemData{
// CreatedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-11T22:05:09.000Z"); return t}()),
// CreatedBy: to.Ptr("abc@microsoft.com"),
// CreatedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// LastModifiedAt: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-06-12T22:05:09.000Z"); return t}()),
// LastModifiedBy: to.Ptr("xyz@microsoft.com"),
// LastModifiedByType: to.Ptr(armalertsmanagement.CreatedByTypeUser),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.AlertsManagement;
using Azure.ResourceManager.AlertsManagement.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-08-08/examples/AlertProcessingRules_Create_or_update_remove_all_action_groups_outside_business_hours.json
// this example is just showing the usage of "AlertProcessingRules_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 = "subId1";
string resourceGroupName = "alertscorrelationrg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this AlertProcessingRuleResource
AlertProcessingRuleCollection collection = resourceGroupResource.GetAlertProcessingRules();
// invoke the operation
string alertProcessingRuleName = "RemoveActionGroupsOutsideBusinessHours";
AlertProcessingRuleData data = new AlertProcessingRuleData(new AzureLocation("Global"))
{
Properties = new AlertProcessingRuleProperties(new string[]
{
"/subscriptions/subId1"
}, new AlertProcessingRuleAction[]
{
new AlertProcessingRuleRemoveAllGroupsAction()
})
{
Schedule = new AlertProcessingRuleSchedule()
{
TimeZone = "Eastern Standard Time",
Recurrences =
{
new DailyRecurrence()
{
StartOn = TimeSpan.Parse("17:00:00"),
EndOn = TimeSpan.Parse("09:00:00"),
},new AlertProcessingRuleWeeklyRecurrence(new AlertsManagementDayOfWeek[]
{
AlertsManagementDayOfWeek.Saturday,AlertsManagementDayOfWeek.Sunday
})
},
},
Description = "Remove all ActionGroups outside business hours",
IsEnabled = true,
},
Tags =
{
},
};
ArmOperation<AlertProcessingRuleResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, alertProcessingRuleName, data);
AlertProcessingRuleResource 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
AlertProcessingRuleData 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
Sample Response
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-11T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-12T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"timeZone": "Eastern Standard Time",
"recurrences": [
{
"recurrenceType": "Daily",
"startTime": "17:00:00",
"endTime": "09:00:00"
},
{
"recurrenceType": "Weekly",
"daysOfWeek": [
"Saturday",
"Sunday"
]
}
]
},
"description": "Remove all ActionGroups outside business hours",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsOutsideBusinessHours",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "RemoveActionGroupsOutsideBusinessHours",
"location": "Global",
"tags": {}
}
{
"systemData": {
"createdBy": "abc@microsoft.com",
"createdByType": "User",
"createdAt": "2018-06-11T22:05:09Z",
"lastModifiedBy": "xyz@microsoft.com",
"lastModifiedByType": "User",
"lastModifiedAt": "2018-06-12T22:05:09Z"
},
"properties": {
"scopes": [
"/subscriptions/subId1"
],
"actions": [
{
"actionType": "RemoveAllActionGroups"
}
],
"schedule": {
"timeZone": "Eastern Standard Time",
"recurrences": [
{
"recurrenceType": "Daily",
"startTime": "17:00:00",
"endTime": "09:00:00"
},
{
"recurrenceType": "Weekly",
"daysOfWeek": [
"Saturday",
"Sunday"
]
}
]
},
"description": "Remove all ActionGroups outside business hours",
"enabled": true
},
"id": "/subscriptions/subId1/resourceGroups/alertscorrelationrg/providers/Microsoft.AlertsManagement/actionRules/RemoveActionGroupsOutsideBusinessHours",
"type": "Microsoft.AlertsManagement/actionRules",
"name": "RemoveActionGroupsOutsideBusinessHours",
"location": "Global",
"tags": {}
}
Definizioni
Nome |
Descrizione |
AddActionGroups
|
Aggiungere gruppi di azioni alla regola di elaborazione degli avvisi.
|
AlertProcessingRule
|
Oggetto regola di elaborazione degli avvisi contenente ambiti di destinazione, condizioni e logica di pianificazione.
|
AlertProcessingRuleProperties
|
Proprietà della regola di elaborazione degli avvisi che definiscono ambiti, condizioni e logica di pianificazione per la regola di elaborazione degli avvisi.
|
api-version
|
Versione API client.
|
Condition
|
Condizione per attivare una regola di elaborazione degli avvisi.
|
createdByType
|
Tipo di identità che ha creato la risorsa.
|
DailyRecurrence
|
Oggetto ricorrenza giornaliero.
|
DaysOfWeek
|
Giorni della settimana.
|
errorResponse
|
Risposta di errore dal servizio.
|
errorResponseBody
|
Dettagli della risposta all'errore.
|
Field
|
Campo per una determinata condizione.
|
MonthlyRecurrence
|
Oggetto ricorrenza mensile.
|
Operator
|
Operatore per una determinata condizione.
|
RemoveAllActionGroups
|
Indica se tutti i gruppi di azioni devono essere rimossi.
|
Schedule
|
Pianificazione della configurazione per una determinata regola di elaborazione degli avvisi.
|
systemData
|
Metadati relativi alla creazione e all'ultima modifica della risorsa.
|
WeeklyRecurrence
|
Oggetto ricorrenza settimanale.
|
AddActionGroups
Aggiungere gruppi di azioni alla regola di elaborazione degli avvisi.
Nome |
Tipo |
Descrizione |
actionGroupIds
|
string[]
|
Elenco degli ID del gruppo di azioni da aggiungere alla regola di elaborazione degli avvisi.
|
actionType
|
string:
AddActionGroups
|
Azione che deve essere applicata.
|
AlertProcessingRule
Oggetto regola di elaborazione degli avvisi contenente ambiti di destinazione, condizioni e logica di pianificazione.
Nome |
Tipo |
Descrizione |
id
|
string
|
ID risorsa di Azure
|
location
|
string
|
Posizione risorsa
|
name
|
string
|
Nome risorsa di Azure
|
properties
|
AlertProcessingRuleProperties
|
Proprietà della regola di elaborazione degli avvisi.
|
systemData
|
systemData
|
Dati del sistema delle regole di elaborazione degli avvisi.
|
tags
|
object
|
Tag delle risorse
|
type
|
string
|
Tipo di risorsa di Azure
|
AlertProcessingRuleProperties
Proprietà della regola di elaborazione degli avvisi che definiscono ambiti, condizioni e logica di pianificazione per la regola di elaborazione degli avvisi.
Nome |
Tipo |
Valore predefinito |
Descrizione |
actions
|
Action[]:
|
|
Azioni da applicare.
|
conditions
|
Condition[]
|
|
Condizioni su cui verranno filtrati gli avvisi.
|
description
|
string
|
|
Descrizione della regola di elaborazione degli avvisi.
|
enabled
|
boolean
|
True
|
Indica se la regola di elaborazione degli avvisi specificata è abilitata o disabilitata.
|
schedule
|
Schedule
|
|
Pianificazione della regola di elaborazione degli avvisi.
|
scopes
|
string[]
|
|
Ambiti in cui verrà applicata la regola di elaborazione degli avvisi.
|
api-version
Versione API client.
Nome |
Tipo |
Descrizione |
2021-08-08
|
string
|
|
Condition
Condizione per attivare una regola di elaborazione degli avvisi.
Nome |
Tipo |
Descrizione |
field
|
Field
|
Campo per una determinata condizione.
|
operator
|
Operator
|
Operatore per una determinata condizione.
|
values
|
string[]
|
Elenco di valori da trovare per una determinata condizione.
|
createdByType
Tipo di identità che ha creato la risorsa.
Nome |
Tipo |
Descrizione |
Application
|
string
|
|
Key
|
string
|
|
ManagedIdentity
|
string
|
|
User
|
string
|
|
DailyRecurrence
Oggetto ricorrenza giornaliero.
Nome |
Tipo |
Descrizione |
endTime
|
string
|
Ora di fine per la ricorrenza.
|
recurrenceType
|
string:
Daily
|
Specifica quando deve essere applicata la ricorrenza.
|
startTime
|
string
|
Ora di inizio per la ricorrenza.
|
DaysOfWeek
Giorni della settimana.
Nome |
Tipo |
Descrizione |
Friday
|
string
|
|
Monday
|
string
|
|
Saturday
|
string
|
|
Sunday
|
string
|
|
Thursday
|
string
|
|
Tuesday
|
string
|
|
Wednesday
|
string
|
|
errorResponse
Risposta di errore dal servizio.
errorResponseBody
Dettagli della risposta all'errore.
Nome |
Tipo |
Descrizione |
code
|
string
|
Codice di errore, destinato a essere utilizzato a livello di codice.
|
details
|
errorResponseBody[]
|
Elenco di dettagli aggiuntivi sull'errore.
|
message
|
string
|
Descrizione dell'errore, destinato alla visualizzazione nell'interfaccia utente.
|
target
|
string
|
Destinazione dell'errore specifico, ad esempio nome della proprietà.
|
Field
Campo per una determinata condizione.
Nome |
Tipo |
Descrizione |
AlertContext
|
string
|
|
AlertRuleId
|
string
|
|
AlertRuleName
|
string
|
|
Description
|
string
|
|
MonitorCondition
|
string
|
|
MonitorService
|
string
|
|
Severity
|
string
|
|
SignalType
|
string
|
|
TargetResource
|
string
|
|
TargetResourceGroup
|
string
|
|
TargetResourceType
|
string
|
|
MonthlyRecurrence
Oggetto ricorrenza mensile.
Nome |
Tipo |
Descrizione |
daysOfMonth
|
integer[]
|
Specifica i valori per il modello di ricorrenza mensile.
|
endTime
|
string
|
Ora di fine per la ricorrenza.
|
recurrenceType
|
string:
Monthly
|
Specifica quando deve essere applicata la ricorrenza.
|
startTime
|
string
|
Ora di inizio per la ricorrenza.
|
Operator
Operatore per una determinata condizione.
Nome |
Tipo |
Descrizione |
Contains
|
string
|
|
DoesNotContain
|
string
|
|
Equals
|
string
|
|
NotEquals
|
string
|
|
RemoveAllActionGroups
Indica se tutti i gruppi di azioni devono essere rimossi.
Schedule
Pianificazione della configurazione per una determinata regola di elaborazione degli avvisi.
Nome |
Tipo |
Descrizione |
effectiveFrom
|
string
|
Pianificazione effettiva dal momento. Date-Time in formato ISO-8601 senza suffisso fuso orario.
|
effectiveUntil
|
string
|
Pianificazione effettiva fino al momento. Date-Time in formato ISO-8601 senza suffisso fuso orario.
|
recurrences
|
Recurrence[]:
|
Elenco delle ricorrenze.
|
timeZone
|
string
|
Fuso orario di pianificazione.
|
systemData
Metadati relativi alla creazione e all'ultima modifica della risorsa.
Nome |
Tipo |
Descrizione |
createdAt
|
string
|
Timestamp della creazione di risorse (UTC).
|
createdBy
|
string
|
Identità che ha creato la risorsa.
|
createdByType
|
createdByType
|
Tipo di identità che ha creato la risorsa.
|
lastModifiedAt
|
string
|
Timestamp dell'ultima modifica della risorsa (UTC)
|
lastModifiedBy
|
string
|
Identità che ha modificato l'ultima risorsa.
|
lastModifiedByType
|
createdByType
|
Tipo di identità che ha modificato l'ultima risorsa.
|
WeeklyRecurrence
Oggetto ricorrenza settimanale.
Nome |
Tipo |
Descrizione |
daysOfWeek
|
DaysOfWeek[]
|
Specifica i valori per il modello di ricorrenza settimanale.
|
endTime
|
string
|
Ora di fine per la ricorrenza.
|
recurrenceType
|
string:
Weekly
|
Specifica quando deve essere applicata la ricorrenza.
|
startTime
|
string
|
Ora di inizio per la ricorrenza.
|