mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Adds defaults to certain steps and FQDN to IP conversion
This commit is contained in:
parent
d983f6f767
commit
7961a0d0d1
2 changed files with 89 additions and 6 deletions
|
|
@ -16,6 +16,7 @@ function Start-IcingaAgentInstallWizard()
|
||||||
$AcceptConnections = $null,
|
$AcceptConnections = $null,
|
||||||
[array]$Endpoints = @(),
|
[array]$Endpoints = @(),
|
||||||
[array]$EndpointConnections = @(),
|
[array]$EndpointConnections = @(),
|
||||||
|
$ConvertEndpointIPConfig = $null,
|
||||||
[string]$ParentZone,
|
[string]$ParentZone,
|
||||||
[array]$GlobalZones = $null,
|
[array]$GlobalZones = $null,
|
||||||
[string]$CAEndpoint,
|
[string]$CAEndpoint,
|
||||||
|
|
@ -218,7 +219,7 @@ function Start-IcingaAgentInstallWizard()
|
||||||
|
|
||||||
if ($UpdateAgent -eq 1) {
|
if ($UpdateAgent -eq 1) {
|
||||||
if ([string]::IsNullOrEmpty($AgentVersion)) {
|
if ([string]::IsNullOrEmpty($AgentVersion)) {
|
||||||
$AgentVersion = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the version you wish to install ("latest", "snapshot", or a version like "2.11.0")' -Default 'v').answer;
|
$AgentVersion = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the version you wish to install ("latest", "snapshot", or a version like "2.11.0")' -Default 'v' -DefaultInput 'latest').answer;
|
||||||
$InstallerArguments += "-AgentVersion '$AgentVersion'";
|
$InstallerArguments += "-AgentVersion '$AgentVersion'";
|
||||||
|
|
||||||
Write-IcingaConsoleNotice ([string]::Format('Updating/Downgrading Icinga 2 Agent to version: "{0}"', $AgentVersion));
|
Write-IcingaConsoleNotice ([string]::Format('Updating/Downgrading Icinga 2 Agent to version: "{0}"', $AgentVersion));
|
||||||
|
|
@ -237,7 +238,7 @@ function Start-IcingaAgentInstallWizard()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Endpoints.Count -eq 0) {
|
if ($Endpoints.Count -eq 0) {
|
||||||
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify all endpoints this Agent will report to (separated by ",")' -Default 'v').answer;
|
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify all Icinga endpoints this Agent will report to separated by "," (Example: master-icinga2a, master-icinga2b)' -Default 'v').answer;
|
||||||
$Endpoints = ($ArrayString.Replace(' ', '')).Split(',');
|
$Endpoints = ($ArrayString.Replace(' ', '')).Split(',');
|
||||||
$InstallerArguments += ("-Endpoints " + ([string]::Join(',', $Endpoints)));
|
$InstallerArguments += ("-Endpoints " + ([string]::Join(',', $Endpoints)));
|
||||||
}
|
}
|
||||||
|
|
@ -255,7 +256,7 @@ function Start-IcingaAgentInstallWizard()
|
||||||
[bool]$CanConnectToParent = $FALSE;
|
[bool]$CanConnectToParent = $FALSE;
|
||||||
|
|
||||||
if ($null -eq $AcceptConnections) {
|
if ($null -eq $AcceptConnections) {
|
||||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is this Agent able to connect to its parent node for certificate generation and general communication?' -Default 'y').result -eq 1) {
|
if ((Get-IcingaAgentInstallerAnswerInput -Prompt "Is this Agent able to connect to it's parent node for certificate requests and general communication?" -Default 'y').result -eq 1) {
|
||||||
$CanConnectToParent = $TRUE;
|
$CanConnectToParent = $TRUE;
|
||||||
$AcceptConnections = 1;
|
$AcceptConnections = 1;
|
||||||
$InstallerArguments += ("-AcceptConnections 1");
|
$InstallerArguments += ("-AcceptConnections 1");
|
||||||
|
|
@ -280,6 +281,21 @@ function Start-IcingaAgentInstallWizard()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($null -eq $ConvertEndpointIPConfig) {
|
||||||
|
if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you want to convert all possible provided FQDN address for endpoint/network configuration for Icinga 2 to plain IP-Address?', $CAPort)) -Default 'y').result -eq 1) {
|
||||||
|
$InstallerArguments += "-ConvertEndpointIPConfig 1";
|
||||||
|
$ConvertEndpointIPConfig = $TRUE;
|
||||||
|
$EndpointsConversion = Convert-IcingaEndpointsToIPv4 -NetworkConfig $Endpoints;
|
||||||
|
if ($EndpointsConversion.HasErrors) {
|
||||||
|
Write-Host 'Not all of your endpoints configuration could be converted and was therefor dropped';
|
||||||
|
}
|
||||||
|
$Endpoints = $EndpointsConversion.Network;
|
||||||
|
} else {
|
||||||
|
$InstallerArguments += "-ConvertEndpointIPConfig 0";
|
||||||
|
$ConvertEndpointIPConfig = $FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($EndpointConnections.Count -eq 0 -And $AcceptConnections -eq 1) {
|
if ($EndpointConnections.Count -eq 0 -And $AcceptConnections -eq 1) {
|
||||||
$NetworkDefault = '';
|
$NetworkDefault = '';
|
||||||
foreach ($Endpoint in $Endpoints) {
|
foreach ($Endpoint in $Endpoints) {
|
||||||
|
|
@ -288,8 +304,15 @@ function Start-IcingaAgentInstallWizard()
|
||||||
if ([string]::IsNullOrEmpty($NetworkDefault) -eq $FALSE) {
|
if ([string]::IsNullOrEmpty($NetworkDefault) -eq $FALSE) {
|
||||||
$NetworkDefault = $NetworkDefault.Substring(0, $NetworkDefault.Length - 1);
|
$NetworkDefault = $NetworkDefault.Substring(0, $NetworkDefault.Length - 1);
|
||||||
}
|
}
|
||||||
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the network destinations this agent will connect to, separated by ","' -Default 'v' -DefaultInput $NetworkDefault).answer;
|
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the network destinations this Agent will connect to separated by "," (Example: 192.168.0.1, [192.168.0.2]:5665, [icinga2.example.com]:5665)' -Default 'v' -DefaultInput $NetworkDefault).answer;
|
||||||
$EndpointConnections = ($ArrayString.Replace(' ', '')).Split(',');
|
$EndpointConnections = ($ArrayString.Replace(' ', '')).Split(',');
|
||||||
|
|
||||||
|
if ($ConvertEndpointIPConfig) {
|
||||||
|
$EndpointsConversion = Convert-IcingaEndpointsToIPv4 -NetworkConfig $EndpointConnections;
|
||||||
|
if ($EndpointsConversion.HasErrors -eq $FALSE) {
|
||||||
|
$EndpointConnections = $EndpointsConversion.Network;
|
||||||
|
}
|
||||||
|
}
|
||||||
$InstallerArguments += ("-EndpointConnections " + ([string]::Join(',', $EndpointConnections)));
|
$InstallerArguments += ("-EndpointConnections " + ([string]::Join(',', $EndpointConnections)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,7 +365,7 @@ function Start-IcingaAgentInstallWizard()
|
||||||
|
|
||||||
if ($CanConnectToParent) {
|
if ($CanConnectToParent) {
|
||||||
if ([string]::IsNullOrEmpty($CAEndpoint)) {
|
if ([string]::IsNullOrEmpty($CAEndpoint)) {
|
||||||
$CAEndpoint = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the IP/FQDN for either ONE of your Icinga parent nodes or your Icinga 2 CA master' -Default 'v' -DefaultInput (Get-IPConfigFromString $EndpointConnections[0]).address).answer;
|
$CAEndpoint = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the IP/FQDN for either ONE of your Icinga parent nodes or your Icinga 2 CA master for requesting certificates' -Default 'v' -DefaultInput (Get-IPConfigFromString $EndpointConnections[0]).address).answer;
|
||||||
$InstallerArguments += "-CAEndpoint $CAEndpoint";
|
$InstallerArguments += "-CAEndpoint $CAEndpoint";
|
||||||
}
|
}
|
||||||
if ([string]::IsNullOrEmpty($Ticket) -And $null -eq $EmptyTicket) {
|
if ([string]::IsNullOrEmpty($Ticket) -And $null -eq $EmptyTicket) {
|
||||||
|
|
@ -400,7 +423,7 @@ function Start-IcingaAgentInstallWizard()
|
||||||
|
|
||||||
if ([string]::IsNullOrEmpty($ServiceUser)) {
|
if ([string]::IsNullOrEmpty($ServiceUser)) {
|
||||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to change the user the Icinga Agent service is running with (Default: "NT Authority\NetworkService")?' -Default 'n').result -eq 0) {
|
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to change the user the Icinga Agent service is running with (Default: "NT Authority\NetworkService")?' -Default 'n').result -eq 0) {
|
||||||
$ServiceUser = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the user you wish the Icinga Agent service to run with' -Default 'v').answer;
|
$ServiceUser = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the user you wish the Icinga Agent service to run with' -Default 'v' -DefaultInput 'NT Authority\NetworkService').answer;
|
||||||
$InstallerArguments += "-ServiceUser $ServiceUser";
|
$InstallerArguments += "-ServiceUser $ServiceUser";
|
||||||
if ($null -eq $ServicePass) {
|
if ($null -eq $ServicePass) {
|
||||||
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Does your Icinga Service user require a password to login (not required for System users)?' -Default 'y').result -eq 1) {
|
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Does your Icinga Service user require a password to login (not required for System users)?' -Default 'y').result -eq 1) {
|
||||||
|
|
|
||||||
60
lib/core/tools/Convert-IcingaEndpointsToIP.psm1
Normal file
60
lib/core/tools/Convert-IcingaEndpointsToIP.psm1
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Converts Icinga Network configuration from FQDN to IP
|
||||||
|
.DESCRIPTION
|
||||||
|
This Cmdlet will convert a given Icinga Endpoint configuration based
|
||||||
|
on a FQDN to a IPv4 based configuration and returns nothing of the
|
||||||
|
FQDN could not be resolved
|
||||||
|
.FUNCTIONALITY
|
||||||
|
Converts Icinga Network configuration from FQDN to IP
|
||||||
|
.EXAMPLE
|
||||||
|
PS>Convert-IcingaEndpointsToIPv4 -NetworkConfig @( '[icinga2.example.com]:5665' );
|
||||||
|
.PARAMETER NetworkConfig
|
||||||
|
An array of Icinga endpoint or single network configuration, like '[icinga2.example.com]:5665'
|
||||||
|
which will be converted to IP based configuration
|
||||||
|
.INPUTS
|
||||||
|
System.Array
|
||||||
|
.OUTPUTS
|
||||||
|
System.Hashtable
|
||||||
|
.LINK
|
||||||
|
https://github.com/Icinga/icinga-powershell-framework
|
||||||
|
#>
|
||||||
|
function Convert-IcingaEndpointsToIPv4()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[array]$NetworkConfig
|
||||||
|
);
|
||||||
|
|
||||||
|
[array]$ResolvedNetwork = @();
|
||||||
|
[bool]$HasUnresolved = $FALSE;
|
||||||
|
[string]$Domain = $ENV:UserDNSDomain;
|
||||||
|
|
||||||
|
foreach ($entry in $NetworkConfig) {
|
||||||
|
$Network = Get-IPConfigFromString -IPConfig $entry;
|
||||||
|
try {
|
||||||
|
$ResolvedIP = [System.Net.Dns]::GetHostAddresses($Network.address);
|
||||||
|
$ResolvedNetwork += $entry.Replace($Network.address, $ResolvedIP);
|
||||||
|
} catch {
|
||||||
|
# Once we failed in first place, try to lookup the "FQDN" with our host domain
|
||||||
|
# we are in. Might resolve some issues if our DNS is not knowing the plain
|
||||||
|
# hostname and untable to resolve it
|
||||||
|
try {
|
||||||
|
$ResolvedIP = [System.Net.Dns]::GetHostAddresses(
|
||||||
|
[string]::Format(
|
||||||
|
'{0}.{1}',
|
||||||
|
$Network.address,
|
||||||
|
$Domain
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$ResolvedNetwork += $entry.Replace($Network.address, $ResolvedIP);
|
||||||
|
} catch {
|
||||||
|
$HasUnresolved = $TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return @{
|
||||||
|
'Network' = $ResolvedNetwork;
|
||||||
|
'HasErrors' = $HasUnresolved;
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue