mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
parent
ce9257a30d
commit
b978ee6574
5 changed files with 29 additions and 3 deletions
|
|
@ -29,5 +29,7 @@ function Get-IcingaDirectorSelfServiceConfig()
|
|||
throw 'Icinga Director Self-Service has thrown an error: ' + $JsonContent.error;
|
||||
}
|
||||
|
||||
$JsonContent = Add-PSCustomObjectMember -Object $JsonContent -Key 'IcingaMaster' -Value $response.BaseResponse.ResponseUri.Host;
|
||||
|
||||
return $JsonContent;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ function Register-IcingaDirectorSelfServiceHost()
|
|||
param(
|
||||
$DirectorUrl,
|
||||
$Hostname,
|
||||
$ApiKey = $null
|
||||
$ApiKey = $null,
|
||||
[string]$Endpoint = $null
|
||||
);
|
||||
|
||||
if ([string]::IsNullOrEmpty($DirectorUrl)) {
|
||||
|
|
@ -19,10 +20,16 @@ function Register-IcingaDirectorSelfServiceHost()
|
|||
}
|
||||
|
||||
$ProgressPreference = "SilentlyContinue";
|
||||
$DirectorConfigJson = $null;
|
||||
|
||||
if ([string]::IsNullOrEmpty($Endpoint) -eq $FALSE) {
|
||||
$Interface = Get-IcingaNetworkInterface $Endpoint;
|
||||
$DirectorConfigJson = [string]::Format('{0} "address":"{2}" {1}', '{', '}', $Interface);
|
||||
}
|
||||
|
||||
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/register-host?name={0}&key={1}', $Hostname, $ApiKey));
|
||||
|
||||
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
|
||||
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST' -Body $DirectorConfigJson;
|
||||
|
||||
if ($response.StatusCode -ne 200) {
|
||||
throw $response.Content;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ function Convert-IcingaDirectorSelfServiceArguments()
|
|||
AddFirewallRule = $JsonInput.agent_add_firewall_rule;
|
||||
AcceptConnections = $JsonInput.agent_add_firewall_rule;
|
||||
ServiceUser = $JsonInput.icinga_service_user;
|
||||
IcingaMaster = $JsonInput.IcingaMaster;
|
||||
UpdateAgent = $TRUE;
|
||||
AddDirectorGlobal = $FALSE;
|
||||
AddGlobalTemplates = $FALSE;
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ function Start-IcingaAgentDirectorWizard()
|
|||
if ($HostKnown -eq $FALSE) {
|
||||
while ($TRUE) {
|
||||
try {
|
||||
$SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments);
|
||||
$SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments) -Endpoint $Arguments.IcingaMaster;
|
||||
break;
|
||||
} catch {
|
||||
$SelfServiceAPIKey = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Failed to register host within Icinga Director. Please re-enter your SelfService API Key. If this prompt continues, drop your host key at "Hosts -> {0} -> Agent"', (Get-IcingaHostname @Arguments))) -Default 'v' -DefaultInput $SelfServiceAPIKey).answer;
|
||||
|
|
|
|||
16
lib/core/tools/Add-PSCustomObjectMember.psm1
Normal file
16
lib/core/tools/Add-PSCustomObjectMember.psm1
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function Add-PSCustomObjectMember()
|
||||
{
|
||||
param (
|
||||
$Object,
|
||||
$Key,
|
||||
$Value
|
||||
);
|
||||
|
||||
if ($null -eq $Object) {
|
||||
return $Object;
|
||||
}
|
||||
|
||||
$Object | Add-Member -MemberType NoteProperty -Name $Key -Value $Value;
|
||||
|
||||
return $Object;
|
||||
}
|
||||
Loading…
Reference in a new issue