PrivateFunctions/Get-ApiChecksToUpload.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 |
<#
Prepare DQ Monitor Api check objects to upload. #> Function Get-ApiChecksToUpload { [OutputType([Array])] [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] [String] $CheckJsonRaw, [Parameter(Mandatory=$True)] [ValidateNotNullOrEmpty()] [String] $CheckStatementRootPath ) Write-Verbose "Voorbereiden requests naar de server..." $CheckJsonObject = $CheckJsonRaw | ConvertFrom-Json $ChecksToUpload = @() If ($CheckJsonObject.checks.Count -eq 0) { Return $ChecksToUpload; } # First get information about available entities. [Array]$Entities = Get-DqEntities ForEach($CustomCheck in $CheckJsonObject.checks) { $StatementFile = $CustomCheck.statementFile If (-not([System.IO.Path]::IsPathRooted($StatementFile))) { $StatementFile = Join-Path -Path $CheckStatementRootPath -ChildPath $StatementFile } If (-not(Test-Path -Path $StatementFile -PathType Leaf)) { Write-Warning "T-SQL statement bestand '$($StatementFile)' kon niet worden gevonden." Write-Warning "Controle $($CustomCheck.name)' zal worden overgeslagen." Continue; } $Statement = [String](Get-Content -Path $StatementFile -Raw -ErrorAction Stop) $EntityId = -1; If ([Int]::TryParse($CustomCheck.entity, [ref]$EntityId)) { $EntityId = [Int]$CustomCheck.entity } Else { Write-Verbose "Opzoeken id voor entiteit '$($CustomCheck.entity)'..." $Entity = $Entities | Where-Object { $_.Name -eq $CustomCheck.entity } If (-not($Entity)) { Write-Warning "Opgegeven entiteit '$($CustomCheck.entity)' kon niet gevonden worden op de server. Neem contact op met een CNS consultant om deze entiteit op te voeren." Write-Warning "Controle '$($CustomCheck.name)' zal worden overgeslagen." Continue; } $EntityId = $Entity.Id } Try { $ChecksToUpload += [PSCustomObject]@{ check = @{ name = $CustomCheck.name; entityId = $EntityId; tags = $(If ($CustomCheck.PSObject.Properties.name -match "tags") { $CustomCheck.tags } Else { @() }); documentation = [PSCustomObject]@{ caption = $CustomCheck.caption; description = $CustomCheck.description; technicalDescription = $CustomCheck.technicalDescription; }; resultCaptionIsSensitive = $(If ($CustomCheck.PSObject.Properties.name -match "isSensitive") { $CustomCheck.isSensitive } Else { $false }); source = $CustomCheck.source; statement = $Statement; } } } Catch { Write-Warning "Er is een fout opgetreden bij het voorbereiden van controle '$($CustomCheck.name)'. Controleer de syntax van het bestand." Write-Warning "Deze controle wordt genegeerd." Continue; } } Return $ChecksToUpload; } |