Diagnostics/Simple/OVF.SharePoint.EnterpriseSearch.Tests.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
function New-HostTemplate{ # Template object for the host array: $hostTemplate = New-Object -TypeName PSObject $hostTemplate | Add-Member -MemberType NoteProperty -Name hostName -Value $null $hostTemplate | Add-Member -MemberType NoteProperty -Name components -Value 0 $hostTemplate | Add-Member -MemberType NoteProperty -Name cpc -Value $null $hostTemplate | Add-Member -MemberType NoteProperty -Name qpc -Value $null $hostTemplate | Add-Member -MemberType NoteProperty -Name pAdmin -Value $null $hostTemplate | Add-Member -MemberType NoteProperty -Name sAdmin -Value $null $hostTemplate | Add-Member -MemberType NoteProperty -Name apc -Value $null $hostTemplate | Add-Member -MemberType NoteProperty -Name crawler -Value $null $hostTemplate | Add-Member -MemberType NoteProperty -Name index -Value $null return $hostTemplate } function New-HATemplate{ # Template object for the HA group array: $haTemplate = New-Object -TypeName PSObject $haTemplate | Add-Member -MemberType NoteProperty -Name entity -Value $null $haTemplate | Add-Member -MemberType NoteProperty -Name partition -Value -1 $haTemplate | Add-Member -MemberType NoteProperty -Name primary -Value $null $haTemplate | Add-Member -MemberType NoteProperty -Name docs -Value 0 $haTemplate | Add-Member -MemberType NoteProperty -Name components -Value 0 $haTemplate | Add-Member -MemberType NoteProperty -Name componentsOk -Value 0 return $haTemplate } function New-ComponentTemplate{ # Template object for the component/server table: $compTemplate = New-Object -TypeName PSObject $compTemplate | Add-Member -MemberType NoteProperty -Name Component -Value $null $compTemplate | Add-Member -MemberType NoteProperty -Name Server -Value $null $compTemplate | Add-Member -MemberType NoteProperty -Name Partition -Value $null $compTemplate | Add-Member -MemberType NoteProperty -Name State -Value $null return $compTemplate } function New-ComponentHAList{ param( $searchComponent ) if ($searchComponent.ServerName) { $hostName = $searchComponent.ServerName } else { $hostName = "Unknown server" } $partition = $searchComponent.IndexPartitionOrdinal $newHostFound = $true $newHaFound = $true $entity = $null foreach ($searchHost in ($script:hostArray)) { if ($searchHost.hostName -eq $hostName) { $newHostFound = $false } } if ($newHostFound) { # Add the host to $script:hostArray $hostTemp = New-HostTemplate $hostTemp.hostName = $hostName $script:hostArray += $hostTemp $script:searchHosts += 1 } # Fill in component specific data in $script:hostArray foreach ($searchHost in ($script:hostArray)) { if ($searchHost.hostName -eq $hostName) { $partition = -1 if ($searchComponent.Name -match "Query") { $entity = "QueryProcessingComponent" $searchHost.qpc = "QueryProcessing " $searchHost.components += 1 } elseif ($searchComponent.Name -match "Content") { $entity = "ContentProcessingComponent" $searchHost.cpc = "ContentProcessing " $searchHost.components += 1 } elseif ($searchComponent.Name -match "Analytics") { $entity = "AnalyticsProcessingComponent" $searchHost.apc = "AnalyticsProcessing " $searchHost.components += 1 } elseif ($searchComponent.Name -match "Admin") { $entity = "AdminComponent" if ($searchComponent.Name -eq $script:primaryAdmin) { $searchHost.pAdmin = "Admin(Primary) " } else { $searchHost.sAdmin = "Admin " } $searchHost.components += 1 } elseif ($searchComponent.Name -match "Crawl") { $entity = "CrawlComponent" $searchHost.crawler = "Crawler " $searchHost.components += 1 } elseif ($searchComponent.Name -match "Index") { $entity = "IndexComponent" $partition = $searchComponent.IndexPartitionOrdinal $searchHost.index = "IndexPartition($partition) " $searchHost.components += 1 } } } # Fill in component specific data in $script:haArray foreach ($haEntity in ($script:haArray)) { if ($haEntity.entity -eq $entity) { if ($entity -eq "IndexComponent") { if ($haEntity.partition -eq $partition) { $newHaFound = $false } } else { $newHaFound = $false } } } if ($newHaFound) { # Add the HA entities to $script:haArray $haTemp = New-HATemplate $haTemp.entity = $entity $haTemp.components = 1 if ($partition -ne -1) { $haTemp.partition = $partition } $script:haArray += $haTemp } else { foreach ($haEntity in ($script:haArray)) { if ($haEntity.entity -eq $entity) { if (($entity -eq "IndexComponent") ) { if ($haEntity.partition -eq $partition) { $haEntity.components += 1 } } else { $haEntity.components += 1 if (($haEntity.entity -eq "AdminComponent") -and ($searchComponent.Name -eq $script:primaryAdmin)) { $haEntity.primary = $script:primaryAdmin } } } } } } function Get-IndexerEvents{ $indexerComps = $script:escss | Where-Object{$_.Name -match "Index" -or $_.Name -match "Content" -or $_.Name -match "Admin" -and $_.Name -notmatch "Cell" -and $_.State -notmatch "Unknown" -and $_.State -notmatch "Registering"} foreach ($component in $indexerComps) { [array]$events += Get-SPEnterpriseSearchStatus -SearchApplication $script:essa -HealthReport -Component $component.Name return $events } } function Test-AnalyticsStatus{ $analyticsStatus = Get-SPEnterpriseSearchStatus -SearchApplication $script:essa -JobStatus foreach ($analyticsEntry in $analyticsStatus) { # Output additional diagnostics from the dictionary foreach ($de in ($analyticsEntry.Details)) { # Skip entries that is listed as Not Available if ( ($de.Value -ne "Not available") -and ($de.Key -ne "Activity") -and ($de.Key -ne "Status") ) { if ($de.Key -match "Last successful start time") { $dLast = Get-Date $de.Value $dNow = Get-Date $daysSinceLastSuccess = $dNow.DayOfYear - $dLast.DayOfYear if ($daysSinceLastSuccess -gt 3) { [array]$analytcsJobNotRunCount += 1 } } } } } return $analytcsJobNotRunCount } Add-PSSnapin Microsoft.SharePoint.Powershell $script:essa = Get-SPEnterpriseSearchServiceApplication $script:esccs = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $script:essa $script:est = Get-SPEnterpriseSearchTopology -SearchApplication $script:essa -Active $script:esc = Get-SPEnterpriseSearchComponent -SearchTopology $script:est $script:ess = Get-SPEnterpriseSearchStatus -SearchApplication $script:essa -JobStatus $script:eshc = Get-SPEnterpriseSearchHostController $script:escss = Get-SPEnterpriseSearchStatus -SearchApplication $script:essa $script:hostArray = @() $script:haArray = @() $script:compArray = @() $script:topologyCompList = Get-SPEnterpriseSearchComponent -SearchTopology $script:est foreach ($component in ($script:esccs)){ if ( ($component.Name -match "Admin") -and ($component.State -ne "Unknown") ){ if (Get-SPEnterpriseSearchStatus -SearchApplication $script:essa -Primary -Component $($component.Name)){ $script:primaryAdmin = $component.Name } } } foreach ($searchComponent in ($script:topologyCompList)) { New-ComponentHAList -searchComponent $searchComponent } $componentEvents = Get-IndexerEvents Describe "Operational Validation of SharePoint 2013 Search Topology"{ It "Enterprise Search Service Application should be Online"{ $script:essa.Status | Should be "Online" } It "All Enterprise Search Components should be Online"{ $offlineComponents = ($script:escss | Where-Object{$_.State -ne "Active"} | Measure-Object).Count $offlineComponents | Should be 0 } It "Indexer, Content Processor and Admin Component should not have Errors"{ $errorEventCount = ($componentEvents | Where-Object{$_.Level -eq "Error"} | Measure-Object).Count $errorEventCount | Should be 0 } It "Indexer, Content Processor and Admin Component should not have Warnings"{ $warningEventCount = ($componentEvents | Where-Object{$_.Level -eq "Warning"} | Measure-Object).Count $warningEventCount | Should be 0 } It "No Component should be on a High Document Count"{ $docsHighCount = ($script:haArray | Where-Object{$_.docs -gt 9000000} | Measure-Object).Count $docsHighCount | Should be 0 } It "No Component should exceed the Healthy Document Count"{ $docsExceededCount = ($script:haArray | Where-Object{$_.docs -gt 10000000}| Measure-Object).Count $docsExceededCount | Should be 0 } It "All Host Controllers should have the same Repository Version"{ $hostControllerCount = ($script:eshc | Measure-Object).Count if($hostControllerCount -eq 1){ $sameVersion = $true } elseif($hostControllerCount -gt 1){ $highestVersion = 0 foreach($hostController in $script:eshc){ if($hostController.Version -gt $highestVersion){ $highestVersion = $hostController.Version } } $hostControllerWithLowerVersionCount = ($script:eshc | Where-Object{$_.Version -lt $highestVersion} | Measure-Object).Count if($hostControllerWithLowerVersionCount = 0){ $sameVersion = $true } else{ $sameVersion = $false } } $sameVersion | Should be true } It "All Analytics Jobs should have Succesfully Run in the last three Days"{ $jobsNotRunCount = Test-AnalyticsStatus $jobsNotRunCount | Should be 0 } It "Enterprise Search Service Application should not be Paused"{ $essaStatus = $script:essa.Ispaused() $essaStatus | Should be 0 } It "All Content Sources should have been successfully crawled in the last 3 days"{ $contentSources = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $global:essa $crawlNotCompletedCount = 0 foreach($contentSource in $contentSources){ $crawlLastCompleted = $contentSource.CrawlCompleted $timeDifference = (Get-Date) - $crawlLastCompleted if($timeDifference.Days -ge 3){ $crawlNotCompletedCount++ } } $crawlNotCompletedCount | Should be 0 } } |