Fixes and improves various messages, handlings and severities for wizard

This commit is contained in:
Lord Hepipud 2020-05-22 16:34:18 +02:00
parent 987a52c418
commit 971e09dc43
11 changed files with 95 additions and 61 deletions

View file

@ -11,7 +11,7 @@ function Disable-IcingaFirewall()
if ($Firewall.ExitCode -ne 0) { if ($Firewall.ExitCode -ne 0) {
Write-IcingaConsoleError ([string]::Format('Failed to remove legacy firewall: {0}{1}', $Firewall.Message, $Firewall.Error)); Write-IcingaConsoleError ([string]::Format('Failed to remove legacy firewall: {0}{1}', $Firewall.Message, $Firewall.Error));
} else { } else {
Write-IcingaConsoleNotice 'Successfully removed legacy Firewall rule'; Write-IcingaConsoleNotice 'Successfully removed legacy firewall rule';
} }
} }
@ -24,7 +24,7 @@ function Disable-IcingaFirewall()
if ($Firewall.ExitCode -ne 0) { if ($Firewall.ExitCode -ne 0) {
Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga firewall: {0}{1}', $Firewall.Message, $Firewall.Error)); Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga firewall: {0}{1}', $Firewall.Message, $Firewall.Error));
} else { } else {
Write-IcingaConsoleNotice 'Successfully removed Icinga Firewall rule'; Write-IcingaConsoleNotice 'Successfully removed Icinga firewall rule';
} }
} }
} }

View file

@ -39,7 +39,7 @@ function Install-IcingaAgentCertificates()
} }
if ([string]::IsNullOrEmpty($Endpoint) -And [string]::IsNullOrEmpty($CACert)) { if ([string]::IsNullOrEmpty($Endpoint) -And [string]::IsNullOrEmpty($CACert)) {
Write-IcingaConsoleNotice 'Your host certificates have been generated successfully. Please either specify an endpoint to connect to or provide the path to a valid ca.crt.'; Write-IcingaConsoleWarning 'Your host certificates have been generated successfully. Please either specify an endpoint to connect to or provide the path to a valid ca.crt';
return $TRUE; return $TRUE;
} }

View file

@ -9,7 +9,7 @@ function Disable-IcingaAgentFeature()
} }
if ((Test-IcingaAgentFeatureEnabled -Feature $Feature) -eq $FALSE) { if ((Test-IcingaAgentFeatureEnabled -Feature $Feature) -eq $FALSE) {
Write-IcingaConsoleWarning ([string]::Format('This feature is already disabled [{0}]', $Feature)); Write-IcingaConsoleNotice ([string]::Format('This feature is already disabled [{0}]', $Feature));
return; return;
} }

View file

@ -9,7 +9,7 @@ function Enable-IcingaAgentFeature()
} }
if ((Test-IcingaAgentFeatureEnabled -Feature $Feature)) { if ((Test-IcingaAgentFeatureEnabled -Feature $Feature)) {
Write-IcingaConsoleWarning ([string]::Format('This feature is already enabled [{0}]', $Feature)); Write-IcingaConsoleNotice ([string]::Format('This feature is already enabled [{0}]', $Feature));
return; return;
} }

View file

