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