-
Notifications
You must be signed in to change notification settings - Fork 11
/
createOrUpdateScheduledQueryRule.go
80 lines (77 loc) · 3.12 KB
/
createOrUpdateScheduledQueryRule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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/tree/main/specification/monitor/resource-manager/Microsoft.Insights/stable/2022-06-15/examples/createOrUpdateScheduledQueryRule.json
func ExampleScheduledQueryRulesClient_CreateOrUpdate_createOrUpdateAScheduledQueryRuleForSingleResource() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
client, err := armmonitor.NewScheduledQueryRulesClient("dd4bfc94-a096-412b-9c43-4bd13e35afbc", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := client.CreateOrUpdate(ctx, "QueryResourceGroupName", "perf", armmonitor.ScheduledQueryRuleResource{
Location: to.Ptr("eastus"),
Properties: &armmonitor.ScheduledQueryRuleProperties{
Description: to.Ptr("Performance rule"),
Actions: &armmonitor.Actions{
ActionGroups: []*string{
to.Ptr("/subscriptions/1cf177ed-1330-4692-80ea-fd3d7783b147/resourcegroups/sqrapi/providers/microsoft.insights/actiongroups/myactiongroup")},
CustomProperties: map[string]*string{
"key11": to.Ptr("value11"),
"key12": to.Ptr("value12"),
},
},
AutoMitigate: to.Ptr(true),
CheckWorkspaceAlertsStorageConfigured: to.Ptr(true),
Criteria: &armmonitor.ScheduledQueryRuleCriteria{
AllOf: []*armmonitor.Condition{
{
Dimensions: []*armmonitor.Dimension{
{
Name: to.Ptr("ComputerIp"),
Operator: to.Ptr(armmonitor.DimensionOperatorExclude),
Values: []*string{
to.Ptr("192.168.1.1")},
},
{
Name: to.Ptr("OSType"),
Operator: to.Ptr(armmonitor.DimensionOperatorInclude),
Values: []*string{
to.Ptr("*")},
}},
FailingPeriods: &armmonitor.ConditionFailingPeriods{
MinFailingPeriodsToAlert: to.Ptr[int64](1),
NumberOfEvaluationPeriods: to.Ptr[int64](1),
},
MetricMeasureColumn: to.Ptr("% Processor Time"),
Operator: to.Ptr(armmonitor.ConditionOperatorGreaterThan),
Query: to.Ptr("Perf | where ObjectName == \"Processor\""),
ResourceIDColumn: to.Ptr("resourceId"),
Threshold: to.Ptr[float64](70),
TimeAggregation: to.Ptr(armmonitor.TimeAggregationAverage),
}},
},
Enabled: to.Ptr(true),
EvaluationFrequency: to.Ptr("PT5M"),
MuteActionsDuration: to.Ptr("PT30M"),
Scopes: []*string{
to.Ptr("/subscriptions/aaf177ed-1330-a9f2-80ea-fd3d7783b147/resourceGroups/scopeResourceGroup1/providers/Microsoft.Compute/virtualMachines/vm1")},
Severity: to.Ptr(armmonitor.AlertSeverity(4)),
SkipQueryValidation: to.Ptr(true),
WindowSize: to.Ptr("PT10M"),
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// TODO: use response item
_ = res
}