@ -137,8 +137,9 @@ function Start-IcingaAgentInstallWizard()
} }
if ([string]::IsNullOrEmpty($Hostname) -And $null -eq $AutoUseFQDN -And $null -eq $AutoUseHostname) { if ([string]::IsNullOrEmpty($Hostname) -And $null -eq $AutoUseFQDN -And $null -eq $AutoUseHostname) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to manually specify a hostname?' -Default 'n').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to specify the hostname manually?' -Default 'n').result -eq 1) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to automatically fetch the hostname with its FQDN?' -Default 'y').result -eq 1) { $HostFQDN = Get-IcingaHostname -AutoUseFQDN 1 -AutoUseHostname 0 -LowerCase 1 -UpperCase 0;
if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you want to automatically fetch the hostname as FQDN? (Result: "{0}")', $HostFQDN)) -Default 'y').result -eq 1) {
$InstallerArguments += '-AutoUseFQDN 1'; $InstallerArguments += '-AutoUseFQDN 1';
$InstallerArguments += '-AutoUseHostname 0'; $InstallerArguments += '-AutoUseHostname 0';
$AutoUseFQDN = $TRUE; $AutoUseFQDN = $TRUE;
@ -149,17 +150,24 @@ function Start-IcingaAgentInstallWizard()
$AutoUseFQDN = $FALSE; $AutoUseFQDN = $FALSE;
$AutoUseHostname = $TRUE; $AutoUseHostname = $TRUE;
} }
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to modify the hostname to only include lower case characters?' -Default 'y').result -eq 1) { $Hostname = Get-IcingaHostname -AutoUseFQDN $AutoUseFQDN -AutoUseHostname $AutoUseHostname -LowerCase 1 -UpperCase 0;
if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you want to convert the hostname into lower case characters? (Result: "{0}")', $Hostname)) -Default 'y').result -eq 1) {
$InstallerArguments += '-LowerCase 1'; $InstallerArguments += '-LowerCase 1';
$InstallerArguments += '-UpperCase 0'; $InstallerArguments += '-UpperCase 0';
$LowerCase = $TRUE; $LowerCase = $TRUE;
$UpperCase = $FALSE; $UpperCase = $FALSE;
} else { } else {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to modify the hostname to only include upper case characters?' -Default 'n').result -eq 0) { $Hostname = Get-IcingaHostname -AutoUseFQDN $AutoUseFQDN -AutoUseHostname $AutoUseHostname -LowerCase 0 -UpperCase 1;
if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you want to convert the hostname into upper case characters? (Result: "{0}")', $Hostname)) -Default 'y').result -eq 1) {
$InstallerArguments += '-LowerCase 0'; $InstallerArguments += '-LowerCase 0';
$InstallerArguments += '-UpperCase 1'; $InstallerArguments += '-UpperCase 1';
$LowerCase = $FALSE; $LowerCase = $FALSE;
$UpperCase = $TRUE; $UpperCase = $TRUE;
} else {
$InstallerArguments += '-LowerCase 0';
$InstallerArguments += '-UpperCase 0';
$LowerCase = $FALSE;
$UpperCase = $FALSE;
} }
} }
$Hostname = Get-IcingaHostname -AutoUseFQDN $AutoUseFQDN -AutoUseHostname $AutoUseHostname -LowerCase $LowerCase -UpperCase $UpperCase; $Hostname = Get-IcingaHostname -AutoUseFQDN $AutoUseFQDN -AutoUseHostname $AutoUseHostname -LowerCase $LowerCase -UpperCase $UpperCase;
@ -172,13 +180,13 @@ function Start-IcingaAgentInstallWizard()
} }
} }
Write-IcingaConsoleNotice ([string]::Format('Using hostname "{0}" for the Icinga 2 Agent configuration', $Hostname)); Write-IcingaConsoleNotice ([string]::Format('Using hostname "{0}" for the Icinga Agent configuration', $Hostname));
$IcingaAgent = Get-IcingaAgentInstallation; $IcingaAgent = Get-IcingaAgentInstallation;
if ($IcingaAgent.Installed -eq $FALSE) { if ($IcingaAgent.Installed -eq $FALSE) {
if ([string]::IsNullOrEmpty($PackageSource)) { if ([string]::IsNullOrEmpty($PackageSource)) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the Icinga Agent now?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the Icinga Agent now?' -Default 'y').result -eq 1) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to use a different package source then "https://packages.icinga.com/windows/"?' -Default 'n').result -eq 0) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to use a different package source? (Defaults: "https://packages.icinga.com/windows/")' -Default 'n').result -eq 0) {
$PackageSource = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify your package source' -Default 'v').answer; $PackageSource = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify your package source' -Default 'v').answer;
$InstallerArguments += "-PackageSource '$PackageSource'"; $InstallerArguments += "-PackageSource '$PackageSource'";
} else { } else {
@ -186,15 +194,15 @@ function Start-IcingaAgentInstallWizard()
$InstallerArguments += "-PackageSource '$PackageSource'"; $InstallerArguments += "-PackageSource '$PackageSource'";
} }
Write-IcingaConsoleNotice ([string]::Format('Using package source "{0}" for the Icinga 2 Agent package', $PackageSource)); Write-IcingaConsoleNotice ([string]::Format('Using package source "{0}" for the Icinga Agent package', $PackageSource));
$AllowVersionChanges = $TRUE; $AllowVersionChanges = $TRUE;
$InstallerArguments += '-AllowVersionChanges 1'; $InstallerArguments += '-AllowVersionChanges 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' -DefaultInput 'latest').answer; $AgentVersion = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the version you wish to install ("latest", "snapshot" or a version like "2.11.3")' -Default 'v' -DefaultInput 'latest').answer;
$InstallerArguments += "-AgentVersion '$AgentVersion'"; $InstallerArguments += "-AgentVersion '$AgentVersion'";
Write-IcingaConsoleNotice ([string]::Format('Installing Icinga Version: "{0}"', $AgentVersion)); Write-IcingaConsoleNotice ([string]::Format('Installing Icinga version: "{0}"', $AgentVersion));
} }
} else { } else {
$AllowVersionChanges = $FALSE; $AllowVersionChanges = $FALSE;
@ -205,7 +213,7 @@ function Start-IcingaAgentInstallWizard()
} }
} else { } else {
if ($null -eq $UpdateAgent) { if ($null -eq $UpdateAgent) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'The Icinga 2 Agent is already installed. Would you like to update it?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'The Icinga Agent is already installed. Would you like to update it?' -Default 'y').result -eq 1) {
$UpdateAgent = 1; $UpdateAgent = 1;
$AllowVersionChanges = $TRUE; $AllowVersionChanges = $TRUE;
$InstallerArguments += '-AllowVersionChanges 1'; $InstallerArguments += '-AllowVersionChanges 1';
@ -238,14 +246,14 @@ function Start-IcingaAgentInstallWizard()
} }
if ($Endpoints.Count -eq 0) { if ($Endpoints.Count -eq 0) {
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify all Icinga endpoints this Agent will report to separated by "," (Example: master-icinga2a, master-icinga2b)' -Default 'v').answer; $ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the parent node(s) 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)));
} }
if ($null -eq $CAPort) { if ($null -eq $CAPort) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Are you using a different port than 5665 for Icinga communications?' -Default 'n').result -eq 0) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Are you using a custom port for Icinga communication?' -Default 'n').result -eq 0) {
$CAPort = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the port for Icinga 2 communication' -Default 'v').answer; $CAPort = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the port for Icinga communication' -Default 'v' -DefaultInput '5665').answer;
$InstallerArguments += "-CAPort $CAPort"; $InstallerArguments += "-CAPort $CAPort";
} else { } else {
$InstallerArguments += "-CAPort 5665"; $InstallerArguments += "-CAPort 5665";
@ -256,22 +264,25 @@ 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 it's parent node for certificate requests and general communication?" -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt "Is this Agent able to connect to its parent node(s)?" -Default 'y').result -eq 1) {
$CanConnectToParent = $TRUE; $CanConnectToParent = $TRUE;
$AcceptConnections = 1;
$InstallerArguments += ("-AcceptConnections 1");
} else {
$AcceptConnections = 0; $AcceptConnections = 0;
$InstallerArguments += ("-AcceptConnections 0"); $InstallerArguments += ("-AcceptConnections 0");
} else {
$AcceptConnections = 1;
$InstallerArguments += ("-AcceptConnections 1");
} }
} elseif ($AcceptConnections) { } else {
$CanConnectToParent = $TRUE;
if ((Test-IcingaWizardArgument -Argument 'AcceptConnections') -eq $FALSE) { if ((Test-IcingaWizardArgument -Argument 'AcceptConnections') -eq $FALSE) {
$InstallerArguments += ([string]::Format('-AcceptConnections {0}', [int]$AcceptConnections)); $InstallerArguments += ([string]::Format('-AcceptConnections {0}', [int]$AcceptConnections));
} }
if ($AcceptConnections -eq $FALSE) {
$CanConnectToParent = $TRUE;
}
} }
if ($null -eq $AddFirewallRule) { if ($null -eq $AddFirewallRule -And $CanConnectToParent -eq $FALSE) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you want to open the Windows Firewall for incoming traffic on Port "{0}"?', $CAPort)) -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Do you want to open the Windows Firewall for incoming traffic on Port "{0}"?', $CAPort)) -Default 'y').result -eq 1) {
$InstallerArguments += "-AddFirewallRule 1"; $InstallerArguments += "-AddFirewallRule 1";
$AddFirewallRule = $TRUE; $AddFirewallRule = $TRUE;
@ -279,10 +290,15 @@ function Start-IcingaAgentInstallWizard()
$InstallerArguments += "-AddFirewallRule 0"; $InstallerArguments += "-AddFirewallRule 0";
$AddFirewallRule = $FALSE; $AddFirewallRule = $FALSE;
} }
} else {
if ($CanConnectToParent -eq $TRUE) {
$InstallerArguments += "-AddFirewallRule 0";
$AddFirewallRule = $FALSE;
}
} }
if ($null -eq $ConvertEndpointIPConfig) { if ($null -eq $ConvertEndpointIPConfig -And $CanConnectToParent -eq $TRUE) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to convert endpoint connection data to IP adresses?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to convert parent node(s) connection data to IP adresses?' -Default 'y').result -eq 1) {
$InstallerArguments += "-ConvertEndpointIPConfig 1"; $InstallerArguments += "-ConvertEndpointIPConfig 1";
$ConvertEndpointIPConfig = $TRUE; $ConvertEndpointIPConfig = $TRUE;
if ($EndpointConnections.Count -eq 0) { if ($EndpointConnections.Count -eq 0) {
@ -300,7 +316,7 @@ function Start-IcingaAgentInstallWizard()
} }
} }
if ($EndpointConnections.Count -eq 0 -And $AcceptConnections -eq 1) { if ($EndpointConnections.Count -eq 0 -And $AcceptConnections -eq 0) {
$NetworkDefault = ''; $NetworkDefault = '';
foreach ($Endpoint in $Endpoints) { foreach ($Endpoint in $Endpoints) {
$NetworkDefault += [string]::Format('[{0}]:{1},', $Endpoint, $CAPort); $NetworkDefault += [string]::Format('[{0}]:{1},', $Endpoint, $CAPort);
@ -321,7 +337,7 @@ function Start-IcingaAgentInstallWizard()
} }
if ([string]::IsNullOrEmpty($ParentZone)) { if ([string]::IsNullOrEmpty($ParentZone)) {
$ParentZone = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the parent zone this agent will connect to' -Default 'v' -DefaultInput 'master').answer; $ParentZone = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the parent zone this Agent will connect to' -Default 'v' -DefaultInput 'master').answer;
$InstallerArguments += "-ParentZone $ParentZone"; $InstallerArguments += "-ParentZone $ParentZone";
} }
@ -355,7 +371,8 @@ function Start-IcingaAgentInstallWizard()
if ($null -eq $GlobalZones) { if ($null -eq $GlobalZones) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to add custom global zones?' -Default 'n').result -eq 0) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to add custom global zones?' -Default 'n').result -eq 0) {
$ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify your additional zones seperated by ","' -Default 'v').answer; $ArrayString = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify your additional zones seperated by "," (Example: "global-zone1, global-zone2")' -Default 'v').answer;
if ([string]::IsNullOrEmpty($ArrayString) -eq $FALSE) {
$GlobalZones = ($ArrayString.Replace(' ', '')).Split(',') $GlobalZones = ($ArrayString.Replace(' ', '')).Split(',')
$GlobalZoneConfig += $GlobalZones; $GlobalZoneConfig += $GlobalZones;
$InstallerArguments += ("-GlobalZones " + ([string]::Join(',', $GlobalZones))); $InstallerArguments += ("-GlobalZones " + ([string]::Join(',', $GlobalZones)));
@ -363,18 +380,22 @@ function Start-IcingaAgentInstallWizard()
$GlobalZones = @(); $GlobalZones = @();
$InstallerArguments += ("-GlobalZones @()"); $InstallerArguments += ("-GlobalZones @()");
} }
} else {
$GlobalZones = @();
$InstallerArguments += ("-GlobalZones @()");
}
} else { } else {
$GlobalZoneConfig += $GlobalZones; $GlobalZoneConfig += $GlobalZones;
} }
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 for requesting certificates' -Default 'v' -DefaultInput (Get-IPConfigFromString $EndpointConnections[0]).address).answer; $CAEndpoint = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the connection data of the parent node that handles certificate requests' -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) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you have a Icinga Ticket available to sign your certificate?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you have a PKI Ticket to sign your certificate request?' -Default 'y').result -eq 1) {
$Ticket = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter your Icinga Ticket' -Default 'v').answer; $Ticket = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter your PKI Ticket' -Default 'v').answer;
if ([string]::IsNullOrEmpty($Ticket)) { if ([string]::IsNullOrEmpty($Ticket)) {
$InstallerArguments += "-EmptyTicket 1" $InstallerArguments += "-EmptyTicket 1"
} else { } else {
@ -400,7 +421,7 @@ function Start-IcingaAgentInstallWizard()
} else { } else {
if ([string]::IsNullOrEmpty($CAFile) -And $null -eq $EmptyCA) { if ([string]::IsNullOrEmpty($CAFile) -And $null -eq $EmptyCA) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is your public Icinga 2 CA (ca.crt) available on a local, network or web share?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is your public Icinga 2 CA (ca.crt) available on a local, network or web share?' -Default 'y').result -eq 1) {
$CAFile = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please provide the full path to your ca.crt file' -Default 'v').answer; $CAFile = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please provide the full path to your ca.crt file (Examples: "C:\icinga2\ca.crt", "https://icinga.example.com/ca.crt"' -Default 'v').answer;
if ([string]::IsNullOrEmpty($CAFile)) { if ([string]::IsNullOrEmpty($CAFile)) {
$InstallerArguments += "-EmptyCA 1" $InstallerArguments += "-EmptyCA 1"
} else { } else {
@ -409,7 +430,8 @@ function Start-IcingaAgentInstallWizard()
$InstallerArguments += "-CAFile '$CAFile'"; $InstallerArguments += "-CAFile '$CAFile'";
} else { } else {
$InstallerArguments += "-CAFile ''"; $InstallerArguments += "-CAFile ''";
$InstallerArguments += "-EmptyCA 1" $InstallerArguments += "-EmptyCA 1";
$EmptyCA = $TRUE;
} }
} else { } else {
if ([string]::IsNullOrEmpty($CAFile)) { if ([string]::IsNullOrEmpty($CAFile)) {
@ -426,11 +448,11 @@ 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 of the Icinga Agent service? (Defaults: "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' -DefaultInput 'NT Authority\NetworkService').answer; $ServiceUser = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter a custom user for the Icinga Agent service' -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 Agent service user require a password to login? (Not required for System users)' -Default 'y').result -eq 1) {
$ServicePass = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the password for your service user' -Secure -Default 'v').answer; $ServicePass = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please enter the password for your service user' -Secure -Default 'v').answer;
$InstallerArguments += "-ServicePass $ServicePass"; $InstallerArguments += "-ServicePass $ServicePass";
} else { } else {
@ -464,7 +486,7 @@ function Start-IcingaAgentInstallWizard()
} }
if ($null -eq $InstallFrameworkService) { if ($null -eq $InstallFrameworkService) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the PowerShell Framework as a Service?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to install the PowerShell Framework as a service?' -Default 'y').result -eq 1) {
$result = Get-IcingaFrameworkServiceBinary; $result = Get-IcingaFrameworkServiceBinary;
$InstallerArguments += "-InstallFrameworkService 1"; $InstallerArguments += "-InstallFrameworkService 1";
$InstallerArguments += [string]::Format("-FrameworkServiceUrl '{0}'", $result.FrameworkServiceUrl); $InstallerArguments += [string]::Format("-FrameworkServiceUrl '{0}'", $result.FrameworkServiceUrl);
@ -511,18 +533,30 @@ function Start-IcingaAgentInstallWizard()
Move-IcingaAgentDefaultConfig; Move-IcingaAgentDefaultConfig;
Set-IcingaAgentNodeName -Hostname $Hostname; Set-IcingaAgentNodeName -Hostname $Hostname;
Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass -SetPermission | Out-Null; Set-IcingaAgentServiceUser -User $ServiceUser -Password $ServicePass -SetPermission | Out-Null;
if ($InstallFrameworkService) {
Install-IcingaFrameworkService -Path $ServiceBin -User $ServiceUser -Password $ServicePass | Out-Null; Install-IcingaFrameworkService -Path $ServiceBin -User $ServiceUser -Password $ServicePass | Out-Null;
}
Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon'; Register-IcingaBackgroundDaemon -Command 'Start-IcingaServiceCheckDaemon';
Install-IcingaAgentBaseFeatures; Install-IcingaAgentBaseFeatures;
Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $CAEndpoint -Port $CAPort -CACert $CAFile -Ticket $Ticket | Out-Null; Install-IcingaAgentCertificates -Hostname $Hostname -Endpoint $CAEndpoint -Port $CAPort -CACert $CAFile -Ticket $Ticket | Out-Null;
Write-IcingaAgentApiConfig -Port $CAPort; Write-IcingaAgentApiConfig -Port $CAPort;
if ($EmptyCA -eq $TRUE) {
Disable-IcingaAgentFeature 'api';
Write-IcingaConsoleWarning -Message '{0}{1}{2}{3}{4}' -Objects 'Your Icinga Agent API feature has been disabled. Please provide either your ca.crt ',
'or connect to a parent node for certificate requests. You can run "Install-IcingaAgentCertificates" ',
'with your configuration to properly create the host certificate and a valid certificate request. ',
'After this you can enable the API feature by using "Enable-IcingaAgentFeature api" and restart the ',
'Icinga Agent service "Restart-IcingaService icinga2"';
}
Write-IcingaAgentZonesConfig -Endpoints $Endpoints -EndpointConnections $EndpointConnections -ParentZone $ParentZone -GlobalZones $GlobalZoneConfig -Hostname $Hostname; Write-IcingaAgentZonesConfig -Endpoints $Endpoints -EndpointConnections $EndpointConnections -ParentZone $ParentZone -GlobalZones $GlobalZoneConfig -Hostname $Hostname;
if ($AddFirewallRule) { if ($AddFirewallRule) {
# First cleanup the system by removing all old Firewalls # First cleanup the system by removing all old Firewalls
Enable-IcingaFirewall -IcingaPort $CAPort -Force; Enable-IcingaFirewall -IcingaPort $CAPort -Force;
} }
Test-IcingaAgent; Test-IcingaAgent;
if ($InstallFrameworkService) {
Restart-IcingaService 'icingapowershell'; Restart-IcingaService 'icingapowershell';
}
Restart-IcingaService 'icinga2'; Restart-IcingaService 'icinga2';
} }
} }

