Created
October 22, 2020 16:50
-
-
Save Mitya88/f78b0881e42ba6c9eca4dca96669fef4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ExecuteHealthcheck { | |
param( | |
$componentId, | |
[hashtable]$params | |
) | |
$result = @{ } | |
$props = @{ | |
Index = $params["SourceIndex"] | |
ScopeQuery = $params["Query"] | |
} | |
$referenceList = Find-Item @props | |
$referenceLookup = @{} | |
foreach($entry in $referenceList) { | |
$referenceLookup[$entry.ItemId.ToString()] = $entry | |
} | |
$props = @{ | |
Index = $params["TargetIndex"] | |
ScopeQuery = $params["Query"] | |
} | |
$referenceIds = [System.Collections.Generic.List[string]]@() | |
$referenceList | ForEach-Object { $referenceIds.Add($_.ItemId) > $null } | |
$differenceIds = [System.Collections.Generic.List[string]]@() | |
$differenceList | ForEach-Object { $differenceIds.Add($_.ItemId) > $null } | |
$referenceHash = New-Object 'System.Collections.Generic.HashSet[String]' | |
$referenceHash.UnionWith($referenceIds) | |
$differenceHash = New-Object 'System.Collections.Generic.HashSet[String]' | |
$differenceHash.UnionWith($differenceIds) | |
$leftOnlyHash = New-Object 'System.Collections.Generic.HashSet[String]'($referenceHash) | |
$leftOnlyHash.ExceptWith($differenceHash) | |
$missing = $leftOnlyHash | ForEach-Object { $referenceLookup[$_] } | |
if($missing.Count -gt 0){ | |
$result["Status"] = "Error" | |
$result["Reason"] = "There are " + $missing.Count.ToString() + " differences between "+$params["SourceIndex"] + " and "+$params["TargetIndex"] | |
} | |
else{ | |
$result["Status"] = "Healthy" | |
$result["HealthyMessage"] = "There is no differences" | |
} | |
return $result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment