1 package monitorlegacy
2
3
4
5
6
7
8
9 import (
10 "context"
11 "github.com/Azure/go-autorest/autorest"
12 "github.com/Azure/go-autorest/autorest/azure"
13 "github.com/Azure/go-autorest/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type AlertRuleIncidentsClient struct {
20 BaseClient
21 }
22
23
24 func NewAlertRuleIncidentsClient(subscriptionID string) AlertRuleIncidentsClient {
25 return NewAlertRuleIncidentsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30
31 func NewAlertRuleIncidentsClientWithBaseURI(baseURI string, subscriptionID string) AlertRuleIncidentsClient {
32 return AlertRuleIncidentsClient{NewWithBaseURI(baseURI, subscriptionID)}
33 }
34
35
36
37
38
39
40 func (client AlertRuleIncidentsClient) Get(ctx context.Context, resourceGroupName string, ruleName string, incidentName string) (result Incident, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleIncidentsClient.Get")
43 defer func() {
44 sc := -1
45 if result.Response.Response != nil {
46 sc = result.Response.Response.StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 if err := validation.Validate([]validation.Validation{
52 {TargetValue: resourceGroupName,
53 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
54 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
55 {TargetValue: client.SubscriptionID,
56 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
57 return result, validation.NewError("monitorlegacy.AlertRuleIncidentsClient", "Get", err.Error())
58 }
59
60 req, err := client.GetPreparer(ctx, resourceGroupName, ruleName, incidentName)
61 if err != nil {
62 err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "Get", nil, "Failure preparing request")
63 return
64 }
65
66 resp, err := client.GetSender(req)
67 if err != nil {
68 result.Response = autorest.Response{Response: resp}
69 err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "Get", resp, "Failure sending request")
70 return
71 }
72
73 result, err = client.GetResponder(resp)
74 if err != nil {
75 err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "Get", resp, "Failure responding to request")
76 return
77 }
78
79 return
80 }
81
82
83 func (client AlertRuleIncidentsClient) GetPreparer(ctx context.Context, resourceGroupName string, ruleName string, incidentName string) (*http.Request, error) {
84 pathParameters := map[string]interface{}{
85 "incidentName": autorest.Encode("path", incidentName),
86 "resourceGroupName": autorest.Encode("path", resourceGroupName),
87 "ruleName": autorest.Encode("path", ruleName),
88 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
89 }
90
91 const APIVersion = "2016-03-01"
92 queryParameters := map[string]interface{}{
93 "api-version": APIVersion,
94 }
95
96 preparer := autorest.CreatePreparer(
97 autorest.AsGet(),
98 autorest.WithBaseURL(client.BaseURI),
99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}/incidents/{incidentName}", pathParameters),
100 autorest.WithQueryParameters(queryParameters))
101 return preparer.Prepare((&http.Request{}).WithContext(ctx))
102 }
103
104
105
106 func (client AlertRuleIncidentsClient) GetSender(req *http.Request) (*http.Response, error) {
107 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108 }
109
110
111
112 func (client AlertRuleIncidentsClient) GetResponder(resp *http.Response) (result Incident, err error) {
113 err = autorest.Respond(
114 resp,
115 azure.WithErrorUnlessStatusCode(http.StatusOK),
116 autorest.ByUnmarshallingJSON(&result),
117 autorest.ByClosing())
118 result.Response = autorest.Response{Response: resp}
119 return
120 }
121
122
123
124
125
126 func (client AlertRuleIncidentsClient) ListByAlertRule(ctx context.Context, resourceGroupName string, ruleName string) (result IncidentListResult, err error) {
127 if tracing.IsEnabled() {
128 ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleIncidentsClient.ListByAlertRule")
129 defer func() {
130 sc := -1
131 if result.Response.Response != nil {
132 sc = result.Response.Response.StatusCode
133 }
134 tracing.EndSpan(ctx, sc, err)
135 }()
136 }
137 if err := validation.Validate([]validation.Validation{
138 {TargetValue: resourceGroupName,
139 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
140 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
141 {TargetValue: client.SubscriptionID,
142 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
143 return result, validation.NewError("monitorlegacy.AlertRuleIncidentsClient", "ListByAlertRule", err.Error())
144 }
145
146 req, err := client.ListByAlertRulePreparer(ctx, resourceGroupName, ruleName)
147 if err != nil {
148 err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "ListByAlertRule", nil, "Failure preparing request")
149 return
150 }
151
152 resp, err := client.ListByAlertRuleSender(req)
153 if err != nil {
154 result.Response = autorest.Response{Response: resp}
155 err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "ListByAlertRule", resp, "Failure sending request")
156 return
157 }
158
159 result, err = client.ListByAlertRuleResponder(resp)
160 if err != nil {
161 err = autorest.NewErrorWithError(err, "monitorlegacy.AlertRuleIncidentsClient", "ListByAlertRule", resp, "Failure responding to request")
162 return
163 }
164
165 return
166 }
167
168
169 func (client AlertRuleIncidentsClient) ListByAlertRulePreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) {
170 pathParameters := map[string]interface{}{
171 "resourceGroupName": autorest.Encode("path", resourceGroupName),
172 "ruleName": autorest.Encode("path", ruleName),
173 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
174 }
175
176 const APIVersion = "2016-03-01"
177 queryParameters := map[string]interface{}{
178 "api-version": APIVersion,
179 }
180
181 preparer := autorest.CreatePreparer(
182 autorest.AsGet(),
183 autorest.WithBaseURL(client.BaseURI),
184 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}/incidents", pathParameters),
185 autorest.WithQueryParameters(queryParameters))
186 return preparer.Prepare((&http.Request{}).WithContext(ctx))
187 }
188
189
190
191 func (client AlertRuleIncidentsClient) ListByAlertRuleSender(req *http.Request) (*http.Response, error) {
192 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
193 }
194
195
196
197 func (client AlertRuleIncidentsClient) ListByAlertRuleResponder(resp *http.Response) (result IncidentListResult, err error) {
198 err = autorest.Respond(
199 resp,
200 azure.WithErrorUnlessStatusCode(http.StatusOK),
201 autorest.ByUnmarshallingJSON(&result),
202 autorest.ByClosing())
203 result.Response = autorest.Response{Response: resp}
204 return
205 }
206
View as plain text