View file

@ -12,7 +12,7 @@ function Set-IcingaAgentServicePermission()
$NewSystemContent = @(); $NewSystemContent = @();
if ([string]::IsNullOrEmpty($ServiceUser)) { if ([string]::IsNullOrEmpty($ServiceUser)) {
Write-IcingaTestOutput -Severity 'FAILED' -Message 'There is no user assigned to the Icinga 2 service or the service is not yet installed'; Write-IcingaTestOutput -Severity 'Failed' -Message 'There is no user assigned to the Icinga 2 service or the service is not yet installed';
return $FALSE; return $FALSE;
} }

View file

@ -38,13 +38,13 @@ function Test-IcingaAcl()
[string]$messageFormat = 'Directory "{0}" {1} by the Icinga Service User "{2}"'; [string]$messageFormat = 'Directory "{0}" {1} by the Icinga Service User "{2}"';
if ($UserFound) { if ($UserFound) {
if ($HasAccess) { if ($HasAccess) {
Write-IcingaTestOutput -Severity 'PASSED' -Message ([string]::Format($messageFormat, $Directory, 'is accessible and writeable', $ServiceUser)); Write-IcingaTestOutput -Severity 'Passed' -Message ([string]::Format($messageFormat, $Directory, 'is accessible and writeable', $ServiceUser));
} else { } else {
Write-IcingaTestOutput -Severity 'FAILED' -Message ([string]::Format($messageFormat, $Directory, 'is accessible but NOT writeable', $ServiceUser)); Write-IcingaTestOutput -Severity 'Failed' -Message ([string]::Format($messageFormat, $Directory, 'is accessible but NOT writeable', $ServiceUser));
Write-IcingaConsolePlain "\_ Please run the following command to fix this issue: Set-IcingaAcl -Directory '$Directory'"; Write-IcingaConsolePlain "\_ Please run the following command to fix this issue: Set-IcingaAcl -Directory '$Directory'";
} }
} else { } else {
Write-IcingaTestOutput -Severity 'FAILED' -Message ([string]::Format($messageFormat, $Directory, 'is not accessible', $ServiceUser)); Write-IcingaTestOutput -Severity 'Failed' -Message ([string]::Format($messageFormat, $Directory, 'is not accessible', $ServiceUser));
Write-IcingaConsolePlain "\_ Please run the following command to fix this issue: Set-IcingaAcl -Directory '$Directory'"; Write-IcingaConsolePlain "\_ Please run the following command to fix this issue: Set-IcingaAcl -Directory '$Directory'";
} }
} }

