2019-10-06 10:56:59 -04:00
function Get-IcingaDirectorSelfServiceConfig ( )
{
param (
$DirectorUrl ,
$ApiKey = $null
) ;
if ( [ string ] :: IsNullOrEmpty ( $DirectorUrl ) ) {
throw 'Please enter a valid Url to your Icinga Director' ;
}
if ( [ string ] :: IsNullOrEmpty ( $ApiKey ) ) {
2020-03-11 12:53:59 -04:00
throw 'Please enter either a template or your host key. If this message persists, ensure your host is not having a template key assigned already. If so, you can try dropping it within the Icinga Director.' ;
2019-10-06 10:56:59 -04:00
}
$ProgressPreference = " SilentlyContinue " ;
2019-11-02 12:42:39 -04:00
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ( [ string ] :: Format ( '/self-service/powershell-parameters?key={0}' , $ApiKey ) ) ;
2019-10-06 10:56:59 -04:00
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @ { 'accept' = 'application/json' ; 'X-Director-Accept' = 'application/json' } -Method 'POST' ;
if ( $response . StatusCode -ne 200 ) {
throw $response . Content ;
}
$JsonContent = ConvertFrom-Json -InputObject $response . Content ;
if ( Test-PSCustomObjectMember -PSObject $JsonContent -Name 'error' ) {
throw 'Icinga Director Self-Service has thrown an error: ' + $JsonContent . error ;
}
2019-12-12 09:49:56 -05:00
$JsonContent = Add-PSCustomObjectMember -Object $JsonContent -Key 'IcingaMaster' -Value $response . BaseResponse . ResponseUri . Host ;
2019-10-06 10:56:59 -04:00
return $JsonContent ;
}