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/autorest/validation"
25	"net/http"
26)
27
28// ActivityLogAlertsClient is the monitor Management Client
29type ActivityLogAlertsClient struct {
30	BaseClient
31}
32
33// NewActivityLogAlertsClient creates an instance of the ActivityLogAlertsClient client.
34func NewActivityLogAlertsClient(subscriptionID string) ActivityLogAlertsClient {
35	return NewActivityLogAlertsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewActivityLogAlertsClientWithBaseURI creates an instance of the ActivityLogAlertsClient client.
39func NewActivityLogAlertsClientWithBaseURI(baseURI string, subscriptionID string) ActivityLogAlertsClient {
40	return ActivityLogAlertsClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// CreateOrUpdate create a new activity log alert or update an existing one.
44// Parameters:
45// resourceGroupName - the name of the resource group.
46// activityLogAlertName - the name of the activity log alert.
47// activityLogAlert - the activity log alert to create or use for the update.
48func (client ActivityLogAlertsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, activityLogAlertName string, activityLogAlert ActivityLogAlertResource) (result ActivityLogAlertResource, err error) {
49	if err := validation.Validate([]validation.Validation{
50		{TargetValue: activityLogAlert,
51			Constraints: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert", Name: validation.Null, Rule: false,
52				Chain: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert.Scopes", Name: validation.Null, Rule: true, Chain: nil},
53					{Target: "activityLogAlert.ActivityLogAlert.Condition", Name: validation.Null, Rule: true,
54						Chain: []validation.Constraint{{Target: "activityLogAlert.ActivityLogAlert.Condition.AllOf", Name: validation.Null, Rule: true, Chain: nil}}},
55					{Target: "activityLogAlert.ActivityLogAlert.Actions", Name: validation.Null, Rule: true, Chain: nil},
56				}}}}}); err != nil {
57		return result, validation.NewError("insights.ActivityLogAlertsClient", "CreateOrUpdate", err.Error())
58	}
59
60	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, activityLogAlertName, activityLogAlert)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "CreateOrUpdate", nil, "Failure preparing request")
63		return
64	}
65
66	resp, err := client.CreateOrUpdateSender(req)
67	if err != nil {
68		result.Response = autorest.Response{Response: resp}
69		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "CreateOrUpdate", resp, "Failure sending request")
70		return
71	}
72
73	result, err = client.CreateOrUpdateResponder(resp)
74	if err != nil {
75		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "CreateOrUpdate", resp, "Failure responding to request")
76	}
77
78	return
79}
80
81// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
82func (client ActivityLogAlertsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, activityLogAlertName string, activityLogAlert ActivityLogAlertResource) (*http.Request, error) {
83	pathParameters := map[string]interface{}{
84		"activityLogAlertName": autorest.Encode("path", activityLogAlertName),
85		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
86		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
87	}
88
89	const APIVersion = "2017-04-01"
90	queryParameters := map[string]interface{}{
91		"api-version": APIVersion,
92	}
93
94	preparer := autorest.CreatePreparer(
95		autorest.AsContentType("application/json; charset=utf-8"),
96		autorest.AsPut(),
97		autorest.WithBaseURL(client.BaseURI),
98		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts/{activityLogAlertName}", pathParameters),
99		autorest.WithJSON(activityLogAlert),
100		autorest.WithQueryParameters(queryParameters))
101	return preparer.Prepare((&http.Request{}).WithContext(ctx))
102}
103
104// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
105// http.Response Body if it receives an error.
106func (client ActivityLogAlertsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
107	return autorest.SendWithSender(client, req,
108		azure.DoRetryWithRegistration(client.Client))
109}
110
111// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
112// closes the http.Response Body.
113func (client ActivityLogAlertsClient) CreateOrUpdateResponder(resp *http.Response) (result ActivityLogAlertResource, err error) {
114	err = autorest.Respond(
115		resp,
116		client.ByInspecting(),
117		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
118		autorest.ByUnmarshallingJSON(&result),
119		autorest.ByClosing())
120	result.Response = autorest.Response{Response: resp}
121	return
122}
123
124// Delete delete an activity log alert.
125// Parameters:
126// resourceGroupName - the name of the resource group.
127// activityLogAlertName - the name of the activity log alert.
128func (client ActivityLogAlertsClient) Delete(ctx context.Context, resourceGroupName string, activityLogAlertName string) (result autorest.Response, err error) {
129	req, err := client.DeletePreparer(ctx, resourceGroupName, activityLogAlertName)
130	if err != nil {
131		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Delete", nil, "Failure preparing request")
132		return
133	}
134
135	resp, err := client.DeleteSender(req)
136	if err != nil {
137		result.Response = resp
138		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Delete", resp, "Failure sending request")
139		return
140	}
141
142	result, err = client.DeleteResponder(resp)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Delete", resp, "Failure responding to request")
145	}
146
147	return
148}
149
150// DeletePreparer prepares the Delete request.
151func (client ActivityLogAlertsClient) DeletePreparer(ctx context.Context, resourceGroupName string, activityLogAlertName string) (*http.Request, error) {
152	pathParameters := map[string]interface{}{
153		"activityLogAlertName": autorest.Encode("path", activityLogAlertName),
154		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
155		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
156	}
157
158	const APIVersion = "2017-04-01"
159	queryParameters := map[string]interface{}{
160		"api-version": APIVersion,
161	}
162
163	preparer := autorest.CreatePreparer(
164		autorest.AsDelete(),
165		autorest.WithBaseURL(client.BaseURI),
166		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts/{activityLogAlertName}", pathParameters),
167		autorest.WithQueryParameters(queryParameters))
168	return preparer.Prepare((&http.Request{}).WithContext(ctx))
169}
170
171// DeleteSender sends the Delete request. The method will close the
172// http.Response Body if it receives an error.
173func (client ActivityLogAlertsClient) DeleteSender(req *http.Request) (*http.Response, error) {
174	return autorest.SendWithSender(client, req,
175		azure.DoRetryWithRegistration(client.Client))
176}
177
178// DeleteResponder handles the response to the Delete request. The method always
179// closes the http.Response Body.
180func (client ActivityLogAlertsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
181	err = autorest.Respond(
182		resp,
183		client.ByInspecting(),
184		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
185		autorest.ByClosing())
186	result.Response = resp
187	return
188}
189
190// Get get an activity log alert.
191// Parameters:
192// resourceGroupName - the name of the resource group.
193// activityLogAlertName - the name of the activity log alert.
194func (client ActivityLogAlertsClient) Get(ctx context.Context, resourceGroupName string, activityLogAlertName string) (result ActivityLogAlertResource, err error) {
195	req, err := client.GetPreparer(ctx, resourceGroupName, activityLogAlertName)
196	if err != nil {
197		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Get", nil, "Failure preparing request")
198		return
199	}
200
201	resp, err := client.GetSender(req)
202	if err != nil {
203		result.Response = autorest.Response{Response: resp}
204		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Get", resp, "Failure sending request")
205		return
206	}
207
208	result, err = client.GetResponder(resp)
209	if err != nil {
210		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Get", resp, "Failure responding to request")
211	}
212
213	return
214}
215
216// GetPreparer prepares the Get request.
217func (client ActivityLogAlertsClient) GetPreparer(ctx context.Context, resourceGroupName string, activityLogAlertName string) (*http.Request, error) {
218	pathParameters := map[string]interface{}{
219		"activityLogAlertName": autorest.Encode("path", activityLogAlertName),
220		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
221		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
222	}
223
224	const APIVersion = "2017-04-01"
225	queryParameters := map[string]interface{}{
226		"api-version": APIVersion,
227	}
228
229	preparer := autorest.CreatePreparer(
230		autorest.AsGet(),
231		autorest.WithBaseURL(client.BaseURI),
232		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts/{activityLogAlertName}", pathParameters),
233		autorest.WithQueryParameters(queryParameters))
234	return preparer.Prepare((&http.Request{}).WithContext(ctx))
235}
236
237// GetSender sends the Get request. The method will close the
238// http.Response Body if it receives an error.
239func (client ActivityLogAlertsClient) GetSender(req *http.Request) (*http.Response, error) {
240	return autorest.SendWithSender(client, req,
241		azure.DoRetryWithRegistration(client.Client))
242}
243
244// GetResponder handles the response to the Get request. The method always
245// closes the http.Response Body.
246func (client ActivityLogAlertsClient) GetResponder(resp *http.Response) (result ActivityLogAlertResource, err error) {
247	err = autorest.Respond(
248		resp,
249		client.ByInspecting(),
250		azure.WithErrorUnlessStatusCode(http.StatusOK),
251		autorest.ByUnmarshallingJSON(&result),
252		autorest.ByClosing())
253	result.Response = autorest.Response{Response: resp}
254	return
255}
256
257// ListByResourceGroup get a list of all activity log alerts in a resource group.
258// Parameters:
259// resourceGroupName - the name of the resource group.
260func (client ActivityLogAlertsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ActivityLogAlertList, err error) {
261	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
262	if err != nil {
263		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListByResourceGroup", nil, "Failure preparing request")
264		return
265	}
266
267	resp, err := client.ListByResourceGroupSender(req)
268	if err != nil {
269		result.Response = autorest.Response{Response: resp}
270		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListByResourceGroup", resp, "Failure sending request")
271		return
272	}
273
274	result, err = client.ListByResourceGroupResponder(resp)
275	if err != nil {
276		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListByResourceGroup", resp, "Failure responding to request")
277	}
278
279	return
280}
281
282// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
283func (client ActivityLogAlertsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
284	pathParameters := map[string]interface{}{
285		"resourceGroupName": autorest.Encode("path", resourceGroupName),
286		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
287	}
288
289	const APIVersion = "2017-04-01"
290	queryParameters := map[string]interface{}{
291		"api-version": APIVersion,
292	}
293
294	preparer := autorest.CreatePreparer(
295		autorest.AsGet(),
296		autorest.WithBaseURL(client.BaseURI),
297		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts", pathParameters),
298		autorest.WithQueryParameters(queryParameters))
299	return preparer.Prepare((&http.Request{}).WithContext(ctx))
300}
301
302// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
303// http.Response Body if it receives an error.
304func (client ActivityLogAlertsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
305	return autorest.SendWithSender(client, req,
306		azure.DoRetryWithRegistration(client.Client))
307}
308
309// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
310// closes the http.Response Body.
311func (client ActivityLogAlertsClient) ListByResourceGroupResponder(resp *http.Response) (result ActivityLogAlertList, err error) {
312	err = autorest.Respond(
313		resp,
314		client.ByInspecting(),
315		azure.WithErrorUnlessStatusCode(http.StatusOK),
316		autorest.ByUnmarshallingJSON(&result),
317		autorest.ByClosing())
318	result.Response = autorest.Response{Response: resp}
319	return
320}
321
322// ListBySubscriptionID get a list of all activity log alerts in a subscription.
323func (client ActivityLogAlertsClient) ListBySubscriptionID(ctx context.Context) (result ActivityLogAlertList, err error) {
324	req, err := client.ListBySubscriptionIDPreparer(ctx)
325	if err != nil {
326		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListBySubscriptionID", nil, "Failure preparing request")
327		return
328	}
329
330	resp, err := client.ListBySubscriptionIDSender(req)
331	if err != nil {
332		result.Response = autorest.Response{Response: resp}
333		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListBySubscriptionID", resp, "Failure sending request")
334		return
335	}
336
337	result, err = client.ListBySubscriptionIDResponder(resp)
338	if err != nil {
339		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "ListBySubscriptionID", resp, "Failure responding to request")
340	}
341
342	return
343}
344
345// ListBySubscriptionIDPreparer prepares the ListBySubscriptionID request.
346func (client ActivityLogAlertsClient) ListBySubscriptionIDPreparer(ctx context.Context) (*http.Request, error) {
347	pathParameters := map[string]interface{}{
348		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
349	}
350
351	const APIVersion = "2017-04-01"
352	queryParameters := map[string]interface{}{
353		"api-version": APIVersion,
354	}
355
356	preparer := autorest.CreatePreparer(
357		autorest.AsGet(),
358		autorest.WithBaseURL(client.BaseURI),
359		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/microsoft.insights/activityLogAlerts", pathParameters),
360		autorest.WithQueryParameters(queryParameters))
361	return preparer.Prepare((&http.Request{}).WithContext(ctx))
362}
363
364// ListBySubscriptionIDSender sends the ListBySubscriptionID request. The method will close the
365// http.Response Body if it receives an error.
366func (client ActivityLogAlertsClient) ListBySubscriptionIDSender(req *http.Request) (*http.Response, error) {
367	return autorest.SendWithSender(client, req,
368		azure.DoRetryWithRegistration(client.Client))
369}
370
371// ListBySubscriptionIDResponder handles the response to the ListBySubscriptionID request. The method always
372// closes the http.Response Body.
373func (client ActivityLogAlertsClient) ListBySubscriptionIDResponder(resp *http.Response) (result ActivityLogAlertList, err error) {
374	err = autorest.Respond(
375		resp,
376		client.ByInspecting(),
377		azure.WithErrorUnlessStatusCode(http.StatusOK),
378		autorest.ByUnmarshallingJSON(&result),
379		autorest.ByClosing())
380	result.Response = autorest.Response{Response: resp}
381	return
382}
383
384// Update updates an existing ActivityLogAlertResource's tags. To update other fields use the CreateOrUpdate method.
385// Parameters:
386// resourceGroupName - the name of the resource group.
387// activityLogAlertName - the name of the activity log alert.
388// activityLogAlertPatch - parameters supplied to the operation.
389func (client ActivityLogAlertsClient) Update(ctx context.Context, resourceGroupName string, activityLogAlertName string, activityLogAlertPatch ActivityLogAlertPatchBody) (result ActivityLogAlertResource, err error) {
390	req, err := client.UpdatePreparer(ctx, resourceGroupName, activityLogAlertName, activityLogAlertPatch)
391	if err != nil {
392		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Update", nil, "Failure preparing request")
393		return
394	}
395
396	resp, err := client.UpdateSender(req)
397	if err != nil {
398		result.Response = autorest.Response{Response: resp}
399		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Update", resp, "Failure sending request")
400		return
401	}
402
403	result, err = client.UpdateResponder(resp)
404	if err != nil {
405		err = autorest.NewErrorWithError(err, "insights.ActivityLogAlertsClient", "Update", resp, "Failure responding to request")
406	}
407
408	return
409}
410
411// UpdatePreparer prepares the Update request.
412func (client ActivityLogAlertsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, activityLogAlertName string, activityLogAlertPatch ActivityLogAlertPatchBody) (*http.Request, error) {
413	pathParameters := map[string]interface{}{
414		"activityLogAlertName": autorest.Encode("path", activityLogAlertName),
415		"resourceGroupName":    autorest.Encode("path", resourceGroupName),
416		"subscriptionId":       autorest.Encode("path", client.SubscriptionID),
417	}
418
419	const APIVersion = "2017-04-01"
420	queryParameters := map[string]interface{}{
421		"api-version": APIVersion,
422	}
423
424	preparer := autorest.CreatePreparer(
425		autorest.AsContentType("application/json; charset=utf-8"),
426		autorest.AsPatch(),
427		autorest.WithBaseURL(client.BaseURI),
428		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.insights/activityLogAlerts/{activityLogAlertName}", pathParameters),
429		autorest.WithJSON(activityLogAlertPatch),
430		autorest.WithQueryParameters(queryParameters))
431	return preparer.Prepare((&http.Request{}).WithContext(ctx))
432}
433
434// UpdateSender sends the Update request. The method will close the
435// http.Response Body if it receives an error.
436func (client ActivityLogAlertsClient) UpdateSender(req *http.Request) (*http.Response, error) {
437	return autorest.SendWithSender(client, req,
438		azure.DoRetryWithRegistration(client.Client))
439}
440
441// UpdateResponder handles the response to the Update request. The method always
442// closes the http.Response Body.
443func (client ActivityLogAlertsClient) UpdateResponder(resp *http.Response) (result ActivityLogAlertResource, err error) {
444	err = autorest.Respond(
445		resp,
446		client.ByInspecting(),
447		azure.WithErrorUnlessStatusCode(http.StatusOK),
448		autorest.ByUnmarshallingJSON(&result),
449		autorest.ByClosing())
450	result.Response = autorest.Response{Response: resp}
451	return
452}
453