View file

@ -1,18 +1,18 @@
function Test-IcingaAgent() function Test-IcingaAgent()
{ {
if (Get-Service 'icinga2' -ErrorAction SilentlyContinue) { if (Get-Service 'icinga2' -ErrorAction SilentlyContinue) {
Write-IcingaTestOutput -Severity 'PASSED' -Message 'Icinga Agent Service is installed'; Write-IcingaTestOutput -Severity 'Passed' -Message 'Icinga Agent service is installed';
Test-IcingaAgentServicePermission | Out-Null; Test-IcingaAgentServicePermission | Out-Null;
Test-IcingaAcl "$Env:ProgramData\icinga2\etc" -WriteOutput | Out-Null; Test-IcingaAcl "$Env:ProgramData\icinga2\etc" -WriteOutput | Out-Null;
Test-IcingaAcl "$Env:ProgramData\icinga2\var" -WriteOutput | Out-Null; Test-IcingaAcl "$Env:ProgramData\icinga2\var" -WriteOutput | Out-Null;
Test-IcingaAcl (Get-IcingaCacheDir) -WriteOutput | Out-Null; Test-IcingaAcl (Get-IcingaCacheDir) -WriteOutput | Out-Null;
Test-IcingaAgentConfig | Out-Null; Test-IcingaAgentConfig | Out-Null;
if (Test-IcingaAgentFeatureEnabled -Feature 'debuglog') { if (Test-IcingaAgentFeatureEnabled -Feature 'debuglog') {
Write-IcingaTestOutput -Severity 'WARNING' -Message 'The Debug-Log of the Icinga Agent is enabled. Please keep in mind to disable it once testing is done, as a huge amount of data is generated.' Write-IcingaTestOutput -Severity 'Warning' -Message 'The debug log of the Icinga Agent is enabled. Please keep in mind to disable it once testing is done, as a huge amount of data is generated'
} else { } else {
Write-IcingaTestOutput -Severity 'PASSED' -Message 'Icinga Agent Debug-Log is disabled' Write-IcingaTestOutput -Severity 'Passed' -Message 'Icinga Agent debug log is disabled'
} }
} else { } else {
Write-IcingaTestOutput -Severity 'FAILED' -Message 'Icinga Agent Service is not installed'; Write-IcingaTestOutput -Severity 'Failed' -Message 'Icinga Agent service is not installed';
} }
} }

