Write-Host([string]::Format('Using hostname "{0}" for the Icinga 2 Agent configuration',$Hostname));
$IcingaAgent=Get-IcingaAgentInstallation;
if($IcingaAgent.Installed-eq$FALSE){
if([string]::IsNullOrEmpty($PackageSource)){
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Do you want to install the Icinga Agent now?'-Default'y').result-eq1){
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Do you want to use a different package source then "https://packages.icinga.com/windows/" ?'-Default'n').result-eq0){
$PackageSource=(Get-IcingaAgentInstallerAnswerInput-Prompt'Please specify your package source'-Default'v').answer;
Write-Host([string]::Format('Using package source "{0}" for the Icinga 2 Agent package',$PackageSource));
}
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;
if((Get-IcingaAgentInstallerAnswerInput-Prompt'The Icinga 2 Agent is already installed. Would you like to update it?'-Default'y').result-eq1){
$UpdateAgent=1;
}else{
$UpdateAgent=0;
}
$InstallerArguments+="-UpdateAgent $UpdateAgent";
}
if($UpdateAgent-eq1){
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;
Write-Host([string]::Format('Updating/Downgrading Icinga 2 Agent to version: "{0}"',$AgentVersion));
}
if([string]::IsNullOrEmpty($PackageSource)){
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Do you want to use a different package source then "https://packages.icinga.com/windows/" ?'-Default'n').result-eq0){
$PackageSource=(Get-IcingaAgentInstallerAnswerInput-Prompt'Please specify your package source'-Default'v').answer;
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Will this Agent connect to its parent endpoint(s)?'-Default'y').result-eq1){
$InstallerArguments+="-AcceptConnections 1";
$AcceptConnections=1;
}else{
$InstallerArguments+="-AcceptConnections 0";
$AcceptConnections=0;
}
}
if($Endpoints.Count-eq0){
$ArrayString=(Get-IcingaAgentInstallerAnswerInput-Prompt'Please specify all endpoints this Agent will report to (separated by ",")'-Default'v').answer;
$ArrayString=(Get-IcingaAgentInstallerAnswerInput-Prompt'Please specify the network destinations this agent will connect to ("," separated, like: "[127.0.0.1], [127.0.0.2]")'-Default'v').answer;
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Is this Agent able to connect to its parent node for certificate generation?'-Default'y').result-eq1){
$CanConnectToParent=$TRUE;
}
}else{
$CanConnectToParent=$TRUE;
}
if($CanConnectToParent){
if([string]::IsNullOrEmpty($CAEndpoint)){
$CAEndpoint=(Get-IcingaAgentInstallerAnswerInput-Prompt'Please enter the FQDN for either ONE of your Icinga parent node/nodes or your Icinga 2 CA master (if you can connect to it)'-Default'v').answer;
$InstallerArguments+="-CAEndpoint $CAEndpoint";
}
if($null-eq$CAPort){
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Are you using a different port then 5665 for Icinga communications?'-Default'n').result-eq0){
$CAPort=(Get-IcingaAgentInstallerAnswerInput-Prompt'Please enter your port to communicate with the Icinga 2 CA'-Default'v').answer;
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Is your public Icinga 2 CA (ca.crt) available on a local, network or web share?'-Default'y').result-eq1){
$CAFile=(Get-IcingaAgentInstallerAnswerInput-Prompt'Please provide the full path to your ca.crt file'-Default'v').answer;
$InstallerArguments+="-CAFile $CAFile";
}
}
}
if($InstallerArguments.Count-ne0){
$InstallerArguments+="-RunInstaller";
Write-Host'The wizard is complete. These are the configured settings:';
Write-Host($InstallerArguments|Out-String);
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Is this configuration correct?'-Default'y').result-eq1){
if((Get-IcingaAgentInstallerAnswerInput-Prompt'Do you want to run the installer now? (Otherwise only the configration command will be printed)'-Default'y').result-eq1){
Write-Host'To execute your Icinga Agent installation based on your answers again on this or another machine, simply run this command:'
$RunInstaller=$TRUE;
}else{
Write-Host'To execute your Icinga Agent installation based on your answers, simply run this command:'
}
}else{
Write-Host'Please run the wizard again to modify your answers or modify the command below:'