Skip to content

Commit 1375ab7

Browse files
author
Hovsep
committed
Merge pull request Azure#1661 from independentwork/dev
Adds Search and SavedSearch powershell cmdlets
2 parents 6e49043 + 793c806 commit 1375ab7

37 files changed

+2371
-29
lines changed

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/Commands.OperationalInsights.Test.csproj

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@
6060
<Reference Include="Microsoft.Azure.Gallery">
6161
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
6262
</Reference>
63-
<Reference Include="Microsoft.Azure.Management.OperationalInsights">
64-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.OperationalInsights.0.10.0-preview\lib\net40\Microsoft.Azure.Management.OperationalInsights.dll</HintPath>
63+
<Reference Include="Microsoft.Azure.Management.OperationalInsights, Version=0.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
64+
<SpecificVersion>False</SpecificVersion>
65+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.OperationalInsights.0.11.0-preview\lib\net40\Microsoft.Azure.Management.OperationalInsights.dll</HintPath>
6566
</Reference>
6667
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6768
<SpecificVersion>False</SpecificVersion>
@@ -155,6 +156,7 @@
155156
</ItemGroup>
156157
<ItemGroup>
157158
<Compile Include="Properties\AssemblyInfo.cs" />
159+
<Compile Include="ScenarioTests\SearchTests.cs" />
158160
<Compile Include="ScenarioTests\StorageInsightTests.cs" />
159161
<Compile Include="ScenarioTests\WorkspaceTests.cs" />
160162
<Compile Include="ScenarioTests\OperationalInsightsScenarioTestBase.cs" />
@@ -167,12 +169,27 @@
167169
<None Include="ScenarioTests\Common.ps1">
168170
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
169171
</None>
172+
<None Include="ScenarioTests\SearchTests.ps1">
173+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
174+
</None>
170175
<None Include="ScenarioTests\StorageInsightTests.ps1">
171176
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
172177
</None>
173178
<None Include="ScenarioTests\WorkspaceTests.ps1">
174179
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
175180
</None>
181+
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.SearchTests\TestSearchGetSavedSearchesAndResults.json">
182+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
183+
</None>
184+
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.SearchTests\TestSearchGetSchema.json">
185+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
186+
</None>
187+
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.SearchTests\TestSearchGetSearchResultsAndUpdate.json">
188+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
189+
</None>
190+
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.SearchTests\TestSearchSetAndRemoveSavedSearches.json">
191+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
192+
</None>
176193
<None Include="SessionRecords\Microsoft.Azure.Commands.OperationalInsights.Test.StorageInsightTests\TestStorageInsightCreateFailsWithoutWorkspace.json">
177194
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
178195
</None>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.Azure.Commands.OperationalInsights.Test
19+
{
20+
public class SearchTests : OperationalInsightsScenarioTestBase
21+
{
22+
[Fact]
23+
[Trait(Category.AcceptanceType, Category.CheckIn)]
24+
public void TestSearchGetSchema()
25+
{
26+
RunPowerShellTest("Test-SearchGetSchema");
27+
}
28+
29+
[Fact]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
public void TestSearchGetSearchResultsAndUpdate()
32+
{
33+
RunPowerShellTest("Test-SearchGetSearchResultsAndUpdate");
34+
}
35+
36+
[Fact]
37+
[Trait(Category.AcceptanceType, Category.CheckIn)]
38+
public void TestSearchGetSavedSearchesAndResults()
39+
{
40+
RunPowerShellTest("Test-SearchGetSavedSearchesAndResults");
41+
}
42+
43+
[Fact]
44+
[Trait(Category.AcceptanceType, Category.CheckIn)]
45+
public void TestSearchSetAndRemoveSavedSearches()
46+
{
47+
RunPowerShellTest("Test-SearchSetAndRemoveSavedSearches");
48+
}
49+
50+
}
51+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Get and update search results
18+
#>
19+
function Test-SearchGetSearchResultsAndUpdate
20+
{
21+
$rgname = "OI-Default-East-US"
22+
$wsname = "rasha"
23+
24+
$top = 25
25+
26+
$searchResult = Get-AzureRmOperationalInsightsSearchResults -ResourceGroupName $rgname -WorkspaceName $wsname -Top $top -Query "*"
27+
28+
Assert-NotNull $searchResult
29+
Assert-NotNull $searchResult.Metadata
30+
Assert-NotNull $searchResult.Value
31+
Assert-AreEqual $searchResult.Value.Count $top
32+
33+
$idArray = $searchResult.Id.Split("/")
34+
$id = $idArray[$idArray.Length-1]
35+
$updatedResult = Get-AzureRmOperationalInsightsSearchResults -ResourceGroupName $rgname -WorkspaceName $wsname -Id $id
36+
37+
Assert-NotNull $updatedResult
38+
Assert-NotNull $updatedResult.Metadata
39+
Assert-NotNull $searchResult.Value
40+
}
41+
42+
<#
43+
.SYNOPSIS
44+
Get schemas for a given workspace
45+
#>
46+
function Test-SearchGetSchema
47+
{
48+
$rgname = "mms-eus"
49+
$wsname = "workspace-861bd466-5400-44be-9552-5ba40823c3aa"
50+
51+
$schema = Get-AzureRmOperationalInsightsSchema -ResourceGroupName $rgname -WorkspaceName $wsname
52+
Assert-NotNull $schema
53+
Assert-NotNull $schema.Metadata
54+
Assert-AreEqual $schema.Metadata.ResultType "schema"
55+
Assert-NotNull $schema.Value
56+
}
57+
58+
<#
59+
.SYNOPSIS
60+
Get saved searches and search results from a saved search
61+
#>
62+
function Test-SearchGetSavedSearchesAndResults
63+
{
64+
$rgname = "mms-eus"
65+
$wsname = "workspace-861bd466-5400-44be-9552-5ba40823c3aa"
66+
67+
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
68+
69+
Assert-NotNull $savedSearches
70+
Assert-NotNull $savedSearches.Value
71+
72+
$idArray = $savedSearches.Value[0].Id.Split("/")
73+
$id = $idArray[$idArray.Length-1]
74+
75+
$savedSearch = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id
76+
77+
Assert-NotNull $savedSearch
78+
Assert-NotNull $savedSearch.ETag
79+
Assert-NotNull $savedSearch.Id
80+
Assert-NotNull $savedSearch.Properties
81+
Assert-NotNull $savedSearch.Properties.Query
82+
83+
$savedSearchResult = Get-AzureRmOperationalInsightsSavedSearchResults -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id
84+
85+
Assert-NotNull $savedSearchResult
86+
Assert-NotNull $savedSearchResult.Metadata
87+
Assert-NotNull $savedSearchResult.Value
88+
}
89+
90+
<#
91+
.SYNOPSIS
92+
Create a new saved search, update, and then remove it
93+
#>
94+
function Test-SearchSetAndRemoveSavedSearches
95+
{
96+
$rgname = "mms-eus"
97+
$wsname = "workspace-861bd466-5400-44be-9552-5ba40823c3aa"
98+
99+
$id = "test-new-saved-search-id-2015"
100+
$displayName = "TestingSavedSearch"
101+
$category = "Saved Search Test Category"
102+
$version = 1
103+
$query = "* | measure Count() by Type"
104+
105+
# Get the count of saved searches
106+
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
107+
$count = $savedSearches.Value.Count
108+
$newCount = $count + 1
109+
110+
New-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id -DisplayName $displayName -Category $category -Query $query -Version $version -Force
111+
112+
# Check that the search was saved
113+
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
114+
Assert-AreEqual $savedSearches.Value.Count $newCount
115+
116+
$etag = ""
117+
ForEach ($s in $savedSearches.Value)
118+
{
119+
If ($s.Properties.DisplayName.Equals($displayName)) {
120+
$etag = $s.ETag
121+
}
122+
}
123+
124+
# Test updating the search
125+
$query = "*"
126+
Set-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id -DisplayName $displayName -Category $category -Query $query -Version $version -ETag $etag
127+
128+
# Check that the search was updated
129+
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
130+
Assert-AreEqual $savedSearches.Value.Count $newCount
131+
132+
$found = 0
133+
ForEach ($s in $savedSearches.Value)
134+
{
135+
If ($s.Properties.DisplayName.Equals($displayName) -And $s.Properties.Query.Equals($query)) {
136+
$found = 1
137+
}
138+
}
139+
Assert-AreEqual $found 1
140+
141+
142+
Remove-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname -SavedSearchId $id -Force
143+
144+
# Check that the search was deleted
145+
$savedSearches = Get-AzureRmOperationalInsightsSavedSearch -ResourceGroupName $rgname -WorkspaceName $wsname
146+
Assert-AreEqual $savedSearches.Value.Count $count
147+
}

0 commit comments

Comments
 (0)