mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2026-02-03 04:09:29 -05:00
Adds support to configure Director Self-Service config string
This commit is contained in:
parent
08bb19673d
commit
100a666e09
7 changed files with 137 additions and 31 deletions
|
|
@ -21,6 +21,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
|||
|
||||
### Enhancements
|
||||
|
||||
* [#544](https://github.com/Icinga/icinga-powershell-framework/issues/544) Adds support to configure the Icinga Director JSON string for registering hosts via self-service API
|
||||
* [#619](https://github.com/Icinga/icinga-powershell-framework/pull/619) Adds feature to securely read enum provider values with new function `Get-IcingaProviderEnumData`
|
||||
* [#623](https://github.com/Icinga/icinga-powershell-framework/issues/623) Adds support to provide the Icinga service user written as `user@domain`
|
||||
* [#635](https://github.com/Icinga/icinga-powershell-framework/pull/635) Adds support for `Write-IcingaAgentApiConfig` function to configure the Icinga Agent TLS cipher list setting by new argument `-CipherList`
|
||||
|
|
|
|||
|
|
@ -61,8 +61,26 @@ function Register-IcingaDirectorSelfServiceHost()
|
|||
}
|
||||
}
|
||||
|
||||
$Interface = Get-IcingaNetworkInterface $Endpoint;
|
||||
$DirectorConfigJson = [string]::Format('{0} "address":"{2}" {1}', '{', '}', $Interface);
|
||||
$Interface = Get-IcingaNetworkInterface $Endpoint;
|
||||
|
||||
if ($null -eq $Global:Icinga.InstallWizard.DirectorSelfServiceConfig) {
|
||||
$DirectorConfigJson = [string]::Format('{{ "address": "{0}" }}', $Interface);
|
||||
} else {
|
||||
try {
|
||||
$DirectorConfigJson = ConvertTo-Json -InputObject $Global:Icinga.InstallWizard.DirectorSelfServiceConfig -Compress -ErrorAction Stop;
|
||||
$DirectorConfigJson = $DirectorConfigJson.Replace('$ifw.hostaddress$', $Interface);
|
||||
$DirectorConfigJson = $DirectorConfigJson.Replace('$ifw.hostname.tolower$', (Get-IcingaHostname -AutoUseHostname 1 -LowerCase 1));
|
||||
$DirectorConfigJson = $DirectorConfigJson.Replace('$ifw.hostname.toupper$', (Get-IcingaHostname -AutoUseHostname 1 -UpperCase 1));
|
||||
$DirectorConfigJson = $DirectorConfigJson.Replace('$ifw.hostname$', (Get-IcingaHostname -AutoUseHostname 1));
|
||||
$DirectorConfigJson = $DirectorConfigJson.Replace('$ifw.hostfqdn.tolower$', (Get-IcingaHostname -AutoUseFQDN 1 -LowerCase 1));
|
||||
$DirectorConfigJson = $DirectorConfigJson.Replace('$ifw.hostfqdn.toupper$', (Get-IcingaHostname -AutoUseFQDN 1 -UpperCase 1));
|
||||
$DirectorConfigJson = $DirectorConfigJson.Replace('$ifw.hostfqdn$', (Get-IcingaHostname -AutoUseFQDN 1));
|
||||
} catch {
|
||||
# Fallback to default
|
||||
Write-IcingaConsosoleError 'Failed to deserialize your custom Icinga Director Self-Service configuration. Using Icinga for Windows defaults.'
|
||||
$DirectorConfigJson = [string]::Format('{{ "address": "{0}" }}', $Interface);
|
||||
}
|
||||
}
|
||||
|
||||
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/register-host?name={0}&key={1}', $Hostname, $ApiKey));
|
||||
|
||||
|
|
|
|||
|
|
@ -21,34 +21,35 @@ function Install-Icinga()
|
|||
if ($global:Icinga.ContainsKey('InstallWizard') -eq $FALSE) {
|
||||
$global:Icinga.Add(
|
||||
'InstallWizard', @{
|
||||
'AdminShell' = (Test-AdministrativeShell);
|
||||
'LastInput' = '';
|
||||
'LastNotice' = '';
|
||||
'LastWarning' = @();
|
||||
'LastError' = @();
|
||||
'DirectorError' = '';
|
||||
'HeaderPreview' = '';
|
||||
'DirectorSelfService' = $FALSE;
|
||||
'DirectorRegisteredHost' = $FALSE;
|
||||
'DirectorInstallError' = $FALSE;
|
||||
'LastParent' = [System.Collections.ArrayList]@();
|
||||
'LastValues' = @();
|
||||
'DisabledEntries' = @{ };
|
||||
'Config' = @{ };
|
||||
'ConfigSwap' = @{ };
|
||||
'ParentConfig' = $null;
|
||||
'Menu' = 'Install-Icinga';
|
||||
'NextCommand' = '';
|
||||
'NextArguments' = $null;
|
||||
'HeaderSelection' = $null;
|
||||
'DisplayAdvanced' = $FALSE;
|
||||
'ShowAdvanced' = $FALSE;
|
||||
'ShowHelp' = $FALSE;
|
||||
'ShowCommand' = $FALSE;
|
||||
'DeleteValues' = $FALSE;
|
||||
'HeaderPrint' = $FALSE;
|
||||
'JumpToSummary' = $FALSE;
|
||||
'Closing' = $FALSE;
|
||||
'AdminShell' = (Test-AdministrativeShell);
|
||||
'LastInput' = '';
|
||||
'LastNotice' = '';
|
||||
'LastWarning' = @();
|
||||
'LastError' = @();
|
||||
'DirectorError' = '';
|
||||
'HeaderPreview' = '';
|
||||
'DirectorSelfServiceConfig' = $null;
|
||||
'DirectorSelfService' = $FALSE;
|
||||
'DirectorRegisteredHost' = $FALSE;
|
||||
'DirectorInstallError' = $FALSE;
|
||||
'LastParent' = [System.Collections.ArrayList]@();
|
||||
'LastValues' = @();
|
||||
'DisabledEntries' = @{ };
|
||||
'Config' = @{ };
|
||||
'ConfigSwap' = @{ };
|
||||
'ParentConfig' = $null;
|
||||
'Menu' = 'Install-Icinga';
|
||||
'NextCommand' = '';
|
||||
'NextArguments' = $null;
|
||||
'HeaderSelection' = $null;
|
||||
'DisplayAdvanced' = $FALSE;
|
||||
'ShowAdvanced' = $FALSE;
|
||||
'ShowHelp' = $FALSE;
|
||||
'ShowCommand' = $FALSE;
|
||||
'DeleteValues' = $FALSE;
|
||||
'HeaderPrint' = $FALSE;
|
||||
'JumpToSummary' = $FALSE;
|
||||
'Closing' = $FALSE;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ function Add-IcingaForWindowsInstallationAdvancedEntries()
|
|||
Show-IcingaForWindowsInstallationMenuEnterIcingaCAServer -Automated -Advanced;
|
||||
Show-IcingaForWindowsInstallerMenuSelectInstallApiChecks -Automated -Advanced;
|
||||
Show-IcingaForWindowsInstallerMenuSelectServiceRecovery -Automated -Advanced;
|
||||
Show-IcingaForWindowsManagementConsoleInstallationEnterDirectorSelfServiceConfig -Automated -Advanced;
|
||||
|
||||
Enable-IcingaFrameworkConsoleOutput;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
function Show-IcingaForWindowsManagementConsoleInstallationEnterDirectorSelfServiceConfig()
|
||||
{
|
||||
param (
|
||||
[array]$Value = @(),
|
||||
[string]$DefaultInput = 'c',
|
||||
[switch]$JumpToSummary = $FALSE,
|
||||
[switch]$Automated = $FALSE,
|
||||
[switch]$Advanced = $FALSE
|
||||
);
|
||||
|
||||
# Ensure we simply set the global variable for the Config in case we run in automation mode
|
||||
if ($Automated) {
|
||||
if ($null -ne $Value -And $null -ne $Value[0]) {
|
||||
$Global:Icinga.InstallWizard.DirectorSelfServiceConfig = ConvertFrom-Json -InputObject $Value[0] -ErrorAction Stop;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
# Set the default if no value ist set
|
||||
if ($Value -IsNot [array] -Or $null -eq $Value -or $Value.Count -eq 0) {
|
||||
$Value.Clear();
|
||||
if ($null -eq $Global:Icinga.InstallWizard.DirectorSelfServiceConfig) {
|
||||
$Value += '{ "address": "$ifw.hostaddress$" }';
|
||||
} else {
|
||||
$Value += ConvertTo-Json -InputObject $Global:Icinga.InstallWizard.DirectorSelfServiceConfig -Depth 100 -Compress;
|
||||
}
|
||||
}
|
||||
|
||||
Show-IcingaForWindowsInstallerMenu `
|
||||
-Header 'You can update the Icinga Director Self-Service config in this section. USE WITH CARE!' `
|
||||
-Entries @(
|
||||
@{
|
||||
'Command' = 'Show-IcingaForWindowsInstallerConfigurationSummary';
|
||||
'Help' = 'This is the configuration JSON-Object for the Icinga Director Self-Service API. You can set a custom IP-Address or define the display name of an object with "display_name" as key. Use this methid with caution! Not all configuration elements in general possible are accessible by using the Self-Service keys.';
|
||||
}
|
||||
) `
|
||||
-DefaultIndex $DefaultInput `
|
||||
-AddConfig `
|
||||
-ConfigLimit 1 `
|
||||
-DefaultValues @( $Value ) `
|
||||
-MandatoryValue `
|
||||
-JumpToSummary:$JumpToSummary `
|
||||
-ConfigElement `
|
||||
-Automated:$Automated `
|
||||
-Advanced:$Advanced;
|
||||
|
||||
# Fetch the current JSON-String inserted by the user
|
||||
[string]$ConfigString = Get-IcingaForWindowsInstallerValuesFromStep;
|
||||
|
||||
if ([string]::IsNullOrEmpty($ConfigString) -eq $FALSE) {
|
||||
try {
|
||||
# Validate that our JSON is correct
|
||||
$Global:Icinga.InstallWizard.DirectorSelfServiceConfig = ConvertFrom-Json -InputObject $ConfigString -ErrorAction Stop;
|
||||
} catch {
|
||||
# Set some defaults to ensure we don't break the installer
|
||||
Write-IcingaConsoleError ([string]::Format('The provided Icinga Director Self Service configuration "{0}" does not appear to be a valid JSON-String. E.g.: {{ "address": "$ifw.hostaddress$" }} without leading and ending "" before and after {{ }}', $ConfigString));
|
||||
$Global:Icinga.InstallWizard.DirectorSelfServiceConfig = $null;
|
||||
Set-IcingaForWindowsInstallerValuesFromStep -Values @( '{ }' );
|
||||
}
|
||||
} else {
|
||||
$Global:Icinga.InstallWizard.DirectorSelfServiceConfig = $null;
|
||||
}
|
||||
}
|
||||
|
||||
Set-Alias -Name 'IfW-DirectorSelfServiceConfig' -Value 'Show-IcingaForWindowsManagementConsoleInstallationEnterDirectorSelfServiceConfig';
|
||||
|
|
@ -16,7 +16,7 @@ function Invoke-IcingaForWindowsManagementConsoleCustomConfig()
|
|||
}
|
||||
|
||||
if ($cmdConfig.ContainsKey('Values') -And $null -ne $cmdConfig.Values) {
|
||||
$cmdArguments.Add('Value', $cmdConfig.Values)
|
||||
$cmdArguments.Add('Value', $cmdConfig.Values);
|
||||
}
|
||||
if ($cmdConfig.ContainsKey('Selection') -And $null -ne $cmdConfig.Selection) {
|
||||
$cmdArguments.Add('DefaultInput', $cmdConfig.Selection)
|
||||
|
|
|
|||
20
lib/core/installer/tools/SetValuesFromStep.psm1
Normal file
20
lib/core/installer/tools/SetValuesFromStep.psm1
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function Set-IcingaForWindowsInstallerValuesFromStep()
|
||||
{
|
||||
param (
|
||||
[string]$InstallerStep,
|
||||
[string]$Parent,
|
||||
[array]$Values = @()
|
||||
);
|
||||
|
||||
$Step = Get-IcingaForWindowsManagementConsoleMenu;
|
||||
|
||||
if ([string]::IsNullOrEmpty($InstallerStep) -eq $FALSE) {
|
||||
$Step = Get-IcingaForWindowsManagementConsoleAlias -Command $InstallerStep;
|
||||
|
||||
if ([string]::IsNullOrEmpty($Parent) -eq $FALSE) {
|
||||
$Step = [string]::Format('{0}:{1}', $Step, $Parent);
|
||||
}
|
||||
}
|
||||
|
||||
$global:Icinga.InstallWizard.Config[$Step].Values = $Values;
|
||||
}
|
||||
Loading…
Reference in a new issue