View file

@ -8,10 +8,10 @@ function Test-IcingaAgentConfig()
$ConfigResult = Start-IcingaProcess -Executable $Binary -Arguments 'daemon -C'; $ConfigResult = Start-IcingaProcess -Executable $Binary -Arguments 'daemon -C';
if ($ConfigResult.ExitCode -eq 0) { if ($ConfigResult.ExitCode -eq 0) {
Write-IcingaTestOutput -Severity 'PASSED' -Message 'Icinga Agent configuration is valid'; Write-IcingaTestOutput -Severity 'Passed' -Message 'Icinga Agent configuration is valid';
return $TRUE; return $TRUE;
} else { } else {
Write-IcingaTestOutput -Severity 'FAILED' -Message 'Icinga Agent configuration is containing errors. Run this command for getting a detailed error report: "Test-IcingaAgentConfig -WriteStackTrace | Out-Null"'; Write-IcingaTestOutput -Severity 'Failed' -Message 'Icinga Agent configuration contains errors. Run this command for getting a detailed error report: "Test-IcingaAgentConfig -WriteStackTrace | Out-Null"';
if ($WriteStackTrace) { if ($WriteStackTrace) {
Write-IcingaConsolePlain $ConfigResult.Message; Write-IcingaConsolePlain $ConfigResult.Message;
} }

View file

@ -15,7 +15,7 @@ function Test-IcingaAgentServicePermission()
if ([string]::IsNullOrEmpty($ServiceUser)) { if ([string]::IsNullOrEmpty($ServiceUser)) {
if (-Not $Silent) { if (-Not $Silent) {
Write-IcingaTestOutput -Severity 'FAILED' -Message 'There is no user assigned to the Icinga 2 service or the service is not yet installed'; Write-IcingaTestOutput -Severity 'Failed' -Message 'There is no user assigned to the Icinga 2 service or the service is not yet installed';
} }
return $FALSE; return $FALSE;
} }
@ -40,9 +40,9 @@ function Test-IcingaAgentServicePermission()
if (-Not $Silent) { if (-Not $Silent) {
if ($FoundSID) { if ($FoundSID) {
Write-IcingaTestOutput -Severity 'PASSED' -Message ([string]::Format('The specified user "{0}" is allowed to run as service.', $ServiceUser)); Write-IcingaTestOutput -Severity 'Passed' -Message ([string]::Format('The specified user "{0}" is allowed to run as service', $ServiceUser));
} else { } else {
Write-IcingaTestOutput -Severity 'FAILED' -Message ([string]::Format('The specified user "{0}" is not allowed to run as service.', $ServiceUser)); Write-IcingaTestOutput -Severity 'Failed' -Message ([string]::Format('The specified user "{0}" is not allowed to run as service', $ServiceUser));
} }
} }

View file

@ -1,7 +1,7 @@
function Write-IcingaTestOutput() function Write-IcingaTestOutput()
{ {
param( param(
[ValidateSet('PASSED', 'WARNING', 'FAILED')] [ValidateSet('Passed', 'Warning', 'Failed')]
$Severity, $Severity,
$Message $Message
); );
@ -9,15 +9,15 @@ function Write-IcingaTestOutput()
$Color = 'Green'; $Color = 'Green';
Switch ($Severity) { Switch ($Severity) {
'PASSED' { 'Passed' {
$Color = 'Green'; $Color = 'Green';
break; break;
}; };
'WARNING' { 'Warning' {
$Color = 'Yellow'; $Color = 'Yellow';
break; break;
}; };
'FAILED' { 'Failed' {
$Color = 'Red'; $Color = 'Red';
break; break;
}; };