mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Added Cmdlets to talk to Icinga Director Self-Service API
This commit is contained in:
parent
09a681609d
commit
b6a1d91d78
2 changed files with 71 additions and 0 deletions
33
lib/apis/Get-IcingaDirectorSelfServiceConfig.psm1
Normal file
33
lib/apis/Get-IcingaDirectorSelfServiceConfig.psm1
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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;
|
||||
}
|
||||
38
lib/apis/Register-IcingaDirectorSelfServiceHost.psm1
Normal file
38
lib/apis/Register-IcingaDirectorSelfServiceHost.psm1
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
function Register-IcingaDirectorSelfServiceHost()
|
||||
{
|
||||
param(
|
||||
$DirectorUrl,
|
||||
$Hostname,
|
||||
$ApiKey = $null
|
||||
);
|
||||
|
||||
if ([string]::IsNullOrEmpty($DirectorUrl)) {
|
||||
throw 'Please enter a valid Url to your Icinga Director';
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($Hostname)) {
|
||||
throw 'Please enter the hostname to use';
|
||||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($ApiKey)) {
|
||||
throw 'Please enter the API key of the template you wish to use';
|
||||
}
|
||||
|
||||
$ProgressPreference = "SilentlyContinue";
|
||||
|
||||
$EndpointUrl = [string]::Format('{0}/self-service/register-host?name={1}&key={2}', $DirectorUrl, $Hostname, $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;
|
||||
}
|
||||
Loading…
Reference in a new issue