icinga-powershell-framework/lib/apis/Get-IcingaDirectorSelfServiceConfig.psm1

34 lines
1 KiB
PowerShell
Raw Normal View History

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)) {
throw 'Please enter either a template or your host key';
}
$ProgressPreference = "SilentlyContinue";
$EndpointUrl = [string]::Format('{0}/self-service/powershell-parameters?key={1}', $DirectorUrl, $ApiKey);
$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;
}
return $JsonContent;
}