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