diff --git a/src/OperationalInsights/OperationalInsights/ChangeLog.md b/src/OperationalInsights/OperationalInsights/ChangeLog.md index 75526f03584f..95cf69852fba 100644 --- a/src/OperationalInsights/OperationalInsights/ChangeLog.md +++ b/src/OperationalInsights/OperationalInsights/ChangeLog.md @@ -18,6 +18,9 @@ - Additional information about change #1 --> ## Upcoming Release +* Added alias "FunctionParameters" for parameter "FunctionParameter" to + - `New-AzOperationalInsightsSavedSearch` + - `Set-AzOperationalInsightsSavedSearch` ## Version 2.1.0 * Upgraded SDK to 0.21.0 diff --git a/src/OperationalInsights/OperationalInsights/Client/OperationalInsightsClient.Search.cs b/src/OperationalInsights/OperationalInsights/Client/OperationalInsightsClient.Search.cs index 8d8c31af8b0a..9f07807ca885 100644 --- a/src/OperationalInsights/OperationalInsights/Client/OperationalInsightsClient.Search.cs +++ b/src/OperationalInsights/OperationalInsights/Client/OperationalInsightsClient.Search.cs @@ -51,18 +51,43 @@ public virtual PSSearchGetSchemaResponse GetSchema(string resourceGroupName, str return schemaResponse; } - public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName, string workspaceName, string savedSearchId, SavedSearch properties, bool force, Action> ConfirmAction, string ETag = null) + public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName, string workspaceName, string savedSearchId, SavedSearch properties, bool patch, bool force, Action> ConfirmAction, string ETag = null) { + PSSearchGetSavedSearchResponse ExistingSearch; + bool existed; + + try + { + ExistingSearch = GetSavedSearch(resourceGroupName, workspaceName, savedSearchId); + } + catch (Rest.Azure.CloudException) + { + ExistingSearch = null; + } + + existed = ExistingSearch == null ? false : true; + HttpStatusCode status = HttpStatusCode.Ambiguous; Action createSavedSearch = () => + { + if (ETag != null && ETag != "") { - if (ETag != null && ETag != "") - { - properties.ETag = ETag; - } - Rest.Azure.AzureOperationResponse result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult(); - status = result.Response.StatusCode; - }; + properties.ETag = ETag; + } + Rest.Azure.AzureOperationResponse result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult(); + status = result.Response.StatusCode; + }; + + Action updateSavedSearch = () => + { + if (ETag != null && ETag != "") + { + properties.ETag = ETag; + } + properties.FunctionParameters = ExistingSearch.Properties.FunctionParameters; + Rest.Azure.AzureOperationResponse result = OperationalInsightsManagementClient.SavedSearches.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, workspaceName, savedSearchId, properties).GetAwaiter().GetResult(); + status = result.Response.StatusCode; + }; ConfirmAction( force, // prompt only if the saved search exists @@ -77,8 +102,8 @@ public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName savedSearchId, workspaceName), savedSearchId, - createSavedSearch, - () => CheckSavedSearchExists(resourceGroupName, workspaceName, savedSearchId)); + (patch && existed) ? updateSavedSearch : createSavedSearch , + () => existed); return status; } diff --git a/src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsComputerGroupCommand.cs b/src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsComputerGroupCommand.cs index 38ae39ae0b4b..4f16f10c2363 100644 --- a/src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsComputerGroupCommand.cs +++ b/src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsComputerGroupCommand.cs @@ -75,7 +75,7 @@ protected override void ProcessRecord() Tags = new List() { new Tag() { Name = "Group", Value = "Computer" } } }; - WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true); + WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, false, Force, ConfirmAction), true); } } diff --git a/src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsSavedSearchCommand.cs b/src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsSavedSearchCommand.cs index 62fe29700cc5..270a3afa1fb4 100644 --- a/src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsSavedSearchCommand.cs +++ b/src/OperationalInsights/OperationalInsights/Search/NewAzureOperationalInsightsSavedSearchCommand.cs @@ -17,6 +17,7 @@ using Microsoft.Azure.Management.OperationalInsights.Models; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using System.Net; +using Microsoft.WindowsAzure.Commands.Utilities.Common; namespace Microsoft.Azure.Commands.OperationalInsights { @@ -73,7 +74,8 @@ public class NewAzureOperationalInsightsSavedSearchCommand : OperationalInsights [Parameter(Position = 9, Mandatory = false, HelpMessage = "The optional function parameters if query serves as a function. Value should be in the following format: 'param-name1:type1 = default_value1, param-name2:type2 = default_value2'. For more examples and proper syntax please refer to https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions.")] - [ValidateNotNullOrEmpty] + [ValidateNotNull] + [Alias("FunctionParameters")] public string FunctionParameter { get; set; } [Parameter(Mandatory = false, HelpMessage = "Don't ask for confirmation.")] @@ -91,8 +93,10 @@ protected override void ProcessRecord() FunctionParameters = this.FunctionParameter }; + bool patch = this.IsParameterBound(c => c.FunctionParameter); + properties.Tags = SearchCommandHelper.PopulateAndValidateTagsForProperties(this.Tag, properties.Query); - WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true); + WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, patch, Force, ConfirmAction), true); } } diff --git a/src/OperationalInsights/OperationalInsights/Search/SetAzureOperationalInsightsSavedSearch.cs b/src/OperationalInsights/OperationalInsights/Search/SetAzureOperationalInsightsSavedSearch.cs index 5fe337942221..85a4b6a2fc73 100644 --- a/src/OperationalInsights/OperationalInsights/Search/SetAzureOperationalInsightsSavedSearch.cs +++ b/src/OperationalInsights/OperationalInsights/Search/SetAzureOperationalInsightsSavedSearch.cs @@ -17,6 +17,7 @@ using Microsoft.Azure.Management.OperationalInsights.Models; using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; using System.Net; +using Microsoft.WindowsAzure.Commands.Utilities.Common; namespace Microsoft.Azure.Commands.OperationalInsights { @@ -78,7 +79,8 @@ public class SetAzureOperationalInsightsSavedSearchCommand : OperationalInsights [Parameter(Position = 10, Mandatory = false, HelpMessage = "The optional function parameters if query serves as a function. Value should be in the following format: 'param-name1:type1 = default_value1, param-name2:type2 = default_value2'. For more examples and proper syntax please refer to https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions.")] - [ValidateNotNullOrEmpty] + [ValidateNotNull] + [Alias("FunctionParameters")] public string FunctionParameter { get; set; } protected override void ProcessRecord() @@ -93,8 +95,10 @@ protected override void ProcessRecord() FunctionParameters = this.FunctionParameter }; + bool patch = this.IsParameterBound(c => c.FunctionParameter); + properties.Tags = SearchCommandHelper.PopulateAndValidateTagsForProperties(this.Tag, properties.Query); - WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, true, ConfirmAction, ETag), true); + WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, patch, true, ConfirmAction, ETag), true); } } diff --git a/src/OperationalInsights/OperationalInsights/help/New-AzOperationalInsightsSavedSearch.md b/src/OperationalInsights/OperationalInsights/help/New-AzOperationalInsightsSavedSearch.md index 0e1af7b3f3fa..cfe67dae0138 100644 --- a/src/OperationalInsights/OperationalInsights/help/New-AzOperationalInsightsSavedSearch.md +++ b/src/OperationalInsights/OperationalInsights/help/New-AzOperationalInsightsSavedSearch.md @@ -16,7 +16,7 @@ Creates a new saved search with the specified parameters. ``` New-AzOperationalInsightsSavedSearch [-ResourceGroupName] [-WorkspaceName] [-SavedSearchId] [-DisplayName] [-Category] [-Query] [[-Tag] ] - [[-Version] ] [[-FunctionAlias] ] [[-FunctionParameters] ] [-Force] + [[-Version] ] [[-FunctionAlias] ] [[-FunctionParameter] ] [-Force] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -109,13 +109,13 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -FunctionParameters +### -FunctionParameter The optional function parameters if query serves as a function. Value should be in the following format: 'param-name1:type1 = default_value1, param-name2:type2 = default_value2'. For more examples and proper syntax please refer to https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions. ```yaml Type: System.String Parameter Sets: (All) -Aliases: +Aliases: FunctionParameters Required: False Position: 9 diff --git a/src/OperationalInsights/OperationalInsights/help/Set-AzOperationalInsightsSavedSearch.md b/src/OperationalInsights/OperationalInsights/help/Set-AzOperationalInsightsSavedSearch.md index f7e96a9ae3aa..3ab235986a1a 100644 --- a/src/OperationalInsights/OperationalInsights/help/Set-AzOperationalInsightsSavedSearch.md +++ b/src/OperationalInsights/OperationalInsights/help/Set-AzOperationalInsightsSavedSearch.md @@ -16,7 +16,7 @@ Updates a saved search that already exists. ``` Set-AzOperationalInsightsSavedSearch [-ResourceGroupName] [-WorkspaceName] [-SavedSearchId] [-DisplayName] [-Category] [-Query] [[-Tag] ] - [[-Version] ] [[-ETag] ] [[-FunctionAlias] ] [[-FunctionParameters] ] + [[-Version] ] [[-ETag] ] [[-FunctionAlias] ] [[-FunctionParameter] ] [-DefaultProfile ] [] ``` @@ -109,13 +109,13 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -FunctionParameters +### -FunctionParameter The optional function parameters if query serves as a function. Value should be in the following format: 'param-name1:type1 = default_value1, param-name2:type2 = default_value2'. For more examples and proper syntax please refer to https://docs.microsoft.com/en-us/azure/kusto/query/functions/user-defined-functions. ```yaml Type: System.String Parameter Sets: (All) -Aliases: +Aliases: FunctionParameters Required: False Position: 10