mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -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;
|
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;
|
return $JsonContent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ function Register-IcingaDirectorSelfServiceHost()
|
||||||
param(
|
param(
|
||||||
$DirectorUrl,
|
$DirectorUrl,
|
||||||
$Hostname,
|
$Hostname,
|
||||||
$ApiKey = $null
|
$ApiKey = $null,
|
||||||
|
[string]$Endpoint = $null
|
||||||
);
|
);
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($DirectorUrl)) {
|
if ([string]::IsNullOrEmpty($DirectorUrl)) {
|
||||||
|
|
@ -19,10 +20,16 @@ function Register-IcingaDirectorSelfServiceHost()
|
||||||
}
|
}
|
||||||
|
|
||||||
$ProgressPreference = "SilentlyContinue";
|
$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));
|
$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) {
|
if ($response.StatusCode -ne 200) {
|
||||||
throw $response.Content;
|
throw $response.Content;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ function Convert-IcingaDirectorSelfServiceArguments()
|
||||||
AddFirewallRule = $JsonInput.agent_add_firewall_rule;
|
AddFirewallRule = $JsonInput.agent_add_firewall_rule;
|
||||||
AcceptConnections = $JsonInput.agent_add_firewall_rule;
|
AcceptConnections = $JsonInput.agent_add_firewall_rule;
|
||||||
ServiceUser = $JsonInput.icinga_service_user;
|
ServiceUser = $JsonInput.icinga_service_user;
|
||||||
|
IcingaMaster = $JsonInput.IcingaMaster;
|
||||||
UpdateAgent = $TRUE;
|
UpdateAgent = $TRUE;
|
||||||
AddDirectorGlobal = $FALSE;
|
AddDirectorGlobal = $FALSE;
|
||||||
AddGlobalTemplates = $FALSE;
|
AddGlobalTemplates = $FALSE;
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ function Start-IcingaAgentDirectorWizard()
|
||||||
if ($HostKnown -eq $FALSE) {
|
if ($HostKnown -eq $FALSE) {
|
||||||
while ($TRUE) {
|
while ($TRUE) {
|
||||||
try {
|
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;
|
break;
|
||||||
} catch {
|
} 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;
|
$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