Skip to content

Adds Search and SavedSearch powershell cmdlets #1661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@
<Reference Include="Microsoft.Azure.Gallery">
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.OperationalInsights">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.OperationalInsights.0.10.0-preview\lib\net40\Microsoft.Azure.Management.OperationalInsights.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.OperationalInsights, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Management.OperationalInsights.0.11.0-preview\lib\net40\Microsoft.Azure.Management.OperationalInsights.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -155,6 +156,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScenarioTests\SearchTests.cs" />
<Compile Include="ScenarioTests\StorageInsightTests.cs" />
<Compile Include="ScenarioTests\WorkspaceTests.cs" />
<Compile Include="ScenarioTests\OperationalInsightsScenarioTestBase.cs" />
Expand All @@ -167,12 +169,27 @@
<None Include="ScenarioTests\Common.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\SearchTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\StorageInsightTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ScenarioTests\WorkspaceTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.SearchTests\TestSearchGetSavedSearchesAndResults.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.SearchTests\TestSearchGetSchema.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.SearchTests\TestSearchGetSearchResultsAndUpdate.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.SearchTests\TestSearchSetAndRemoveSavedSearches.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.StorageInsightTests\TestStorageInsightCreateFailsWithoutWorkspace.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;

namespace Microsoft.Azure.Commands.OperationalInsights.Test
{
public class SearchTests : OperationalInsightsScenarioTestBase
{
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSearchGetSchema()
{
RunPowerShellTest("Test-SearchGetSchema");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSearchGetSearchResultsAndUpdate()
{
RunPowerShellTest("Test-SearchGetSearchResultsAndUpdate");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSearchGetSavedSearchesAndResults()
{
RunPowerShellTest("Test-SearchGetSavedSearchesAndResults");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSearchSetAndRemoveSavedSearches()
{
RunPowerShellTest("Test-SearchSetAndRemoveSavedSearches");
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Get and update search results
#>
function Test-SearchGetSearchResultsAndUpdate
{
$rgname = "OI-Default-East-US"
$wsname = "rasha"

$top = 25

$searchResult = Get-AzureRmOperationalInsightsSearchResults -ResourceGroupName $rgname -WorkspaceName $wsname -Top $top -Query "*"

Assert-NotNull $searchResult
Assert-NotNull $searchResult.Metadata
Assert-NotNull $searchResult.Value
Assert-AreEqual $searchResult.Value.Count $top

$idArray = $searchResult.Id.Split("/")
$id = $idArray[$idArray.Length-1]
$updatedResult = Get-AzureRmOperationalInsightsSearchResults -ResourceGroupName $rgname -WorkspaceName $wsname -Id $id

Assert-NotNull $updatedResult
Assert-NotNull $updatedResult.Metadata
Assert-NotNull $searchResult.Value
}

<#
.SYNOPSIS
Get schemas for a given workspace
#>
function Test-SearchGetSchema
{
$rgname = "mms-eus"
$wsname = "workspace-861bd466-5400-44be-9552-5ba40823c3aa"

$schema = Get-AzureRmOperationalInsightsSchema -ResourceGroupName $rgname -WorkspaceName $wsname
Assert-NotNull $schema
Assert-NotNull $schema.Metadata
Assert-AreEqual $schema.Metadata.ResultType "schema"
Assert-NotNull $schema.Value
}

<#
.SYNOPSIS
Get saved searches and search results from a saved search
#>
function Test-SearchGetSavedSearchesAndResults
{
$rgname = "mms-eus"
$wsname = "workspace-861bd466-5400-44be-9552-5ba40823c3aa"

$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname

Assert-NotNull $savedSearches
Assert-NotNull $savedSearches.Value

$idArray = $savedSearches.Value[0].Id.Split("/")
$id = $idArray[$idArray.Length-1]

$savedSearch = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id

Assert-NotNull $savedSearch
Assert-NotNull $savedSearch.ETag
Assert-NotNull $savedSearch.Id
Assert-NotNull $savedSearch.Properties
Assert-NotNull $savedSearch.Properties.Query

$savedSearchResult = Get-AzureRmOperationalInsightsSavedSearchResults -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id

Assert-NotNull $savedSearchResult
Assert-NotNull $savedSearchResult.Metadata
Assert-NotNull $savedSearchResult.Value
}

<#
.SYNOPSIS
Create a new saved search, update, and then remove it
#>
function Test-SearchSetAndRemoveSavedSearches
{
$rgname = "mms-eus"
$wsname = "workspace-861bd466-5400-44be-9552-5ba40823c3aa"

$id = "test-new-saved-search-id-2015"
$displayName = "TestingSavedSearch"
$category = "Saved Search Test Category"
$version = 1
$query = "* | measure Count() by Type"

# Get the count of saved searches
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
$count = $savedSearches.Value.Count
$newCount = $count + 1

New-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id -DisplayName $displayName -Category $category -Query $query -Version $version -Force

# Check that the search was saved
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
Assert-AreEqual $savedSearches.Value.Count $newCount

$etag = ""
ForEach ($s in $savedSearches.Value)
{
If ($s.Properties.DisplayName.Equals($displayName)) {
$etag = $s.ETag
}
}

# Test updating the search
$query = "*"
Set-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id -DisplayName $displayName -Category $category -Query $query -Version $version -ETag $etag

# Check that the search was updated
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
Assert-AreEqual $savedSearches.Value.Count $newCount

$found = 0
ForEach ($s in $savedSearches.Value)
{
If ($s.Properties.DisplayName.Equals($displayName) -And $s.Properties.Query.Equals($query)) {
$found = 1
}
}
Assert-AreEqual $found 1


Remove-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id -Force

# Check that the search was deleted
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
Assert-AreEqual $savedSearches.Value.Count $count
}
Loading