mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
parent
c7c2ef8c22
commit
58c6d0fd7d
2 changed files with 42 additions and 10 deletions
|
|
@ -40,5 +40,7 @@ function Register-IcingaDirectorSelfServiceHost()
|
||||||
|
|
||||||
Set-IcingaPowerShellConfig -Path 'IcingaDirector.SelfService.ApiKey' -Value $JsonContent;
|
Set-IcingaPowerShellConfig -Path 'IcingaDirector.SelfService.ApiKey' -Value $JsonContent;
|
||||||
|
|
||||||
|
Write-Host 'Host was successfully registered within Icinga Director';
|
||||||
|
|
||||||
return $JsonContent;
|
return $JsonContent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ function Start-IcingaAgentDirectorWizard()
|
||||||
[string]$DirectorUrl,
|
[string]$DirectorUrl,
|
||||||
[string]$SelfServiceAPIKey = $null,
|
[string]$SelfServiceAPIKey = $null,
|
||||||
$OverrideDirectorVars = $null,
|
$OverrideDirectorVars = $null,
|
||||||
[bool]$RunInstaller = $FALSE
|
[bool]$RunInstaller = $FALSE,
|
||||||
|
[switch]$ForceTemplateKey
|
||||||
);
|
);
|
||||||
|
|
||||||
[hashtable]$DirectorOverrideArgs = @{}
|
[hashtable]$DirectorOverrideArgs = @{}
|
||||||
|
|
@ -23,22 +24,44 @@ function Start-IcingaAgentDirectorWizard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$SelfServiceAPIKey = Get-IcingaPowerShellConfig -Path 'IcingaDirector.SelfService.ApiKey';
|
$LocalAPIKey = Get-IcingaPowerShellConfig -Path 'IcingaDirector.SelfService.ApiKey';
|
||||||
if ([string]::IsNullOrEmpty($SelfServiceAPIKey)) {
|
|
||||||
$LegacyTokenPath = Join-Path -Path Get-IcingaAgentConfigDirectory -ChildPath 'icingadirector.token';
|
if ($ForceTemplateKey) {
|
||||||
if (Test-Path $LegacyTokenPath) {
|
if ($SelfServiceAPIKey -eq $LocalAPIKey) {
|
||||||
$SelfServiceAPIKey = Get-Content -Path $LegacyTokenPath;
|
$ForceTemplateKey = $FALSE;
|
||||||
Set-IcingaPowerShellConfig -Path 'IcingaDirector.SelfService.ApiKey' -Value $SelfServiceAPIKey;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ForceTemplateKey -eq $FALSE) {
|
||||||
|
$SelfServiceAPIKey = $LocalAPIKey;
|
||||||
|
if ([string]::IsNullOrEmpty($SelfServiceAPIKey)) {
|
||||||
|
$LegacyTokenPath = Join-Path -Path Get-IcingaAgentConfigDirectory -ChildPath 'icingadirector.token';
|
||||||
|
if (Test-Path $LegacyTokenPath) {
|
||||||
|
$SelfServiceAPIKey = Get-Content -Path $LegacyTokenPath;
|
||||||
|
Set-IcingaPowerShellConfig -Path 'IcingaDirector.SelfService.ApiKey' -Value $SelfServiceAPIKey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($SelfServiceAPIKey)) {
|
if ([string]::IsNullOrEmpty($SelfServiceAPIKey)) {
|
||||||
$SelfServiceAPIKey = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter your Self-Service API key' -Default 'v').answer;
|
$SelfServiceAPIKey = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter your Self-Service API key' -Default 'v').answer;
|
||||||
} else {
|
} else {
|
||||||
$HostKnown = $TRUE;
|
if ($ForceTemplateKey -eq $FALSE) {
|
||||||
|
$HostKnown = $TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey;
|
||||||
|
} catch {
|
||||||
|
Write-Host ([string]::Format('Failed to connect to your Icinga Director at "{0}". Please try again', $DirectorUrl));
|
||||||
|
|
||||||
|
return Start-IcingaAgentDirectorWizard `
|
||||||
|
-SelfServiceAPIKey ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Please re-enter your SelfService API Key for the Host-Template in case the key is no longer assigned to your host' -Default 'v' -DefaultInput $SelfServiceAPIKey).answer) `
|
||||||
|
-OverrideDirectorVars $OverrideDirectorVars `
|
||||||
|
-ForceTemplateKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
$Arguments = Get-IcingaDirectorSelfServiceConfig -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey;
|
|
||||||
$Arguments = Convert-IcingaDirectorSelfServiceArguments -JsonInput $Arguments;
|
$Arguments = Convert-IcingaDirectorSelfServiceArguments -JsonInput $Arguments;
|
||||||
|
|
||||||
if ($OverrideDirectorVars -eq $TRUE -And -Not $RunInstaller) {
|
if ($OverrideDirectorVars -eq $TRUE -And -Not $RunInstaller) {
|
||||||
|
|
@ -51,7 +74,14 @@ function Start-IcingaAgentDirectorWizard()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($HostKnown -eq $FALSE) {
|
if ($HostKnown -eq $FALSE) {
|
||||||
$SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments);
|
while ($TRUE) {
|
||||||
|
try {
|
||||||
|
$SelfServiceAPIKey = Register-IcingaDirectorSelfServiceHost -DirectorUrl $DirectorUrl -ApiKey $SelfServiceAPIKey -Hostname (Get-IcingaHostname @Arguments);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Host is already registered
|
# Host is already registered
|
||||||
if ($null -eq $SelfServiceAPIKey) {
|
if ($null -eq $SelfServiceAPIKey) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue