public SetAzureRmActivityLogAlertTests(Xunit.Abstractions.ITestOutputHelper output) { ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output)); TestExecutionHelpers.SetUpSessionAndProfile(); insightsOperationsMock = new Mock <IActivityLogAlertsOperations>(); insightsManagementClientMock = new Mock <MonitorManagementClient>(); commandRuntimeMock = new Mock <ICommandRuntime>(); cmdlet = new SetAzureRmActivityLogAlertCommand { CommandRuntime = commandRuntimeMock.Object, MonitorManagementClient = insightsManagementClientMock.Object }; response = new AzureOperationResponse <ActivityLogAlertResource>() { Body = new ActivityLogAlertResource() }; insightsOperationsMock.Setup(f => f.CreateOrUpdateWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ActivityLogAlertResource>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult <Microsoft.Rest.Azure.AzureOperationResponse <ActivityLogAlertResource> >(response)) .Callback((string resourceGrp, string name, ActivityLogAlertResource createOrUpdateParams, Dictionary <string, List <string> > headers, CancellationToken t) => { this.resourceGroup = resourceGrp; this.name = name; this.createOrUpdatePrms = createOrUpdateParams; }); insightsManagementClientMock.SetupGet(f => f.ActivityLogAlerts).Returns(this.insightsOperationsMock.Object); // Setup Confirmation commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>())).Returns(true); commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Returns(true); commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(true); commandRuntimeMock.Setup(f => f.ShouldContinue(It.IsAny <string>(), It.IsAny <string>())).Returns(true); }
public void UpdateActivityLogAlertTest() { ActivityLogAlertResource expectedParameters = GetCreateOrUpdateActivityLogAlertParameter(); var handler = new RecordedDelegatingHandler(); var monitorManagementClient = GetMonitorManagementClient(handler); var serializedObject = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(expectedParameters, monitorManagementClient.SerializationSettings); serializedObject = serializedObject.Replace("{", "{\"name\":\"" + expectedParameters.Name + "\",\"id\":\"" + expectedParameters.Id + "\","); var expectedResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(serializedObject) }; handler = new RecordedDelegatingHandler(expectedResponse); monitorManagementClient = GetMonitorManagementClient(handler); ActivityLogAlertPatchBody bodyParameter = new ActivityLogAlertPatchBody { Enabled = true, Tags = null }; ActivityLogAlertResource response = monitorManagementClient.ActivityLogAlerts.Update( resourceGroupName: "rg1", activityLogAlertName: "name1", activityLogAlertPatch: bodyParameter); AreEqual(expectedParameters, response); }
public async Task <Response <ActivityLogAlertResource> > CreateOrUpdateAsync(string resourceGroupName, string activityLogAlertName, ActivityLogAlertResource activityLogAlert, CancellationToken cancellationToken = default) { if (resourceGroupName == null) { throw new ArgumentNullException(nameof(resourceGroupName)); } if (activityLogAlertName == null) { throw new ArgumentNullException(nameof(activityLogAlertName)); } if (activityLogAlert == null) { throw new ArgumentNullException(nameof(activityLogAlert)); } using var message = CreateCreateOrUpdateRequest(resourceGroupName, activityLogAlertName, activityLogAlert); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); switch (message.Response.Status) { case 200: case 201: { ActivityLogAlertResource value = default; using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); value = ActivityLogAlertResource.DeserializeActivityLogAlertResource(document.RootElement); return(Response.FromValue(value, message.Response)); }
private void AreEqual(ActivityLogAlertResource exp, ActivityLogAlertResource act) { Assert.AreEqual(exp.Id, act.Id); Assert.AreEqual(exp.Name, act.Name); Assert.AreEqual(exp.Location, act.Location); Assert.AreEqual(exp.Type, act.Type); Assert.AreEqual(exp.Description, act.Description); }
public async Task Get() { var activityLogAlertName = Recording.GenerateAssetName("testActivityLogAlert-"); var activityLogAlert = await CreateActivityLogAlertAsync(activityLogAlertName); ActivityLogAlertResource activityLogAlert2 = await activityLogAlert.GetAsync(); ResourceDataHelper.AssertActivityLogAlert(activityLogAlert.Data, activityLogAlert2.Data); }
private ActivityLogAlertResource GetActivityLogAlertResource() { var ActivityLogAlert = new ActivityLogAlertResource("Id", "Name", "Type", "West us", new Dictionary <string, string>(), new List <string>(), true, new ActivityLogAlertAllOfCondition(new List <ActivityLogAlertLeafCondition>()), new ActivityLogAlertActionList(), "Description"); return(ActivityLogAlert); }
public GetAzureRmActivityLogAlertTests(Xunit.Abstractions.ITestOutputHelper output) { ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output)); TestExecutionHelpers.SetUpSessionAndProfile(); insightsOperationsMock = new Mock <IActivityLogAlertsOperations>(); insightsManagementClientMock = new Mock <MonitorManagementClient>() { CallBase = true }; commandRuntimeMock = new Mock <ICommandRuntime>(); cmdlet = new GetAzureRmActivityLogAlertCommand() { CommandRuntime = commandRuntimeMock.Object, MonitorManagementClient = insightsManagementClientMock.Object }; ActivityLogAlertResource responseObject = ActivityLogAlertsUtilities.CreateActivityLogAlertResource(location: "westus", name: "alert1"); responseSimple = new AzureOperationResponse <ActivityLogAlertResource>() { Body = responseObject }; responsePage = new AzureOperationResponse <IEnumerable <ActivityLogAlertResource> >() { Body = new List <ActivityLogAlertResource> { responseObject } }; insightsOperationsMock.Setup(f => f.GetWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult <AzureOperationResponse <ActivityLogAlertResource> >(responseSimple)) .Callback((string resourceGrp, string name, Dictionary <string, List <string> > headers, CancellationToken t) => { this.resourceGroup = resourceGrp; this.name = name; }); insightsOperationsMock.Setup(f => f.ListByResourceGroupWithHttpMessagesAsync(It.IsAny <string>(), It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult <AzureOperationResponse <IEnumerable <ActivityLogAlertResource> > >(responsePage)) .Callback((string resourceGrp, Dictionary <string, List <string> > headers, CancellationToken t) => { this.resourceGroup = resourceGrp; }); insightsOperationsMock.Setup(f => f.ListBySubscriptionIdWithHttpMessagesAsync(It.IsAny <Dictionary <string, List <string> > >(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult <AzureOperationResponse <IEnumerable <ActivityLogAlertResource> > >(responsePage)) .Callback((Dictionary <string, List <string> > headers, CancellationToken t) => {}); insightsManagementClientMock.SetupGet(f => f.ActivityLogAlerts).Returns(this.insightsOperationsMock.Object); }
public async Task Get() { var collection = await GetActivityLogAlertCollectionAsync(); var actionGroupName = Recording.GenerateAssetName("testActivityLogAlert"); var subID = DefaultSubscription.Id; var input = ResourceDataHelper.GetBasicActivityLogAlertData("global", subID); var lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, actionGroupName, input); ActivityLogAlertResource alert1 = lro.Value; ActivityLogAlertResource alert2 = await collection.GetAsync(actionGroupName); ResourceDataHelper.AssertActivityLogAlert(alert1.Data, alert2.Data); }
public PSActivityLogAlertResource(ActivityLogAlertResource activityLogAlertResource) : base( location: activityLogAlertResource.Location, scopes: activityLogAlertResource.Scopes, condition: activityLogAlertResource.Condition, actions: activityLogAlertResource.Actions, id: activityLogAlertResource.Id, name: activityLogAlertResource.Name, type: activityLogAlertResource.Type, tags: activityLogAlertResource.Tags, enabled: activityLogAlertResource.Enabled, description: activityLogAlertResource.Description) { }
public static void AreEqual(ActivityLogAlertResource exp, ActivityLogAlertResource act) { if (exp != null) { Assert.Equal(exp.Id, act.Id); Assert.Equal(exp.Name, act.Name); Assert.Equal(exp.Location, act.Location); Assert.Equal(exp.Description, act.Description); Assert.Equal(exp.Enabled, act.Enabled); AreEqual(exp.Tags, act.Tags); AreEqual(exp.Scopes, act.Scopes); AreEqual(exp.Condition, act.Condition); AreEqual(exp.Actions, act.Actions); } }
private ActivityLogAlertResource UpdateActivityLogAlertPsResource(PSActivityLogAlertResource inputObject) { var activityLogAlertResource = new ActivityLogAlertResource( inputObject.Location, inputObject.Scopes, new ActivityLogAlertAllOfCondition(inputObject.Condition.AllOf.Select(e => new ActivityLogAlertLeafCondition(field: e.Field, equals: e.Equals)).ToList()), new ActivityLogAlertActionList(inputObject.Actions.ActionGroups.Select(e => new ActivityLogAlertActionGroup(actionGroupId: e.ActionGroupId, webhookProperties: e.WebhookProperties)).ToList()), inputObject.Id, inputObject.Name, inputObject.Type, inputObject.Tags, inputObject.Enabled, inputObject.Description); return(UpdateActivityLogAlertResource(activityLogAlertResource)); }
private ActivityLogAlertResource CreateActivityLogAlertResource(string name, string location) { ActivityLogAlertResource newAlert = new ActivityLogAlertResource( name: name, location: location, scopes: this.Scope, condition: new ActivityLogAlertAllOfCondition(this.Condition), actions: new ActivityLogAlertActionList(this.Action)); // EnableAlert defaults to true newAlert.Enabled = !this.DisableAlert.IsPresent; newAlert.Description = this.Description; newAlert.Tags = this.Tag; return(newAlert); }
private ActivityLogAlertResource CreateActivityLogAlertResource(string name, string location) { ActivityLogAlertResource newAlert = new ActivityLogAlertResource( name: name, location: location, scopes: this.Scope, condition: new ActivityLogAlertAllOfCondition(allOf: this.Condition.Select(e => new ActivityLogAlertLeafCondition(field: e.Field, equals: e.Equals)).ToList()), actions: new ActivityLogAlertActionList(actionGroups: this.Action.Select(e => new ActivityLogAlertActionGroup(actionGroupId: e.ActionGroupId, webhookProperties: e.WebhookProperties)).ToList())); // EnableAlert defaults to true newAlert.Enabled = !this.DisableAlert.IsPresent; newAlert.Description = this.Description; newAlert.Tags = this.Tag; return(newAlert); }
public void DisableActivityLogAlertCommandParametersProcessing() { cmdlet.ResourceGroupName = Utilities.ResourceGroup; cmdlet.Name = "alert1"; cmdlet.ExecuteCmdlet(); Assert.Equal(Utilities.ResourceGroup, this.resourceGroup); Assert.Equal("alert1", this.name); Assert.NotNull(this.body); Assert.False(this.body.Enabled); Assert.Null(this.body.Tags); cmdlet.ExecuteCmdlet(); Assert.NotNull(this.body); Assert.False(this.body.Enabled); Assert.Null(this.body.Tags); ActivityLogAlertResource resource = new ActivityLogAlertResource(location: "Global", scopes: null, condition: null, name: "andy0307rule", actions: null, id: "//subscriptions/07c0b09d-9f69-4e6e-8d05-f59f67299cb2/resourceGroups/Default-ActivityLogAlerts/providers/microsoft.insights/activityLogAlerts/andy0307rule") { Enabled = true }; cmdlet.InputObject = new OutputClasses.PSActivityLogAlertResource(resource); cmdlet.ExecuteCmdlet(); Assert.NotNull(this.body); Assert.Equal("Default-ActivityLogAlerts", this.resourceGroup); Assert.Equal("andy0307rule", this.name); Assert.False(this.body.Enabled); Assert.Null(this.body.Tags); cmdlet.InputObject = null; cmdlet.ResourceId = "/subscriptions/07c0b09d-9f69-4e6e-8d05-f59f67299cb2/resourceGroups/Default-ActivityLogAlerts/providers/microsoft.insights/activityLogAlerts/andy0307rule"; cmdlet.ExecuteCmdlet(); Assert.NotNull(this.body); Assert.Equal("Default-ActivityLogAlerts", this.resourceGroup); Assert.Equal("andy0307rule", this.name); Assert.False(this.body.Enabled); Assert.Null(this.body.Tags); }
public void CreateOrUpdateActivityLogAlertsTest() { ActivityLogAlertResource expectedParameters = GetCreateOrUpdateActivityLogAlertParameter(); var handler = new RecordedDelegatingHandler(); var insightsClient = GetMonitorManagementClient(handler); var serializedObject = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(expectedParameters, insightsClient.SerializationSettings); serializedObject = serializedObject.Replace("{", "{\"name\":\"" + expectedParameters.Name + "\",\"id\":\"" + expectedParameters.Id + "\","); var expectedResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(serializedObject) }; handler = new RecordedDelegatingHandler(expectedResponse); insightsClient = GetMonitorManagementClient(handler); var result = insightsClient.ActivityLogAlerts.CreateOrUpdate(resourceGroupName: "rg1", activityLogAlertName: expectedParameters.Name, activityLogAlert: expectedParameters); AreEqual(expectedParameters, result); }
private ActivityLogAlertResource UpdateActivityLogAlertResource(ActivityLogAlertResource requestBody) { // There was an ActivityLogAlert already there, just modify what can be modifed // NOTE: Location remains unchanged, the value of the Location parameter is ignored if (this.MyInvocation.BoundParameters.ContainsKey("Scope") || this.Scope != null) { requestBody.Scopes = this.Scope; } if (this.MyInvocation.BoundParameters.ContainsKey("Condition") || this.Condition != null) { requestBody.Condition = new ActivityLogAlertAllOfCondition(this.Condition); } if (this.MyInvocation.BoundParameters.ContainsKey("Action") || this.Action != null) { requestBody.Actions = new ActivityLogAlertActionList(this.Action); } if (this.DisableAlert.IsPresent) { requestBody.Enabled = false; } if (this.MyInvocation.BoundParameters.ContainsKey("Description") || this.Description != null) { requestBody.Description = this.Description; } if (this.MyInvocation.BoundParameters.ContainsKey("Tag") || this.Tag != null) { requestBody.Tags = this.Tag; } return(requestBody); }
private ActivityLogAlertResource UpdateActivityLogAlertResource(ActivityLogAlertResource requestBody) { // There was an ActivityLogAlert already there, just modify what can be modifed // NOTE: Location remains unchanged, the value of the Location parameter is ignored if (this.MyInvocation.BoundParameters.ContainsKey("Scope") || this.Scope != null) { requestBody.Scopes = this.Scope; } if (this.MyInvocation.BoundParameters.ContainsKey("Condition") || this.Condition != null) { requestBody.Condition = new ActivityLogAlertAllOfCondition(allOf: this.Condition.Select(e => new ActivityLogAlertLeafCondition(field: e.Field, equals: e.Equals)).ToList()); } if (this.MyInvocation.BoundParameters.ContainsKey("Action") || this.Action != null) { requestBody.Actions = new ActivityLogAlertActionList(actionGroups: this.Action.Select(e => new ActivityLogAlertActionGroup(actionGroupId: e.ActionGroupId, webhookProperties: e.WebhookProperties)).ToList()); } if (this.DisableAlert.IsPresent) { requestBody.Enabled = false; } if (this.MyInvocation.BoundParameters.ContainsKey("Description") || this.Description != null) { requestBody.Description = this.Description; } if (this.MyInvocation.BoundParameters.ContainsKey("Tag") || this.Tag != null) { requestBody.Tags = this.Tag; } return(requestBody); }
/// <summary> /// Create a new activity log alert or update an existing one. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='activityLogAlertName'> /// The name of the activity log alert. /// </param> /// <param name='activityLogAlert'> /// The activity log alert to create or use for the update. /// </param> public static ActivityLogAlertResource CreateOrUpdate(this IActivityLogAlertsOperations operations, string resourceGroupName, string activityLogAlertName, ActivityLogAlertResource activityLogAlert) { return(operations.CreateOrUpdateAsync(resourceGroupName, activityLogAlertName, activityLogAlert).GetAwaiter().GetResult()); }
internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string activityLogAlertName, ActivityLogAlertResource activityLogAlert) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Put; var uri = new RawRequestUriBuilder(); uri.Reset(endpoint); uri.AppendPath("/subscriptions/", false); uri.AppendPath(subscriptionId, true); uri.AppendPath("/resourceGroups/", false); uri.AppendPath(resourceGroupName, true); uri.AppendPath("/providers/microsoft.insights/activityLogAlerts/", false); uri.AppendPath(activityLogAlertName, true); uri.AppendQuery("api-version", "2017-04-01", true); request.Uri = uri; request.Headers.Add("Content-Type", "application/json"); request.Headers.Add("Accept", "application/json"); var content = new Utf8JsonRequestContent(); content.JsonWriter.WriteObjectValue(activityLogAlert); request.Content = content; return(message); }
public void CreateGetListUpdateDeleteActivityLogAlert() { using (MockContext context = MockContext.Start(this.GetType())) { var insightsClient = GetMonitorManagementClient(context, handler); this.VerifyExistenceOrCreateResourceGroup(resourceGroupName: ResourceGroupName, location: Location); ActivityLogAlertResource bodyParameter = GetCreateOrUpdateActivityLogAlertParameter(insightsClient.SubscriptionId); ActivityLogAlertResource result = insightsClient.ActivityLogAlerts.CreateOrUpdate( resourceGroupName: ResourceGroupName, activityLogAlertName: ActivityLogRuleName, activityLogAlert: bodyParameter); if (!this.IsRecording) { // TODO: Create a Check Assert.False(string.IsNullOrWhiteSpace(result.Id)); Assert.Equal(ActivityLogRuleName, result.Name); Assert.NotNull(result.Actions); Assert.NotNull(result.Condition); Assert.NotNull(result.Scopes); // AreEqual(bodyParameter, result); } ActivityLogAlertResource activityLogAlert = insightsClient.ActivityLogAlerts.Get( resourceGroupName: ResourceGroupName, activityLogAlertName: ActivityLogRuleName); if (!this.IsRecording) { Utilities.AreEqual(result, activityLogAlert); } IEnumerable <ActivityLogAlertResource> actualGroups = insightsClient.ActivityLogAlerts.ListBySubscriptionId(); if (!this.IsRecording) { var listActualGroups = actualGroups.ToList(); Assert.NotNull(listActualGroups); Assert.True(listActualGroups.Count > 0); ActivityLogAlertResource similar = listActualGroups.FirstOrDefault(a => string.Equals(a.Id, activityLogAlert.Id, StringComparison.OrdinalIgnoreCase)); Assert.NotNull(similar); // AreEqual(bodyParameter, actualGroups.ToList()); } actualGroups = insightsClient.ActivityLogAlerts.ListByResourceGroup(resourceGroupName: ResourceGroupName); if (!this.IsRecording) { var listActualGroups = actualGroups.ToList(); Assert.NotNull(listActualGroups); Assert.True(listActualGroups.Count > 0); ActivityLogAlertResource similar = listActualGroups.FirstOrDefault(a => string.Equals(a.Id, activityLogAlert.Id, StringComparison.OrdinalIgnoreCase)); Assert.NotNull(similar); // AreEqual(bodyParameter, actualGroups.ToList()); } // TODO: Verify: Actions cannot be null or the request fails with BadRequest ActivityLogAlertPatchBody patchBodyParameter = new ActivityLogAlertPatchBody { Enabled = true, Tags = null }; ActivityLogAlertResource patchResponse = null; Assert.Throws <ErrorResponseException>( () => patchResponse = insightsClient.ActivityLogAlerts.Update( resourceGroupName: ResourceGroupName, activityLogAlertName: ActivityLogRuleName, activityLogAlertPatch: patchBodyParameter)); if (!this.IsRecording && patchResponse != null) { // Use Check here too Assert.False(string.IsNullOrWhiteSpace(patchResponse.Id)); Assert.Equal(ActivityLogRuleName, patchResponse.Name); Assert.NotNull(patchResponse.Actions); Assert.NotNull(patchResponse.Condition); Assert.NotNull(patchResponse.Scopes); Assert.True(patchResponse.Enabled); Assert.Null(patchResponse.Tags); Assert.Equal(activityLogAlert.Id, patchResponse.Id); // AreEqual(bodyParameter, response); } AzureOperationResponse deleteResponse = insightsClient.ActivityLogAlerts.DeleteWithHttpMessagesAsync( resourceGroupName: ResourceGroupName, activityLogAlertName: ActivityLogRuleName).Result; if (!this.IsRecording) { Assert.Equal(HttpStatusCode.OK, deleteResponse.Response.StatusCode); } } }
/// <summary> /// Create a new activity log alert or update an existing one. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='activityLogAlertName'> /// The name of the activity log alert. /// </param> /// <param name='activityLogAlert'> /// The activity log alert to create or use for the update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ActivityLogAlertResource> CreateOrUpdateAsync(this IActivityLogAlertsOperations operations, string resourceGroupName, string activityLogAlertName, ActivityLogAlertResource activityLogAlert, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, activityLogAlertName, activityLogAlert, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Execute the cmdlet /// </summary> protected override void ProcessRecordInternal() { if (ShouldProcess( target: string.Format("Create/update an activity logs alert: {0} from resource group: {1}", this.Name, this.ResourceGroupName), action: "Create/update an activity logs alert")) { string resourceGroupName = this.ResourceGroupName; string activityLogAlertName = this.Name; ActivityLogAlertResource requestBody = null; // Using value from the pipe if (this.MyInvocation.BoundParameters.ContainsKey("InputObject") || this.InputObject != null) { WriteVerboseWithTimestamp("InputObject detected: creating request body based on it."); ActivityLogAlertUtilities.ProcessPipeObject( inputObject: this.InputObject, resourceGroupName: out resourceGroupName, activityLogAlertName: out activityLogAlertName); requestBody = this.UpdateActivityLogAlertPsResource(this.InputObject); } else if (this.MyInvocation.BoundParameters.ContainsKey("ResourceId") || !string.IsNullOrWhiteSpace(this.ResourceId)) { WriteVerboseWithTimestamp("ResourceId detected: extracting name and resource group name based on it."); // ResourceId is not enough to set an ActivityLogAlert // First there is the need to try and find an existing alert and modify it ActivityLogAlertUtilities.ProcessPipeObject( resourceId: this.ResourceId, resourceGroupName: out resourceGroupName, activityLogAlertName: out activityLogAlertName); WriteVerboseWithTimestamp("ResourceId detected: checking for the existence the given activity log alert."); requestBody = this.MonitorManagementClient.ActivityLogAlerts.Get(resourceGroupName: resourceGroupName, activityLogAlertName: activityLogAlertName); if (requestBody == null) { WriteVerboseWithTimestamp("ResourceId detected: given activity log alert does not exist."); // This can only happen if the user sent a resourceId of an alert that does not exist yet if (string.IsNullOrWhiteSpace(this.Location)) { // The user wants to create an activity log alert given ResourceId as argument, but the Location parameter was empty or null throw new PSArgumentException("With ResourceId parameter used to create a new ActivityLogAlert, Location must contain a value", "Location"); } requestBody = this.CreateActivityLogAlertResource( name: activityLogAlertName, location: this.Location); } else { WriteVerboseWithTimestamp("ResourceId detected: given activity log alert found, modifying its values with the parameters."); requestBody = this.UpdateActivityLogAlertResource(requestBody); } } else { WriteVerboseWithTimestamp("No InputObject or ResourceId detected: following standard creation/update process."); requestBody = this.CreateActivityLogAlertResource( name: activityLogAlertName, location: this.Location); } WriteObject( this.MonitorManagementClient.ActivityLogAlerts.CreateOrUpdate( resourceGroupName: resourceGroupName, activityLogAlertName: activityLogAlertName, activityLogAlert: requestBody)); } }
public virtual Response <ActivityLogAlertResource> CreateOrUpdate(string resourceGroupName, string activityLogAlertName, ActivityLogAlertResource activityLogAlert, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("ActivityLogAlertsOperations.CreateOrUpdate"); scope.Start(); try { return(RestClient.CreateOrUpdate(resourceGroupName, activityLogAlertName, activityLogAlert, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }