Skip to content

Commit b978ee6

Browse files
committed
Add support for Host-Address for Director Register
Fixes #31
1 parent ce9257a commit b978ee6

5 files changed

+29
-3
lines changed

lib/apis/Get-IcingaDirectorSelfServiceConfig.psm1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ function Get-IcingaDirectorSelfServiceConfig()
2929
throw 'Icinga Director Self-Service has thrown an error: ' + $JsonContent.error;
3030
}
3131

32+
$JsonContent = Add-PSCustomObjectMember -Object $JsonContent -Key 'IcingaMaster' -Value $response.BaseResponse.ResponseUri.Host;
33+
3234
return $JsonContent;
3335
}

lib/apis/Register-IcingaDirectorSelfServiceHost.psm1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ function Register-IcingaDirectorSelfServiceHost()
33
param(
44
$DirectorUrl,
55
$Hostname,
6-
$ApiKey = $null
6+
$ApiKey = $null,
7+
[string]$Endpoint = $null
78
);
89

910
if ([string]::IsNullOrEmpty($DirectorUrl)) {
@@ -19,10 +20,16 @@ function Register-IcingaDirectorSelfServiceHost()
1920
}
2021

2122
$ProgressPreference = "SilentlyContinue";
23+
$DirectorConfigJson = $null;
24+
25+
if ([string]::IsNullOrEmpty($Endpoint) -eq $FALSE) {
26+
$Interface = Get-IcingaNetworkInterface $Endpoint;
27+
$DirectorConfigJson = [string]::Format('{0} "address":"{2}" {1}', '{', '}', $Interface);
28+
}
2229

2330
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/register-host?name={0}&key={1}', $Hostname, $ApiKey));
2431

25-
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST';
32+
$response = Invoke-WebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST' -Body $DirectorConfigJson;
2633

2734
if ($response.StatusCode -ne 200) {
2835
throw $response.Content;

lib/core/icingaagent/misc/Convert-IcingaDirectorSelfServiceArguments.psm1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function Convert-IcingaDirectorSelfServiceArguments()
2020
AddFirewallRule = $JsonInput.agent_add_firewall_rule;
2121
AcceptConnections = $JsonInput.agent_add_firewall_rule;
2222
ServiceUser = $JsonInput.icinga_service_user;
23+
IcingaMaster = $JsonInput.IcingaMaster;
2324
UpdateAgent = $TRUE;
2425
AddDirectorGlobal = $FALSE;
2526
AddGlobalTemplates = $FALSE;

lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function Start-IcingaAgentDirectorWizard()
7676
if ($HostKnown -eq $FALSE) {
7777
while ($TRUE) {
7878
try {
79-
$SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments);
79+
$SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments) -Endpoint $Arguments.IcingaMaster;
8080
break;
8181
} catch {
8282
$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;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function Add-PSCustomObjectMember()
2+
{
3+
param (
4+
$Object,
5+
$Key,
6+
$Value
7+
);
8+
9+
if ($null -eq $Object) {
10+
return $Object;
11+
}
12+
13+
$Object | Add-Member -MemberType NoteProperty -Name $Key -Value $Value;
14+
15+
return $Object;
16+
}

0 commit comments

Comments
 (0)