1package insights
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/tracing"
25	"net/http"
26)
27
28// AlertRuleIncidentsClient is the monitor Management Client
29type AlertRuleIncidentsClient struct {
30	BaseClient
31}
32
33// NewAlertRuleIncidentsClient creates an instance of the AlertRuleIncidentsClient client.
34func NewAlertRuleIncidentsClient(subscriptionID string) AlertRuleIncidentsClient {
35	return NewAlertRuleIncidentsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewAlertRuleIncidentsClientWithBaseURI creates an instance of the AlertRuleIncidentsClient client.
39func NewAlertRuleIncidentsClientWithBaseURI(baseURI string, subscriptionID string) AlertRuleIncidentsClient {
40	return AlertRuleIncidentsClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// Get gets an incident associated to an alert rule
44// Parameters:
45// resourceGroupName - the name of the resource group.
46// ruleName - the name of the rule.
47// incidentName - the name of the incident to retrieve.
48func (client AlertRuleIncidentsClient) Get(ctx context.Context, resourceGroupName string, ruleName string, incidentName string) (result Incident, err error) {
49	if tracing.IsEnabled() {
50		ctx = tracing.StartSpan(ctx, fqdn+"/AlertRuleIncidentsClient.Get")
51		defer func() {
52			sc := -1
53			if result.Response.Response != nil {
54				sc = result.Response.Response.StatusCode
55			}
56			tracing.EndSpan(ctx, sc, err)
57		}()
58	}
59	req, err := client.GetPreparer(ctx, resourceGroupName, ruleName, incidentName)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "insights.AlertRuleIncidentsClient", "Get", nil, "Failure preparing request")
62		return
63	}
64
65	resp, err := client.GetSender(req)
66	if err != nil {
67		result.Response = autorest.Response{Response: resp}
68		err = autorest.NewErrorWithError(err, "insights.AlertRuleIncidentsClient", "Get", resp, "Failure sending request")
69		return
70	}
71
72	result, err = client.GetResponder(resp)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "insights.AlertRuleIncidentsClient", "Get", resp, "Failure responding to request")
75	}
76
77	return
78}
79
80// GetPreparer prepares the Get request.
81func (client AlertRuleIncidentsClient) GetPreparer(ctx context.Context, resourceGroupName string, ruleName string, incidentName string) (*http.Request, error) {
82	pathParameters := map[string]interface{}{
83		"incidentName":      autorest.Encode("path", incidentName),
84		"resourceGroupName": autorest.Encode("path", resourceGroupName),
85		"ruleName":          autorest.Encode("path", ruleName),
86		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
87	}
88
89	const APIVersion = "2016-03-01"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93
94	preparer := autorest.CreatePreparer(
95		autorest.AsGet(),
96		autorest.WithBaseURL(client.BaseURI),
97		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}/incidents/{incidentName}", pathParameters),
98		autorest.WithQueryParameters(queryParameters))
99	return preparer.Prepare((&http.Request{}).WithContext(ctx))
100}
101
102// GetSender sends the Get request. The method will close the
103// http.Response Body if it receives an error.
104func (client AlertRuleIncidentsClient) GetSender(req *http.Request) (*http.Response, error) {
105	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
106	return autorest.SendWithSender(client, req, sd...)
107}
108
109// GetResponder handles the response to the Get request. The method always
110// closes the http.Response Body.
111func (client AlertRuleIncidentsClient) GetResponder(resp *http.Response) (result Incident, err error) {
112	err = autorest.Respond(
113		resp,
114		client.ByInspecting(),
115		azure.WithErrorUnlessStatusCode(http.StatusOK),
116		autorest.ByUnmarshallingJSON(&result),
117		autorest.ByClosing())
118	result.Response = autorest.Response{Response: resp}
119	return
120}
121
122// ListByAlertRule gets a list of incidents associated to an alert rule
123// Parameters:
124// resourceGroupName - the name of the resource group.
125// ruleName - the name of the rule.
126func (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	req, err := client.ListByAlertRulePreparer(ctx, resourceGroupName, ruleName)
138	if err != nil {
139		err = autorest.NewErrorWithError(err, "insights.AlertRuleIncidentsClient", "ListByAlertRule", nil, "Failure preparing request")
140		return
141	}
142
143	resp, err := client.ListByAlertRuleSender(req)
144	if err != nil {
145		result.Response = autorest.Response{Response: resp}
146		err = autorest.NewErrorWithError(err, "insights.AlertRuleIncidentsClient", "ListByAlertRule", resp, "Failure sending request")
147		return
148	}
149
150	result, err = client.ListByAlertRuleResponder(resp)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "insights.AlertRuleIncidentsClient", "ListByAlertRule", resp, "Failure responding to request")
153	}
154
155	return
156}
157
158// ListByAlertRulePreparer prepares the ListByAlertRule request.
159func (client AlertRuleIncidentsClient) ListByAlertRulePreparer(ctx context.Context, resourceGroupName string, ruleName string) (*http.Request, error) {
160	pathParameters := map[string]interface{}{
161		"resourceGroupName": autorest.Encode("path", resourceGroupName),
162		"ruleName":          autorest.Encode("path", ruleName),
163		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
164	}
165
166	const APIVersion = "2016-03-01"
167	queryParameters := map[string]interface{}{
168		"api-version": APIVersion,
169	}
170
171	preparer := autorest.CreatePreparer(
172		autorest.AsGet(),
173		autorest.WithBaseURL(client.BaseURI),
174		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/microsoft.insights/alertrules/{ruleName}/incidents", pathParameters),
175		autorest.WithQueryParameters(queryParameters))
176	return preparer.Prepare((&http.Request{}).WithContext(ctx))
177}
178
179// ListByAlertRuleSender sends the ListByAlertRule request. The method will close the
180// http.Response Body if it receives an error.
181func (client AlertRuleIncidentsClient) ListByAlertRuleSender(req *http.Request) (*http.Response, error) {
182	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
183	return autorest.SendWithSender(client, req, sd...)
184}
185
186// ListByAlertRuleResponder handles the response to the ListByAlertRule request. The method always
187// closes the http.Response Body.
188func (client AlertRuleIncidentsClient) ListByAlertRuleResponder(resp *http.Response) (result IncidentListResult, err error) {
189	err = autorest.Respond(
190		resp,
191		client.ByInspecting(),
192		azure.WithErrorUnlessStatusCode(http.StatusOK),
193		autorest.ByUnmarshallingJSON(&result),
194		autorest.ByClosing())
195	result.Response = autorest.Response{Response: resp}
196	return
197}
198