diff --git a/lib/apis/Get-IcingaDirectorSelfServiceTicket.psm1 b/lib/apis/Get-IcingaDirectorSelfServiceTicket.psm1 index 2e2bfaa..f4c1b85 100644 --- a/lib/apis/Get-IcingaDirectorSelfServiceTicket.psm1 +++ b/lib/apis/Get-IcingaDirectorSelfServiceTicket.psm1 @@ -23,30 +23,30 @@ function Get-IcingaDirectorSelfServiceTicket() { - param( - $DirectorUrl, - $ApiKey = $null - ); + param( + $DirectorUrl, + $ApiKey = $null + ); - if ([string]::IsNullOrEmpty($DirectorUrl)) { - Write-Host 'Unable to fetch host ticket. No Director url has been specified'; - return; - } + if ([string]::IsNullOrEmpty($DirectorUrl)) { + Write-IcingaConsoleError 'Unable to fetch host ticket. No Director url has been specified'; + return; + } - if ([string]::IsNullOrEmpty($ApiKey)) { - Write-Host 'Unable to fetch host ticket. No API key has been specified'; - return; - } + if ([string]::IsNullOrEmpty($ApiKey)) { + Write-IcingaConsoleError 'Unable to fetch host ticket. No API key has been specified'; + return; + } - [string]$url = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/ticket?key={0}', $ApiKey)); + [string]$url = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/ticket?key={0}', $ApiKey)); - $response = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST'; + $response = Invoke-WebRequest -Uri $url -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST'; - if ($response.StatusCode -ne 200) { - throw $response.Content; - } + if ($response.StatusCode -ne 200) { + throw $response.Content; + } - $JsonContent = ConvertFrom-Json -InputObject $response.Content; + $JsonContent = ConvertFrom-Json -InputObject $response.Content; - return $JsonContent; + return $JsonContent; } diff --git a/lib/apis/Register-IcingaDirectorSelfServiceHost.psm1 b/lib/apis/Register-IcingaDirectorSelfServiceHost.psm1 index 633a954..adcee02 100644 --- a/lib/apis/Register-IcingaDirectorSelfServiceHost.psm1 +++ b/lib/apis/Register-IcingaDirectorSelfServiceHost.psm1 @@ -77,7 +77,7 @@ function Register-IcingaDirectorSelfServiceHost() Set-IcingaPowerShellConfig -Path 'IcingaDirector.SelfService.ApiKey' -Value $JsonContent; - Write-Host 'Host was successfully registered within Icinga Director'; + Write-IcingaConsoleNotice 'Host was successfully registered within Icinga Director'; return $JsonContent; } diff --git a/lib/core/framework/Copy-ItemSecure.psm1 b/lib/core/framework/Copy-ItemSecure.psm1 index 3085785..f5ccb96 100644 --- a/lib/core/framework/Copy-ItemSecure.psm1 +++ b/lib/core/framework/Copy-ItemSecure.psm1 @@ -50,7 +50,7 @@ function Copy-ItemSecure() } return $TRUE; } catch { - Write-Host ([string]::Format('Failed to copy items from path "{0}" to "{1}": {2}', $Path, $Destination, $_.Exception)) -ForegroundColor Red; + Write-IcingaConsoleError -Message 'Failed to copy items from path "{0}" to "{1}": {2}' -Objects $Path, $Destination, $_.Exception; } return $FALSE; } diff --git a/lib/core/framework/Expand-IcingaZipArchive.psm1 b/lib/core/framework/Expand-IcingaZipArchive.psm1 index dfde53a..5359971 100644 --- a/lib/core/framework/Expand-IcingaZipArchive.psm1 +++ b/lib/core/framework/Expand-IcingaZipArchive.psm1 @@ -27,7 +27,7 @@ function Expand-IcingaZipArchive() ); if ((Test-Path $Path) -eq $FALSE -Or (Test-Path $Destination) -eq $FALSE) { - Write-Host 'The path to the zip archive or the destination path do not exist'; + Write-IcingaConsoleError 'The path to the zip archive or the destination path do not exist'; return $FALSE; } diff --git a/lib/core/framework/Get-IcingaFrameworkServiceBinary.psm1 b/lib/core/framework/Get-IcingaFrameworkServiceBinary.psm1 index cdc34f1..0274a00 100644 --- a/lib/core/framework/Get-IcingaFrameworkServiceBinary.psm1 +++ b/lib/core/framework/Get-IcingaFrameworkServiceBinary.psm1 @@ -45,7 +45,7 @@ function Get-IcingaFrameworkServiceBinary() } if ([string]::IsNullOrEmpty($FrameworkServiceUrl)) { - Write-Host 'No Url to download the Icinga Service Binary from has been specified. Please try again.'; + Write-IcingaConsoleError 'No Url to download the Icinga Service Binary from has been specified. Please try again.'; return Get-IcingaFrameworkServiceBinary; } @@ -66,7 +66,7 @@ function Get-IcingaFrameworkServiceBinary() try { Invoke-WebRequest -Uri $FrameworkServiceUrl -UseBasicParsing -OutFile $ZipArchive; } catch { - Write-Host ([string]::Format('Failed to download the Icinga Service Binary from "{0}". Please try again.', $FrameworkServiceUrl)); + Write-IcingaConsoleError -Message 'Failed to download the Icinga Service Binary from "{0}". Please try again.' -Objects $FrameworkServiceUrl; return Get-IcingaFrameworkServiceBinary; } diff --git a/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 b/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 index 221aefd..bbcc6fb 100644 --- a/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 +++ b/lib/core/framework/Get-IcingaPowerShellModuleArchive.psm1 @@ -61,7 +61,7 @@ function Get-IcingaPowerShellModuleArchive() $CurrentVersion = Get-IcingaPowerShellModuleVersion $Repository; if ($null -ne $CurrentVersion -And $CurrentVersion -eq $Tag) { - Write-Host ([string]::Format('Your "{0}" is already up-to-date', $ModuleName)); + Write-IcingaConsoleNotice -Message 'Your "{0}" is already up-to-date' -Objects $ModuleName; return @{ 'DownloadUrl' = $DownloadUrl; 'Version' = $Tag; @@ -80,15 +80,15 @@ function Get-IcingaPowerShellModuleArchive() try { $DownloadDirectory = New-IcingaTemporaryDirectory; $DownloadDestination = (Join-Path -Path $DownloadDirectory -ChildPath ([string]::Format('{0}.zip', $Repository))); - Write-Host ([string]::Format('Downloading "{0}" into "{1}"', $ModuleName, $DownloadDirectory)); + Write-IcingaConsoleNotice ([string]::Format('Downloading "{0}" into "{1}"', $ModuleName, $DownloadDirectory)); Invoke-WebRequest -UseBasicParsing -Uri $DownloadUrl -OutFile $DownloadDestination; } catch { - Write-Host ([string]::Format('Failed to download "{0}" into "{1}". Starting cleanup process', $ModuleName, $DownloadDirectory)); + Write-IcingaConsoleError ([string]::Format('Failed to download "{0}" into "{1}". Starting cleanup process', $ModuleName, $DownloadDirectory)); Start-Sleep -Seconds 2; Remove-Item -Path $DownloadDirectory -Recurse -Force; - Write-Host 'Starting to re-run the download wizard'; + Write-IcingaConsoleNotice 'Starting to re-run the download wizard'; return Get-IcingaPowerShellModuleArchive -ModuleName $ModuleName -Repository $Repository; } diff --git a/lib/core/framework/Install-IcingaFrameworkPlugins.psm1 b/lib/core/framework/Install-IcingaFrameworkPlugins.psm1 index 7d11b40..d281c63 100644 --- a/lib/core/framework/Install-IcingaFrameworkPlugins.psm1 +++ b/lib/core/framework/Install-IcingaFrameworkPlugins.psm1 @@ -13,7 +13,7 @@ function Install-IcingaFrameworkPlugins() }; } - Write-Host ([string]::Format('Installing module into "{0}"', ($Archive.Directory))); + Write-IcingaConsoleNotice ([string]::Format('Installing module into "{0}"', ($Archive.Directory))); Expand-IcingaZipArchive -Path $Archive.Archive -Destination $Archive.Directory | Out-Null; $FolderContent = Get-ChildItem -Path $Archive.Directory; @@ -26,19 +26,19 @@ function Install-IcingaFrameworkPlugins() } } - Write-Host ([string]::Format('Using content of folder "{0}" for updates', $ModuleContent)); + Write-IcingaConsoleNotice ([string]::Format('Using content of folder "{0}" for updates', $ModuleContent)); $PluginDirectory = (Join-Path -Path $Archive.ModuleRoot -ChildPath $RepositoryName); if ((Test-Path $PluginDirectory) -eq $FALSE) { - Write-Host ([string]::Format('Plugin Module Directory "{0}" is not present. Creating Directory', $PluginDirectory)); + Write-IcingaConsoleNotice ([string]::Format('Plugin Module Directory "{0}" is not present. Creating Directory', $PluginDirectory)); New-Item -Path $PluginDirectory -ItemType Directory | Out-Null; } - Write-Host 'Copying files to plugins'; + Write-IcingaConsoleNotice 'Copying files to plugins'; Copy-ItemSecure -Path (Join-Path -Path $ModuleContent -ChildPath '/*') -Destination $PluginDirectory -Recurse -Force | Out-Null; - Write-Host 'Cleaning temporary content'; + Write-IcingaConsoleNotice 'Cleaning temporary content'; Start-Sleep -Seconds 1; Remove-ItemSecure -Path $Archive.Directory -Recurse -Force | Out-Null; @@ -47,7 +47,7 @@ function Install-IcingaFrameworkPlugins() # include the plugins Use-Icinga; - Write-Host 'Icinga Plugin update has been completed'; + Write-IcingaConsoleNotice 'Icinga Plugin update has been completed'; return @{ 'PluginUrl' = $Archive.DownloadUrl diff --git a/lib/core/framework/Install-IcingaFrameworkService.psm1 b/lib/core/framework/Install-IcingaFrameworkService.psm1 index dd67ec1..1263c0f 100644 --- a/lib/core/framework/Install-IcingaFrameworkService.psm1 +++ b/lib/core/framework/Install-IcingaFrameworkService.psm1 @@ -7,7 +7,7 @@ function Install-IcingaFrameworkService() ); if ([string]::IsNullOrEmpty($Path)) { - Write-Host 'No path specified for Framework service. Service will not be installed'; + Write-IcingaConsoleError 'No path specified for Framework service. Service will not be installed'; return; } @@ -17,10 +17,10 @@ function Install-IcingaFrameworkService() if ((Test-Path $UpdateFile)) { - Write-Host 'Updating Icinga PowerShell Service binary'; + Write-IcingaConsoleNotice 'Updating Icinga PowerShell Service binary'; if ($ServiceStatus -eq 'Running') { - Write-Host 'Stopping Icinga PowerShell service'; + Write-IcingaConsoleNotice 'Stopping Icinga PowerShell service'; Stop-IcingaService 'icingapowershell'; Start-Sleep -Seconds 1; } @@ -47,7 +47,7 @@ function Install-IcingaFrameworkService() throw ([string]::Format('Failed to install Icinga PowerShell Service: {0}{1}', $ServiceCreation.Message, $ServiceCreation.Error)); } } else { - Write-Host 'The Icinga PowerShell Service is already installed'; + Write-IcingaConsoleWarning 'The Icinga PowerShell Service is already installed'; } # This is just a hotfix to ensure we setup the service properly before assigning it to @@ -60,7 +60,7 @@ function Install-IcingaFrameworkService() Stop-IcingaService 'icingapowershell'; if ($ServiceStatus -eq 'Running') { - Write-Host 'Starting Icinga PowerShell service'; + Write-IcingaConsoleNotice 'Starting Icinga PowerShell service'; Start-IcingaService 'icingapowershell'; Start-Sleep -Seconds 1; } diff --git a/lib/core/framework/Install-IcingaFrameworkUpdate.psm1 b/lib/core/framework/Install-IcingaFrameworkUpdate.psm1 index b2cb4ba..327efab 100644 --- a/lib/core/framework/Install-IcingaFrameworkUpdate.psm1 +++ b/lib/core/framework/Install-IcingaFrameworkUpdate.psm1 @@ -13,7 +13,7 @@ function Install-IcingaFrameworkUpdate() }; } - Write-Host ([string]::Format('Installing module into "{0}"', ($Archive.Directory))); + Write-IcingaConsoleNotice ([string]::Format('Installing module into "{0}"', ($Archive.Directory))); Expand-IcingaZipArchive -Path $Archive.Archive -Destination $Archive.Directory | Out-Null; $FolderContent = Get-ChildItem -Path $Archive.Directory; @@ -26,12 +26,12 @@ function Install-IcingaFrameworkUpdate() } } - Write-Host ([string]::Format('Using content of folder "{0}" for updates', $ModuleContent)); + Write-IcingaConsoleNotice ([string]::Format('Using content of folder "{0}" for updates', $ModuleContent)); $ServiceStatus = (Get-Service 'icingapowershell' -ErrorAction SilentlyContinue).Status; if ($ServiceStatus -eq 'Running') { - Write-Host 'Stopping Icinga PowerShell service'; + Write-IcingaConsoleNotice 'Stopping Icinga PowerShell service'; Stop-IcingaService 'icingapowershell'; Start-Sleep -Seconds 1; } @@ -39,13 +39,13 @@ function Install-IcingaFrameworkUpdate() $ModuleDirectory = (Join-Path -Path $Archive.ModuleRoot -ChildPath $RepositoryName); if ((Test-Path $ModuleDirectory) -eq $FALSE) { - Write-Host 'Failed to update the component. Module Root-Directory was not found'; + Write-IcingaConsoleError 'Failed to update the component. Module Root-Directory was not found'; return; } $Files = Get-ChildItem $ModuleDirectory -File '*'; - Write-Host 'Removing files from framework'; + Write-IcingaConsoleNotice 'Removing files from framework'; foreach ($ModuleFile in $Files) { Remove-ItemSecure -Path $ModuleFile -Force | Out-Null; @@ -55,7 +55,7 @@ function Install-IcingaFrameworkUpdate() Remove-ItemSecure -Path (Join-Path $ModuleDirectory -ChildPath 'lib') -Recurse -Force | Out-Null; Remove-ItemSecure -Path (Join-Path $ModuleDirectory -ChildPath 'manifests') -Recurse -Force | Out-Null; - Write-Host 'Copying new files to framework'; + Write-IcingaConsoleNotice 'Copying new files to framework'; Copy-ItemSecure -Path (Join-Path $ModuleContent -ChildPath 'doc') -Destination $ModuleDirectory -Recurse -Force | Out-Null; Copy-ItemSecure -Path (Join-Path $ModuleContent -ChildPath 'lib') -Destination $ModuleDirectory -Recurse -Force | Out-Null; Copy-ItemSecure -Path (Join-Path $ModuleContent -ChildPath 'manifests') -Destination $ModuleDirectory -Recurse -Force | Out-Null; @@ -63,16 +63,16 @@ function Install-IcingaFrameworkUpdate() Unblock-IcingaPowerShellFiles -Path $ModuleDirectory; - Write-Host 'Cleaning temporary content'; + Write-IcingaConsoleNotice 'Cleaning temporary content'; Start-Sleep -Seconds 1; Remove-ItemSecure -Path $Archive.Directory -Recurse -Force | Out-Null; - Write-Host 'Framework update has been completed. Please start a new PowerShell instance now to complete the update'; + Write-IcingaConsoleNotice 'Framework update has been completed. Please start a new PowerShell instance now to complete the update'; Test-IcingaAgent; if ($ServiceStatus -eq 'Running') { - Write-Host 'Starting Icinga PowerShell service'; + Write-IcingaConsoleNotice 'Starting Icinga PowerShell service'; Start-IcingaService 'icingapowershell'; } } diff --git a/lib/core/framework/Remove-ItemSecure.psm1 b/lib/core/framework/Remove-ItemSecure.psm1 index 6c97c90..f284c1e 100644 --- a/lib/core/framework/Remove-ItemSecure.psm1 +++ b/lib/core/framework/Remove-ItemSecure.psm1 @@ -22,7 +22,7 @@ function Remove-ItemSecure() } return $TRUE; } catch { - Write-Host ([string]::Format('Failed to remove items from path "{0}": {1}', $Path, $_.Exception)) -ForegroundColor Red; + Write-IcingaConsoleError ([string]::Format('Failed to remove items from path "{0}": {1}', $Path, $_.Exception)); } return $FALSE; } diff --git a/lib/core/framework/Restart-IcingaService.psm1 b/lib/core/framework/Restart-IcingaService.psm1 index 4fc26e7..b6166e9 100644 --- a/lib/core/framework/Restart-IcingaService.psm1 +++ b/lib/core/framework/Restart-IcingaService.psm1 @@ -5,7 +5,7 @@ function Restart-IcingaService() ); if (Get-Service $Service -ErrorAction SilentlyContinue) { - Write-Host ([string]::Format('Restarting service "{0}"', $Service)); + Write-IcingaConsoleNotice ([string]::Format('Restarting service "{0}"', $Service)); Restart-Service $Service; } } diff --git a/lib/core/framework/Unblock-IcingaPowerShellFiles.psm1 b/lib/core/framework/Unblock-IcingaPowerShellFiles.psm1 index 9f6ef5c..afa6269 100644 --- a/lib/core/framework/Unblock-IcingaPowerShellFiles.psm1 +++ b/lib/core/framework/Unblock-IcingaPowerShellFiles.psm1 @@ -5,10 +5,10 @@ function Unblock-IcingaPowerShellFiles() ); if ([string]::IsNullOrEmpty($Path)) { - Write-Host 'The specified directory was not found'; + Write-IcingaConsoleError 'The specified directory was not found'; return; } - Write-Host 'Unblocking Icinga PowerShell Files'; + Write-IcingaConsoleNotice 'Unblocking Icinga PowerShell Files'; Get-ChildItem -Path $Path -Recurse | Unblock-File; } diff --git a/lib/core/framework/Uninstall-IcingaFrameworkService.psm1 b/lib/core/framework/Uninstall-IcingaFrameworkService.psm1 index 5c703b2..8c2c689 100644 --- a/lib/core/framework/Uninstall-IcingaFrameworkService.psm1 +++ b/lib/core/framework/Uninstall-IcingaFrameworkService.psm1 @@ -7,10 +7,10 @@ function Uninstall-IcingaFrameworkService() switch ($ServiceCreation.ExitCode) { 0 { - Write-Host 'Icinga PowerShell Service was successfully removed'; + Write-IcingaConsoleNotice 'Icinga PowerShell Service was successfully removed'; } 1060 { - Write-Host 'The Icinga PowerShell Service is not installed'; + Write-IcingaConsoleWarning 'The Icinga PowerShell Service is not installed'; } Default { throw ([string]::Format('Failed to install Icinga PowerShell Service: {0}{1}', $ServiceCreation.Message, $ServiceCreation.Error)); diff --git a/lib/core/icingaagent/firewall/Disable-IcingaFirewall.psm1 b/lib/core/icingaagent/firewall/Disable-IcingaFirewall.psm1 index 749d17c..d2cafe0 100644 --- a/lib/core/icingaagent/firewall/Disable-IcingaFirewall.psm1 +++ b/lib/core/icingaagent/firewall/Disable-IcingaFirewall.psm1 @@ -9,9 +9,9 @@ function Disable-IcingaFirewall() if ($FirewallConfig.LegacyFirewall) { $Firewall = Start-IcingaProcess -Executable 'netsh' -Arguments 'advfirewall firewall delete rule name="Icinga 2 Agent Inbound by PS-Module"'; if ($Firewall.ExitCode -ne 0) { - Write-Host ([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 { - Write-Host 'Successfully removed legacy Firewall rule'; + Write-IcingaConsoleNotice 'Successfully removed legacy Firewall rule'; } } @@ -22,9 +22,9 @@ function Disable-IcingaFirewall() if ($FirewallConfig.IcingaFirewall) { $Firewall = Start-IcingaProcess -Executable 'netsh' -Arguments 'advfirewall firewall delete rule name="Icinga Agent Inbound"'; if ($Firewall.ExitCode -ne 0) { - Write-Host ([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 { - Write-Host 'Successfully removed Icinga Firewall rule'; + Write-IcingaConsoleNotice 'Successfully removed Icinga Firewall rule'; } } } diff --git a/lib/core/icingaagent/firewall/Enable-IcingaFirewall.psm1 b/lib/core/icingaagent/firewall/Enable-IcingaFirewall.psm1 index 88b353c..1f8a18c 100644 --- a/lib/core/icingaagent/firewall/Enable-IcingaFirewall.psm1 +++ b/lib/core/icingaagent/firewall/Enable-IcingaFirewall.psm1 @@ -8,7 +8,7 @@ function Enable-IcingaFirewall() $FirewallConfig = Get-IcingaFirewallConfig -NoOutput; if ($FirewallConfig.IcingaFirewall -And $Force -eq $FALSE) { - Write-Host 'Icinga Firewall is already enabled' + Write-IcingaConsoleNotice 'Icinga Firewall is already enabled' return; } @@ -28,8 +28,8 @@ function Enable-IcingaFirewall() $FirewallResult = Start-IcingaProcess -Executable 'netsh' -Arguments $FirewallRule; if ($FirewallResult.ExitCode -ne 0) { - Write-Host ([string]::Format('Failed to open Icinga firewall for port "{0}": {1}[2}', $IcingaPort, $FirewallResult.Message, $FirewallResult.Error)); + Write-IcingaConsoleError ([string]::Format('Failed to open Icinga firewall for port "{0}": {1}[2}', $IcingaPort, $FirewallResult.Message, $FirewallResult.Error)); } else { - Write-Host ([string]::Format('Successfully enabled firewall for port "{0}"', $IcingaPort)); + Write-IcingaConsoleNotice ([string]::Format('Successfully enabled firewall for port "{0}"', $IcingaPort)); } } diff --git a/lib/core/icingaagent/firewall/Get-IcingaFirewallConfig.psm1 b/lib/core/icingaagent/firewall/Get-IcingaFirewallConfig.psm1 index 6caa144..1048b88 100644 --- a/lib/core/icingaagent/firewall/Get-IcingaFirewallConfig.psm1 +++ b/lib/core/icingaagent/firewall/Get-IcingaFirewallConfig.psm1 @@ -11,7 +11,7 @@ function Get-IcingaFirewallConfig() if ($LegacyFirewall.ExitCode -eq 0) { if ($NoOutput -eq $FALSE) { - Write-Host 'Legacy firewall configuration has been detected.'; + Write-IcingaConsoleWarning 'Legacy firewall configuration has been detected.'; } $LegacyFirewallPresent = $TRUE; } @@ -20,12 +20,12 @@ function Get-IcingaFirewallConfig() if ($IcingaFirewall.ExitCode -eq 0) { if ($NoOutput -eq $FALSE) { - Write-Host 'Icinga firewall is present.'; + Write-IcingaConsoleNotice 'Icinga firewall is present.'; } $IcingaFirewallPresent = $TRUE; } else { if ($NoOutput -eq $FALSE) { - Write-Host 'Icinga firewall is not present'; + Write-IcingaConsoleError 'Icinga firewall is not present'; } } diff --git a/lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1 b/lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1 index 132bfeb..580c6ff 100644 --- a/lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1 +++ b/lib/core/icingaagent/getters/Get-IcingaAgentMSIPackage.psm1 @@ -60,7 +60,7 @@ function Get-IcingaAgentMSIPackage() if ($SkipDownload -eq $FALSE) { $DownloadPath = Join-Path $Env:TEMP -ChildPath $UsePackage; - Write-Host ([string]::Format('Downloading Icinga 2 Agent installer "{0}" into temp directory "{1}"', $UsePackage, $DownloadPath)); + Write-IcingaConsoleNotice ([string]::Format('Downloading Icinga 2 Agent installer "{0}" into temp directory "{1}"', $UsePackage, $DownloadPath)); Invoke-WebRequest -Uri (Join-WebPath -Path $Source -ChildPath $UsePackage) -OutFile $DownloadPath; } diff --git a/lib/core/icingaagent/installer/Install-IcingaAgent.psm1 b/lib/core/icingaagent/installer/Install-IcingaAgent.psm1 index 7490a12..613faa6 100644 --- a/lib/core/icingaagent/installer/Install-IcingaAgent.psm1 +++ b/lib/core/icingaagent/installer/Install-IcingaAgent.psm1 @@ -8,12 +8,12 @@ function Install-IcingaAgent() ); if ([string]::IsNullOrEmpty($Version)) { - Write-Host 'No Icinga Agent version specified. Skipping installation.'; + Write-IcingaConsoleError 'No Icinga Agent version specified. Skipping installation.'; return $FALSE; } if ($IcingaData.Installed -eq $TRUE -and $AllowUpdates -eq $FALSE) { - Write-Host 'The Icinga Agent is already installed on this system. To perform updates or downgrades, please add the "-AllowUpdates" argument'; + Write-IcingaConsoleWarning 'The Icinga Agent is already installed on this system. To perform updates or downgrades, please add the "-AllowUpdates" argument'; return $FALSE; } @@ -24,12 +24,12 @@ function Install-IcingaAgent() if ($Version -eq 'snapshot') { if ($IcingaData.InstallDate -ge $IcingaInstaller.LastUpdate -And [string]::IsNullOrEmpty($InstalledVersion.Snapshot) -eq $FALSE) { - Write-Host 'There is no new snapshot package available which requires to be installed.' + Write-IcingaConsoleNotice 'There is no new snapshot package available which requires to be installed.' return $FALSE; } $IcingaInstaller.Version = 'snapshot'; } elseif ($IcingaInstaller.Version -eq $InstalledVersion.Full) { - Write-Host ([string]::Format( + Write-IcingaConsoleNotice ([string]::Format( 'No installation required. Your installed version [{0}] is matching the online version [{1}]', $InstalledVersion.Full, $IcingaInstaller.Version @@ -63,7 +63,7 @@ function Install-IcingaAgent() } } - Write-Host ([string]::Format('Installing new Icinga Agent version into "{0}"', $InstallFolderMsg)); + Write-IcingaConsoleNotice ([string]::Format('Installing new Icinga Agent version into "{0}"', $InstallFolderMsg)); if ($IcingaData.Installed) { if ((Uninstall-IcingaAgent) -eq $FALSE) { @@ -74,10 +74,10 @@ function Install-IcingaAgent() $InstallProcess = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('/quiet /i "{0}" {1}', $IcingaInstaller.InstallerPath, $InstallTarget)) -FlushNewLines; if ($InstallProcess.ExitCode -ne 0) { - Write-Host ([string]::Format('Failed to install Icinga 2 Agent: {0}{1}', $InstallProcess.Message, $InstallProcess.Error)); + Write-IcingaConsoleError -Message 'Failed to install Icinga 2 Agent: {0}{1}' -Objects $InstallProcess.Message, $InstallProcess.Error; return $FALSE; } - Write-Host 'Icinga Agent was successfully installed'; + Write-IcingaConsoleNotice 'Icinga Agent was successfully installed'; return $TRUE; } diff --git a/lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1 b/lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1 index 5a13f55..a82538d 100644 --- a/lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1 +++ b/lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1 @@ -26,7 +26,7 @@ function Install-IcingaAgentCertificates() } if (-Not (Test-IcingaAgentCertificates -CertDirectory $CertificateDirectory -Hostname $Hostname -Force $Force)) { - Write-Host ([string]::Format('Generating host certificates for host "{0}"', $Hostname)); + Write-IcingaConsoleNotice ([string]::Format('Generating host certificates for host "{0}"', $Hostname)); $arguments = [string]::Format('pki new-cert --cn {0} --key {1}{0}.key --cert {1}{0}.crt', $Hostname, @@ -39,14 +39,14 @@ function Install-IcingaAgentCertificates() } if ([string]::IsNullOrEmpty($Endpoint) -And [string]::IsNullOrEmpty($CACert)) { - Write-Host '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-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.'; return $TRUE; } if (-Not [string]::IsNullOrEmpty($Endpoint)) { if (-Not (Test-IcingaAgentCertificates -CertDirectory $CertificateDirectory -Hostname $Hostname -TestTrustedParent -Force $Force)) { - Write-Host ([string]::Format('Fetching trusted master certificate from "{0}"', $Endpoint)); + Write-IcingaConsoleNotice ([string]::Format('Fetching trusted master certificate from "{0}"', $Endpoint)); # Argument --key for save-cert is deprecated starting with Icinga 2.12.0 if (Compare-IcingaVersions -RequiredVersion '2.12.0') { @@ -65,7 +65,7 @@ function Install-IcingaAgentCertificates() } if ((Start-IcingaAgentCertificateProcess -Arguments $arguments) -eq $FALSE) { - Write-Host 'Unable to connect to your provided Icinga CA. Please verify the entered configuration is correct.' ` + Write-IcingaConsoleError 'Unable to connect to your provided Icinga CA. Please verify the entered configuration is correct.' ` 'If you are not able to connect to your Icinga CA from this machine, you will have to provide the path' ` 'to your Icinga ca.crt and use the CA-Proxy certificate handling.'; return $TRUE; @@ -92,9 +92,9 @@ function Install-IcingaAgentCertificates() } if ([string]::IsNullOrEmpty($Ticket)) { - Write-Host 'Your certificates were generated successfully. Please sign the certificate now on your Icinga CA master. You can lookup open requests with "icinga2 ca list"'; + Write-IcingaConsoleNotice 'Your certificates were generated successfully. Please sign the certificate now on your Icinga CA master. You can lookup open requests with "icinga2 ca list"'; } else { - Write-Host 'Icinga certificates successfully installed'; + Write-IcingaConsoleNotice 'Icinga certificates successfully installed'; } } @@ -103,7 +103,7 @@ function Install-IcingaAgentCertificates() if (-Not (Copy-IcingaAgentCACertificate -CAPath $CACert -Desination $CertificateDirectory)) { return $FALSE; } - Write-Host 'Host-Certificates and ca.crt are present. Please start your Icinga Agent now and manually sign your certificate request on your CA master. You can lookup open requests with "icinga2 ca list"'; + Write-IcingaConsoleNotice 'Host-Certificates and ca.crt are present. Please start your Icinga Agent now and manually sign your certificate request on your CA master. You can lookup open requests with "icinga2 ca list"'; } return $TRUE; @@ -119,11 +119,11 @@ function Start-IcingaAgentCertificateProcess() $Process = Start-IcingaProcess -Executable $Binary -Arguments $Arguments; if ($Process.ExitCode -ne 0) { - Write-Host ([string]::Format('Failed to create certificate.{0}Arguments: {1}{0}Error:{2} {3}', "`r`n", $Arguments, $Process.Message, $Process.Error)); + Write-IcingaConsoleError ([string]::Format('Failed to create certificate.{0}Arguments: {1}{0}Error:{2} {3}', "`r`n", $Arguments, $Process.Message, $Process.Error)); return $FALSE; } - Write-Host $Process.Message; + Write-IcingaConsoleNotice $Process.Message; return $TRUE; } @@ -156,20 +156,20 @@ function Test-IcingaAgentCertificates() if ($TestCACert) { if (Test-Path (Join-Path -Path $CertDirectory -ChildPath 'ca.crt')) { - Write-Host 'Your ca.crt is present. No generation or fetching required'; + Write-IcingaConsoleNotice 'Your ca.crt is present. No generation or fetching required'; return $TRUE; } else { - Write-Host 'Your ca.crt is not present. Manuall copy or fetching from your Icinga CA is required.'; + Write-IcingaConsoleWarning 'Your ca.crt is not present. Manuall copy or fetching from your Icinga CA is required.'; return $FALSE; } } if ($TestTrustedParent) { if (Test-Path (Join-Path -Path $CertDirectory -ChildPath 'trusted-parent.crt')) { - Write-Host 'Your trusted-parent.crt is present. No fetching or generation required'; + Write-IcingaConsoleNotice 'Your trusted-parent.crt is present. No fetching or generation required'; return $TRUE; } else { - Write-Host 'Your trusted master certificate is not present. Fetching from your CA server is required'; + Write-IcingaConsoleWarning 'Your trusted master certificate is not present. Fetching from your CA server is required'; return $FALSE; } } @@ -188,13 +188,13 @@ function Test-IcingaAgentCertificates() if ($cert.Name.toLower() -eq $hostCRT.toLower() -Or $cert.Name.toLower() -eq $hostKEY.toLower()) { $file = $cert.Name.Replace('.key', '').Replace('.crt', ''); if (-Not ($file -clike $Hostname)) { - Write-Host ([string]::Format('Certificate file {0} is not matching the hostname {1}. Certificate generation is required.', $cert.Name, $Hostname)); + Write-IcingaConsoleWarning ([string]::Format('Certificate file {0} is not matching the hostname {1}. Certificate generation is required.', $cert.Name, $Hostname)); return $FALSE; } } } - Write-Host 'Icinga host certificates are present and valid. No generation required.'; + Write-IcingaConsoleNotice 'Icinga host certificates are present and valid. No generation required.'; return $TRUE; } @@ -209,7 +209,7 @@ function Copy-IcingaAgentCACertificate() # Copy ca.crt from local path or network share to certificate path if ((Test-Path $CAPath)) { Copy-Item -Path $CAPath -Destination (Join-Path -Path $Desination -ChildPath 'ca.crt') | Out-Null; - Write-Host ([string]::Format('Copied ca.crt from "{0}" to "{1}', $CAPath, $Desination)); + Write-IcingaConsoleNotice ([string]::Format('Copied ca.crt from "{0}" to "{1}', $CAPath, $Desination)); } else { # It could also be a web ressource try { @@ -221,9 +221,9 @@ function Copy-IcingaAgentCACertificate() $response.RawContent.Length - $Index ); Set-Content -Path (Join-Path $Desination -ChildPath 'ca.crt') -Value $CAContent; - Write-Host ([string]::Format('Downloaded ca.crt from "{0}" to "{1}', $CAPath, $Desination)) + Write-IcingaConsoleNotice ([string]::Format('Downloaded ca.crt from "{0}" to "{1}', $CAPath, $Desination)) } catch { - Write-Host 'Failed to load any provided ca.crt ressource'; + Write-IcingaConsoleError 'Failed to load any provided ca.crt ressource'; return $FALSE; } } diff --git a/lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 b/lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 index cb99f8f..4fc8088 100644 --- a/lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 +++ b/lib/core/icingaagent/installer/Uninstall-IcingaAgent.psm1 @@ -3,21 +3,21 @@ function Uninstall-IcingaAgent() $IcingaData = Get-IcingaAgentInstallation; if ($IcingaData.Installed -eq $FALSE) { - Write-Host 'Unable to uninstall the Icinga Agent. The Agent is not installed'; + Write-IcingaConsoleError 'Unable to uninstall the Icinga Agent. The Agent is not installed'; return; } - Write-Host 'Removing current installed Icinga Agent'; + Write-IcingaConsoleNotice 'Removing current installed Icinga Agent'; Stop-IcingaService 'icinga2'; $Uninstaller = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('{0} /q', $IcingaData.Uninstaller)) -FlushNewLine; if ($Uninstaller.ExitCode -ne 0) { - Write-Host ([string]::Format('Failed to remove Icinga 2 Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error)); + Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga 2 Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error)); return $FALSE; } - Write-Host 'Icinga Agent was successfully removed'; + Write-IcingaConsoleNotice 'Icinga Agent was successfully removed'; return $TRUE; } diff --git a/lib/core/icingaagent/misc/Disable-IcingaAgentFeature.psm1 b/lib/core/icingaagent/misc/Disable-IcingaAgentFeature.psm1 index 983c340..4df1806 100644 --- a/lib/core/icingaagent/misc/Disable-IcingaAgentFeature.psm1 +++ b/lib/core/icingaagent/misc/Disable-IcingaAgentFeature.psm1 @@ -9,7 +9,7 @@ function Disable-IcingaAgentFeature() } if ((Test-IcingaAgentFeatureEnabled -Feature $Feature) -eq $FALSE) { - Write-Host ([string]::Format('This feature is already disabled [{0}]', $Feature)); + Write-IcingaConsoleWarning ([string]::Format('This feature is already disabled [{0}]', $Feature)); return; } @@ -20,5 +20,5 @@ function Disable-IcingaAgentFeature() throw ([string]::Format('Failed to disable Icinga Feature: {0}', $Process.Message)); } - Write-Host ([string]::Format('Feature "{0}" was successfully disabled', $Feature)); + Write-IcingaConsoleNotice ([string]::Format('Feature "{0}" was successfully disabled', $Feature)); } diff --git a/lib/core/icingaagent/misc/Enable-IcingaAgentFeature.psm1 b/lib/core/icingaagent/misc/Enable-IcingaAgentFeature.psm1 index 6721a61..beebc19 100644 --- a/lib/core/icingaagent/misc/Enable-IcingaAgentFeature.psm1 +++ b/lib/core/icingaagent/misc/Enable-IcingaAgentFeature.psm1 @@ -9,7 +9,7 @@ function Enable-IcingaAgentFeature() } if ((Test-IcingaAgentFeatureEnabled -Feature $Feature)) { - Write-Host ([string]::Format('This feature is already enabled [{0}]', $Feature)); + Write-IcingaConsoleWarning ([string]::Format('This feature is already enabled [{0}]', $Feature)); return; } @@ -20,5 +20,5 @@ function Enable-IcingaAgentFeature() throw ([string]::Format('Failed to enable Icinga Feature: {0}', $Process.Message)); } - Write-Host ([string]::Format('Feature "{0}" was successfully enabled', $Feature)); + Write-IcingaConsoleNotice ([string]::Format('Feature "{0}" was successfully enabled', $Feature)); } diff --git a/lib/core/icingaagent/misc/Move-IcingaAgentDefaultConfig.psm1 b/lib/core/icingaagent/misc/Move-IcingaAgentDefaultConfig.psm1 index 076761a..0a5f940 100644 --- a/lib/core/icingaagent/misc/Move-IcingaAgentDefaultConfig.psm1 +++ b/lib/core/icingaagent/misc/Move-IcingaAgentDefaultConfig.psm1 @@ -4,7 +4,7 @@ function Move-IcingaAgentDefaultConfig() $BackupFile = Join-Path -Path $ConfigDir -ChildPath 'ps_backup\backup_executed.key'; if ((Test-Path $BackupFile)) { - Write-Host 'A backup of your default configuration is not required. A backup was already made.'; + Write-IcingaConsoleNotice 'A backup of your default configuration is not required. A backup was already made.'; return; } @@ -19,5 +19,5 @@ function Move-IcingaAgentDefaultConfig() New-Item (Join-Path -Path $ConfigDir -ChildPath 'zones.conf') -ItemType File | Out-Null; New-Item -Path $BackupFile -ItemType File | Out-Null; - Write-Host 'Successfully backed up Icinga 2 Agent default config'; + Write-IcingaConsoleNotice 'Successfully backed up Icinga 2 Agent default config'; } diff --git a/lib/core/icingaagent/misc/Reset-IcingaAgentConfigFile.psm1 b/lib/core/icingaagent/misc/Reset-IcingaAgentConfigFile.psm1 index a51a005..43a7590 100644 --- a/lib/core/icingaagent/misc/Reset-IcingaAgentConfigFile.psm1 +++ b/lib/core/icingaagent/misc/Reset-IcingaAgentConfigFile.psm1 @@ -22,7 +22,7 @@ function Reset-IcingaAgentConfigFile() $OriginalConfig = Join-Path -Path $ConfigDir -ChildPath 'icinga2.confdirector.bak'; if ((Test-Path $OriginalConfig)) { - Write-Host 'Found icinga2.conf backup file created by old PowerShell module. Restoring original configuration'; + Write-IcingaConsoleWarning 'Found icinga2.conf backup file created by old PowerShell module. Restoring original configuration'; Move-Item -Path $OldConfig -Destination $OldConfigBackup; Move-Item -Path $OriginalConfig -Destination $OldConfig; diff --git a/lib/core/icingaagent/misc/Show-IcingaAgentObjects.psm1 b/lib/core/icingaagent/misc/Show-IcingaAgentObjects.psm1 index 07f4aae..b53bdaf 100644 --- a/lib/core/icingaagent/misc/Show-IcingaAgentObjects.psm1 +++ b/lib/core/icingaagent/misc/Show-IcingaAgentObjects.psm1 @@ -4,7 +4,7 @@ function Show-IcingaAgentObjects() $Output = Start-IcingaProcess -Executable $Binary -Arguments 'object list'; if ($Output.ExitCode -ne 0) { - Write-Host ([string]::Format('Failed to fetch Icinga Agent objects list: {0}{1}', $Output.Message, $Output.Error)); + Write-IcingaConsoleError ([string]::Format('Failed to fetch Icinga Agent objects list: {0}{1}', $Output.Message, $Output.Error)); return $null; } diff --git a/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 b/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 index e7cb29f..d77faf0 100644 --- a/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 +++ b/lib/core/icingaagent/misc/Start-IcingaAgentDirectorWizard.psm1 @@ -57,7 +57,7 @@ function Start-IcingaAgentDirectorWizard() 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)); + Write-IcingaConsoleError ([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) ` @@ -88,7 +88,7 @@ function Start-IcingaAgentDirectorWizard() # Host is already registered if ($null -eq $SelfServiceAPIKey) { - Write-Host 'The wizard is unable to complete as this host is already registered but the local API key is not stored within the config' + Write-IcingaConsoleError 'The wizard is unable to complete as this host is already registered but the local API key is not stored within the config' return; } @@ -135,8 +135,8 @@ function Start-IcingaDirectorAPIArgumentOverride() ); $NewArguments = @{}; - Write-Host 'Please follow the wizard and manually override all entries you intend to'; - Write-Host '===='; + Write-IcingaConsoleNotice 'Please follow the wizard and manually override all entries you intend to'; + Write-IcingaConsoleNotice '===='; foreach ($entry in $Arguments.Keys) { $value = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Please enter the new value for the argument "{0}"', $entry)) -Default 'v' -DefaultInput $Arguments[$entry]).answer; diff --git a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 index 81e3551..ea33ddf 100644 --- a/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 +++ b/lib/core/icingaagent/misc/Start-IcingaAgentInstallWizard.psm1 @@ -171,7 +171,7 @@ function Start-IcingaAgentInstallWizard() } } - Write-Host ([string]::Format('Using hostname "{0}" for the Icinga 2 Agent configuration', $Hostname)); + Write-IcingaConsoleNotice ([string]::Format('Using hostname "{0}" for the Icinga 2 Agent configuration', $Hostname)); $IcingaAgent = Get-IcingaAgentInstallation; if ($IcingaAgent.Installed -eq $FALSE) { @@ -185,7 +185,7 @@ function Start-IcingaAgentInstallWizard() $InstallerArguments += "-PackageSource '$PackageSource'"; } - Write-Host ([string]::Format('Using package source "{0}" for the Icinga 2 Agent package', $PackageSource)); + Write-IcingaConsoleNotice ([string]::Format('Using package source "{0}" for the Icinga 2 Agent package', $PackageSource)); $AllowVersionChanges = $TRUE; $InstallerArguments += '-AllowVersionChanges 1'; @@ -193,7 +193,7 @@ function Start-IcingaAgentInstallWizard() $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'"; - Write-Host ([string]::Format('Installing Icinga Version: "{0}"', $AgentVersion)); + Write-IcingaConsoleNotice ([string]::Format('Installing Icinga Version: "{0}"', $AgentVersion)); } } else { $AllowVersionChanges = $FALSE; @@ -221,7 +221,7 @@ function Start-IcingaAgentInstallWizard() $AgentVersion = (Get-IcingaAgentInstallerAnswerInput -Prompt 'Please specify the version you wish to install ("latest", "snapshot", or a version like "2.11.0")' -Default 'v').answer; $InstallerArguments += "-AgentVersion '$AgentVersion'"; - Write-Host ([string]::Format('Updating/Downgrading Icinga 2 Agent to version: "{0}"', $AgentVersion)); + Write-IcingaConsoleNotice ([string]::Format('Updating/Downgrading Icinga 2 Agent to version: "{0}"', $AgentVersion)); } if ([string]::IsNullOrEmpty($PackageSource)) { @@ -456,23 +456,23 @@ function Start-IcingaAgentInstallWizard() if ($InstallerArguments.Count -ne 0) { $InstallerArguments += "-RunInstaller"; - Write-Host 'The wizard is complete. These are the configured settings:'; + Write-IcingaConsoleNotice 'The wizard is complete. These are the configured settings:'; - Write-Host '========' - Write-Host ($InstallerArguments | Out-String); - Write-Host '========' + Write-IcingaConsolePlain '========'; + Write-IcingaConsolePlain ($InstallerArguments | Out-String); + Write-IcingaConsolePlain '========'; if (-Not $RunInstaller) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Is this configuration correct?' -Default 'y').result -eq 1) { if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you want to run the installer now? (Otherwise only the configuration command will be printed)' -Default 'y').result -eq 1) { - Write-Host 'To execute your Icinga Agent installation based on your answers again on this or another machine, simply run this command:' + Write-IcingaConsoleNotice '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:' + Write-IcingaConsoleNotice '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:' + Write-IcingaConsoleNotice 'Please run the wizard again to modify your answers or modify the command below:'; } } Get-IcingaAgentInstallCommand -InstallerArguments $InstallerArguments -PrintConsole; @@ -681,9 +681,9 @@ function Get-IcingaAgentInstallCommand() ); if ($PrintConsole) { - Write-Host '====' - Write-Host $Installer -ForegroundColor ([System.ConsoleColor]::Cyan); - Write-Host '====' + Write-IcingaConsolePlain '====' + Write-IcingaConsolePlain $Installer; + Write-IcingaConsolePlain '====' } else { return $Installer; } diff --git a/lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 b/lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 index 992fb43..139dfe6 100644 --- a/lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 +++ b/lib/core/icingaagent/readers/Read-IcingaAgentDebugLogFile.psm1 @@ -2,7 +2,7 @@ function Read-IcingaAgentDebugLogFile() { $Logfile = Join-Path -Path (Get-IcingaAgentLogDirectory) -ChildPath 'debug.log'; if ((Test-Path $Logfile) -eq $FALSE) { - Write-Host 'Icinga 2 debug logfile not present. Unable to load it'; + Write-IcingaConsoleError 'Icinga 2 debug logfile not present. Unable to load it'; return; } diff --git a/lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 b/lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 index 8ce56bf..a277265 100644 --- a/lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 +++ b/lib/core/icingaagent/readers/Read-IcingaAgentLogFile.psm1 @@ -2,7 +2,7 @@ function Read-IcingaAgentLogFile() { $Logfile = Join-Path -Path (Get-IcingaAgentLogDirectory) -ChildPath 'icinga2.log'; if ((Test-Path $Logfile) -eq $FALSE) { - Write-Host 'Icinga 2 logfile not present. Unable to load it'; + Write-IcingaConsoleError 'Icinga 2 logfile not present. Unable to load it'; return; } diff --git a/lib/core/icingaagent/setters/Set-IcingaAgentNodeName.psm1 b/lib/core/icingaagent/setters/Set-IcingaAgentNodeName.psm1 index 4956b41..6262823 100644 --- a/lib/core/icingaagent/setters/Set-IcingaAgentNodeName.psm1 +++ b/lib/core/icingaagent/setters/Set-IcingaAgentNodeName.psm1 @@ -31,5 +31,5 @@ function Set-IcingaAgentNodeName() Set-Content -Path $ConstantsConf -Value $ConfigContent; - Write-Host ([string]::Format('Your hostname was successfully changed to "{0}"', $Hostname)); + Write-IcingaConsoleNotice ([string]::Format('Your hostname was successfully changed to "{0}"', $Hostname)); } diff --git a/lib/core/icingaagent/setters/Set-IcingaAgentServicePermission.psm1 b/lib/core/icingaagent/setters/Set-IcingaAgentServicePermission.psm1 index a166b26..ff38c78 100644 --- a/lib/core/icingaagent/setters/Set-IcingaAgentServicePermission.psm1 +++ b/lib/core/icingaagent/setters/Set-IcingaAgentServicePermission.psm1 @@ -1,7 +1,7 @@ function Set-IcingaAgentServicePermission() { if (Test-IcingaAgentServicePermission -Silent) { - Write-Host 'The Icinga Service User already has permission to run as service'; + Write-IcingaConsoleNotice 'The Icinga Service User already has permission to run as service'; return; } diff --git a/lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1 b/lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1 index 5c1ef0b..c4d79e2 100644 --- a/lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1 +++ b/lib/core/icingaagent/setters/Set-IcingaAgentServiceUser.psm1 @@ -32,10 +32,10 @@ function Set-IcingaAgentServiceUser() Set-IcingaUserPermissions; } - Write-Host 'Service User successfully updated' + Write-IcingaConsoleNotice 'Service User successfully updated' return $TRUE; } else { - Write-Host ([string]::Format('Failed to update the service user: {0}', $Output.Message)); + Write-IcingaConsoleError ([string]::Format('Failed to update the service user: {0}', $Output.Message)); return $FALSE; } } diff --git a/lib/core/icingaagent/tests/Test-IcingaAcl.psm1 b/lib/core/icingaagent/tests/Test-IcingaAcl.psm1 index b69cb3c..249e7a3 100644 --- a/lib/core/icingaagent/tests/Test-IcingaAcl.psm1 +++ b/lib/core/icingaagent/tests/Test-IcingaAcl.psm1 @@ -41,11 +41,11 @@ function Test-IcingaAcl() Write-IcingaTestOutput -Severity 'PASSED' -Message ([string]::Format($messageFormat, $Directory, 'is accessible and writeable', $ServiceUser)); } else { Write-IcingaTestOutput -Severity 'FAILED' -Message ([string]::Format($messageFormat, $Directory, 'is accessible but NOT writeable', $ServiceUser)); - Write-Host "\_ 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 { Write-IcingaTestOutput -Severity 'FAILED' -Message ([string]::Format($messageFormat, $Directory, 'is not accessible', $ServiceUser)); - Write-Host "\_ 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'"; } } diff --git a/lib/core/icingaagent/tests/Test-IcingaAgentConfig.psm1 b/lib/core/icingaagent/tests/Test-IcingaAgentConfig.psm1 index 42b78a6..3dc55ab 100644 --- a/lib/core/icingaagent/tests/Test-IcingaAgentConfig.psm1 +++ b/lib/core/icingaagent/tests/Test-IcingaAgentConfig.psm1 @@ -13,7 +13,7 @@ function Test-IcingaAgentConfig() } 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"'; if ($WriteStackTrace) { - Write-Host $ConfigResult.Message; + Write-IcingaConsolePlain $ConfigResult.Message; } return $FALSE; } diff --git a/lib/core/icingaagent/writers/Write-IcingaAgentApiConfig.psm1 b/lib/core/icingaagent/writers/Write-IcingaAgentApiConfig.psm1 index 50a235f..0d51505 100644 --- a/lib/core/icingaagent/writers/Write-IcingaAgentApiConfig.psm1 +++ b/lib/core/icingaagent/writers/Write-IcingaAgentApiConfig.psm1 @@ -16,5 +16,5 @@ function Write-IcingaAgentApiConfig() $ApiConf = $ApiConf.Substring(0, $ApiConf.Length - 4); Set-Content -Path (Join-Path -Path (Get-IcingaAgentConfigDirectory) -ChildPath 'features-available\api.conf') -Value $ApiConf; - Write-Host 'Api configuration has been written successfully'; + Write-IcingaConsoleNotice 'Api configuration has been written successfully'; } diff --git a/lib/core/icingaagent/writers/Write-IcingaAgentZonesConfig.psm1 b/lib/core/icingaagent/writers/Write-IcingaAgentZonesConfig.psm1 index 4729226..bd0ff6f 100644 --- a/lib/core/icingaagent/writers/Write-IcingaAgentZonesConfig.psm1 +++ b/lib/core/icingaagent/writers/Write-IcingaAgentZonesConfig.psm1 @@ -74,5 +74,5 @@ function Write-IcingaAgentZonesConfig() $ZonesConf = $ZonesConf.Substring(0, $ZonesConf.Length - 4); Set-Content -Path (Join-Path -Path (Get-IcingaAgentConfigDirectory) -ChildPath 'zones.conf') -Value $ZonesConf; - Write-Host 'Icinga Agent zones.conf has been written successfully'; + Write-IcingaConsoleNotice 'Icinga Agent zones.conf has been written successfully'; } diff --git a/lib/core/logging/Write-IcingaConsoleDebug.psm1 b/lib/core/logging/Write-IcingaConsoleDebug.psm1 new file mode 100644 index 0000000..717d950 --- /dev/null +++ b/lib/core/logging/Write-IcingaConsoleDebug.psm1 @@ -0,0 +1,34 @@ +<# +.SYNOPSIS + Default Cmdlet for printing debug messages to console +.DESCRIPTION + Default Cmdlet for printing debug messages to console +.FUNCTIONALITY + Default Cmdlet for printing debug messages to console +.EXAMPLE + PS>Write-IcingaConsoleDebug -Message 'Test message: {0}' -Objects 'Hello World'; +.PARAMETER Message + The message to print with {x} placeholdes replaced by content inside the Objects array. Replace x with the + number of the index from the objects array +.PARAMETER Objects + An array of objects being added to a provided message. The index of the array position has to refer to the + message locations. +.INPUTS + System.String +.LINK + https://github.com/Icinga/icinga-powershell-framework +#> + +function Write-IcingaConsoleDebug() +{ + param ( + [string]$Message, + [array]$Objects + ); + + Write-IcingaConsoleOutput ` + -Message $Message ` + -Objects $Objects ` + -ForeColor 'Blue' ` + -Severity 'Debug'; +} diff --git a/lib/core/logging/Write-IcingaConsoleError.psm1 b/lib/core/logging/Write-IcingaConsoleError.psm1 new file mode 100644 index 0000000..895a6b1 --- /dev/null +++ b/lib/core/logging/Write-IcingaConsoleError.psm1 @@ -0,0 +1,34 @@ +<# +.SYNOPSIS + Default Cmdlet for printing error messages to console +.DESCRIPTION + Default Cmdlet for printing error messages to console +.FUNCTIONALITY + Default Cmdlet for printing error messages to console +.EXAMPLE + PS>Write-IcingaConsoleError -Message 'Test message: {0}' -Objects 'Hello World'; +.PARAMETER Message + The message to print with {x} placeholdes replaced by content inside the Objects array. Replace x with the + number of the index from the objects array +.PARAMETER Objects + An array of objects being added to a provided message. The index of the array position has to refer to the + message locations. +.INPUTS + System.String +.LINK + https://github.com/Icinga/icinga-powershell-framework +#> + +function Write-IcingaConsoleError() +{ + param ( + [string]$Message, + [array]$Objects + ); + + Write-IcingaConsoleOutput ` + -Message $Message ` + -Objects $Objects ` + -ForeColor 'Red' ` + -Severity 'Error'; +} diff --git a/lib/core/logging/Write-IcingaConsoleNotice.psm1 b/lib/core/logging/Write-IcingaConsoleNotice.psm1 new file mode 100644 index 0000000..44939fa --- /dev/null +++ b/lib/core/logging/Write-IcingaConsoleNotice.psm1 @@ -0,0 +1,34 @@ +<# +.SYNOPSIS + Default Cmdlet for printing notice messages to console +.DESCRIPTION + Default Cmdlet for printing notice messages to console +.FUNCTIONALITY + Default Cmdlet for printing notice messages to console +.EXAMPLE + PS>Write-IcingaConsoleNotice -Message 'Test message: {0}' -Objects 'Hello World'; +.PARAMETER Message + The message to print with {x} placeholdes replaced by content inside the Objects array. Replace x with the + number of the index from the objects array +.PARAMETER Objects + An array of objects being added to a provided message. The index of the array position has to refer to the + message locations. +.INPUTS + System.String +.LINK + https://github.com/Icinga/icinga-powershell-framework +#> + +function Write-IcingaConsoleNotice() +{ + param ( + [string]$Message, + [array]$Objects + ); + + Write-IcingaConsoleOutput ` + -Message $Message ` + -Objects $Objects ` + -ForeColor 'Green' ` + -Severity 'Notice'; +} diff --git a/lib/core/logging/Write-IcingaConsoleOutput.psm1 b/lib/core/logging/Write-IcingaConsoleOutput.psm1 new file mode 100644 index 0000000..6a51bdc --- /dev/null +++ b/lib/core/logging/Write-IcingaConsoleOutput.psm1 @@ -0,0 +1,58 @@ +<# +.SYNOPSIS + Standardise console output and make handling of object conversion easier into messages + by using this standard function for displaying severity and log entries +.DESCRIPTION + Standardised function to output console messages controlled by the arguments provided + for coloring, displaying severity and add objects into output messages +.FUNCTIONALITY + Standardise console output and make handling of object conversion easier into messages + by using this standard function for displaying severity and log entries +.EXAMPLE + PS>Write-IcingaConsoleOutput -Message 'Test message: {0}' -Objects 'Hello World' -ForeColor 'Green' -Severity 'Test'; +.PARAMETER Message + The message to print with {x} placeholdes replaced by content inside the Objects array. Replace x with the + number of the index from the objects array +.PARAMETER Objects + An array of objects being added to a provided message. The index of the array position has to refer to the + message locations. +.PARAMETER ForeColor + The color the severity name will be displayed in +.PARAMETER Severity + The severity being displayed before the actual message. Leave empty to skip. +.INPUTS + System.String +.LINK + https://github.com/Icinga/icinga-powershell-framework +#> + +function Write-IcingaConsoleOutput() +{ + param ( + [string]$Message, + [array]$Objects, + [ValidateSet('Black', 'DarkBlue', 'DarkGreen', 'DarkCyan', 'DarkRed', 'DarkMagenta', 'DarkYellow', 'Gray', 'DarkGray', 'Blue', 'Green', 'Cyan', 'Red', 'Magenta', 'Yellow', 'White')] + [string]$ForeColor = 'White', + [string]$Severity = 'Notice' + ); + + $OutputMessage = $Message; + [int]$Index = 0; + + foreach ($entry in $Objects) { + + $OutputMessage = $OutputMessage.Replace( + [string]::Format('{0}{1}{2}', '{', $Index, '}'), + $entry + ); + $Index++; + } + + if ([string]::IsNullOrEmpty($Severity) -eq $FALSE) { + Write-Host '[' -NoNewline; + Write-Host $Severity -NoNewline -ForegroundColor $ForeColor; + Write-Host ']: ' -NoNewline; + } + + Write-Host $OutputMessage; +} diff --git a/lib/core/logging/Write-IcingaConsolePlain.psm1 b/lib/core/logging/Write-IcingaConsolePlain.psm1 new file mode 100644 index 0000000..35c1de7 --- /dev/null +++ b/lib/core/logging/Write-IcingaConsolePlain.psm1 @@ -0,0 +1,34 @@ +<# +.SYNOPSIS + Default Cmdlet for printing plain messages to console +.DESCRIPTION + Default Cmdlet for printing plain messages to console +.FUNCTIONALITY + Default Cmdlet for printing plain messages to console +.EXAMPLE + PS>Write-IcingaConsolePlain -Message 'Test message: {0}' -Objects 'Hello World'; +.PARAMETER Message + The message to print with {x} placeholdes replaced by content inside the Objects array. Replace x with the + number of the index from the objects array +.PARAMETER Objects + An array of objects being added to a provided message. The index of the array position has to refer to the + message locations. +.INPUTS + System.String +.LINK + https://github.com/Icinga/icinga-powershell-framework +#> + +function Write-IcingaConsolePlain() +{ + param ( + [string]$Message, + [array]$Objects + ); + + Write-IcingaConsoleOutput ` + -Message $Message ` + -Objects $Objects ` + -ForeColor 'Blue' ` + -Severity $null; +} diff --git a/lib/core/logging/Write-IcingaConsoleWarning.psm1 b/lib/core/logging/Write-IcingaConsoleWarning.psm1 new file mode 100644 index 0000000..b7f7097 --- /dev/null +++ b/lib/core/logging/Write-IcingaConsoleWarning.psm1 @@ -0,0 +1,34 @@ +<# +.SYNOPSIS + Default Cmdlet for printing warning messages to console +.DESCRIPTION + Default Cmdlet for printing warning messages to console +.FUNCTIONALITY + Default Cmdlet for printing warning messages to console +.EXAMPLE + PS>Write-IcingaConsoleWarning -Message 'Test message: {0}' -Objects 'Hello World'; +.PARAMETER Message + The message to print with {x} placeholdes replaced by content inside the Objects array. Replace x with the + number of the index from the objects array +.PARAMETER Objects + An array of objects being added to a provided message. The index of the array position has to refer to the + message locations. +.INPUTS + System.String +.LINK + https://github.com/Icinga/icinga-powershell-framework +#> + +function Write-IcingaConsoleWarning() +{ + param ( + [string]$Message, + [array]$Objects + ); + + Write-IcingaConsoleOutput ` + -Message $Message ` + -Objects $Objects ` + -ForeColor 'Yellow' ` + -Severity 'Warning'; +} diff --git a/lib/core/tools/Expand-IcingaIPv6String.psm1 b/lib/core/tools/Expand-IcingaIPv6String.psm1 index 8637b89..423a7ed 100644 --- a/lib/core/tools/Expand-IcingaIPv6String.psm1 +++ b/lib/core/tools/Expand-IcingaIPv6String.psm1 @@ -41,7 +41,7 @@ function Expand-IcingaIPv6String() } if ($RelV -lt 0 -and $Counter -ne 7) { - Write-Host "Invalid IP was provided!"; + Write-IcingaConsoleError "Invalid IP was provided!"; return $null; } diff --git a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 index 8e52e0f..668c4fc 100644 --- a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 +++ b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 @@ -320,19 +320,19 @@ function Get-IcingaCheckCommandConfig() Set-Content -Path $OutDirectory -Value $output; # Output-Text - Write-Host "The following commands have been exported:" + Write-IcingaConsoleNotice "The following commands have been exported:" foreach ($check in $CheckName) { - Write-Host "- '$check'"; + Write-IcingaConsoleNotice "- '$check'"; } - Write-Host "JSON export created in '${OutDirectory}'" + Write-IcingaConsoleNotice "JSON export created in '${OutDirectory}'" return; } - Write-Host "Check Command JSON for the following commands:" + Write-IcingaConsoleNotice "Check Command JSON for the following commands:" foreach ($check in $CheckName) { - Write-Host "- '$check'" + Write-IcingaConsoleNotice "- '$check'" } - Write-Host '############################################################'; + Write-IcingaConsoleNotice '############################################################'; return $output; } diff --git a/lib/core/tools/Get-IcingaNetworkInterface.psm1 b/lib/core/tools/Get-IcingaNetworkInterface.psm1 index ad72151..7fa0d7b 100644 --- a/lib/core/tools/Get-IcingaNetworkInterface.psm1 +++ b/lib/core/tools/Get-IcingaNetworkInterface.psm1 @@ -32,14 +32,14 @@ function Get-IcingaNetworkInterface() ); if ([string]::IsNullOrEmpty($IP)) { - Write-Host 'Please specify a valid IP-Address or FQDN'; + Write-IcingaConsoleError 'Please specify a valid IP-Address or FQDN'; return $null; } try { [array]$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString; } catch { - Write-Host 'Invalid IP was provided!'; + Write-IcingaConsoleError 'Invalid IP was provided!'; return $null; } diff --git a/lib/core/tools/New-IcingaCheckCommand.psm1 b/lib/core/tools/New-IcingaCheckCommand.psm1 index ddee00c..042c5b7 100644 --- a/lib/core/tools/New-IcingaCheckCommand.psm1 +++ b/lib/core/tools/New-IcingaCheckCommand.psm1 @@ -96,7 +96,7 @@ function New-IcingaCheckCommand() Add-Content -Path $ScriptFile -Value "}"; - Write-Host ([string]::Format('The Check-Command "{0}" was successfully added.', $CommandName)); + Write-IcingaConsoleNotice ([string]::Format('The Check-Command "{0}" was successfully added.', $CommandName)); # Try to open the default Editor for the new Cmdlet $DefaultEditor = (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.psm1\OpenWithList' -Name a).a; @@ -115,7 +115,7 @@ function New-IcingaCheckCommand() Import-Module $ScriptFile -Global; if ([string]::IsNullOrEmpty($DefaultEditor) -eq $FALSE -And ($null -eq (Get-Command $DefaultEditor -ErrorAction SilentlyContinue)) -And ((Test-Path $DefaultEditor) -eq $FALSE)) { - Write-Host 'No default editor for .psm1 files found. Specify a default editor to automaticly open the newly generated check plugin.'; + Write-IcingaConsoleWarning 'No default editor for .psm1 files found. Specify a default editor to automaticly open the newly generated check plugin.'; return; } diff --git a/lib/core/tools/Remove-IcingaDirectorSelfServiceKey.psm1 b/lib/core/tools/Remove-IcingaDirectorSelfServiceKey.psm1 index 6f30b34..3aa608a 100644 --- a/lib/core/tools/Remove-IcingaDirectorSelfServiceKey.psm1 +++ b/lib/core/tools/Remove-IcingaDirectorSelfServiceKey.psm1 @@ -6,9 +6,9 @@ function Remove-IcingaDirectorSelfServiceKey() Remove-IcingaPowerShellConfig 'IcingaDirector.SelfService.ApiKey'; $Value = Get-IcingaPowerShellConfig $Path; if ($null -eq $Value) { - Write-Host 'Icinga Director Self-Service Api key was successfully removed. Please dont forget to drop it within the Icinga Director as well'; + Write-IcingaConsoleNotice 'Icinga Director Self-Service Api key was successfully removed. Please dont forget to drop it within the Icinga Director as well'; } } else { - Write-Host 'There is no Self-Service Api key configured on this system'; + Write-IcingaConsoleWarning 'There is no Self-Service Api key configured on this system'; } } diff --git a/lib/core/tools/Show-IcingaDirectorSelfServiceKey.psm1 b/lib/core/tools/Show-IcingaDirectorSelfServiceKey.psm1 index 806ad98..94103c6 100644 --- a/lib/core/tools/Show-IcingaDirectorSelfServiceKey.psm1 +++ b/lib/core/tools/Show-IcingaDirectorSelfServiceKey.psm1 @@ -4,8 +4,8 @@ function Show-IcingaDirecorSelfServiceKey() $Value = Get-IcingaPowerShellConfig $Path; if ($null -ne $Value) { - Write-Host ([string]::Format('Self-Service Key: "{0}"', $Value)); + Write-IcingaConsoleNotice ([string]::Format('Self-Service Key: "{0}"', $Value)); } else { - Write-Host 'There is no Self-Service Api key configured on this system'; + Write-IcingaConsoleWarning 'There is no Self-Service Api key configured on this system'; } } diff --git a/lib/daemon/Register-IcingaBackgroundDaemon.psm1 b/lib/daemon/Register-IcingaBackgroundDaemon.psm1 index 83aa6b7..3a47438 100644 --- a/lib/daemon/Register-IcingaBackgroundDaemon.psm1 +++ b/lib/daemon/Register-IcingaBackgroundDaemon.psm1 @@ -18,5 +18,5 @@ function Register-IcingaBackgroundDaemon() Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Command', $Path)) -Value $Command; Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Arguments', $Path)) -Value $Arguments; - Write-Host ([string]::Format('Background daemon Cmdlet "{0}" has been configured', $Command)); + Write-IcingaConsoleNotice ([string]::Format('Background daemon Cmdlet "{0}" has been configured', $Command)); } diff --git a/lib/daemon/Unregister-IcingaBackgroundDaemon.psm1 b/lib/daemon/Unregister-IcingaBackgroundDaemon.psm1 index a836b11..19fa89c 100644 --- a/lib/daemon/Unregister-IcingaBackgroundDaemon.psm1 +++ b/lib/daemon/Unregister-IcingaBackgroundDaemon.psm1 @@ -13,5 +13,5 @@ function Unregister-IcingaBackgroundDaemon() Remove-IcingaPowerShellConfig -Path $Path; - Write-Host 'Background daemon has been removed'; + Write-IcingaConsoleNotice 'Background daemon has been removed'; } diff --git a/lib/daemons/ServiceCheckDaemon/Register-IcingaServiceCheck.psm1 b/lib/daemons/ServiceCheckDaemon/Register-IcingaServiceCheck.psm1 index 2492950..9dd1ed3 100644 --- a/lib/daemons/ServiceCheckDaemon/Register-IcingaServiceCheck.psm1 +++ b/lib/daemons/ServiceCheckDaemon/Register-IcingaServiceCheck.psm1 @@ -19,5 +19,5 @@ function Register-IcingaServiceCheck() Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Interval', $Path)) -Value $Interval; Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.TimeIndexes', $Path)) -Value $TimeIndexes; - Write-Host 'Icinga Service Check has been configured'; + Write-IcingaConsoleNotice 'Icinga Service Check has been configured'; } diff --git a/lib/daemons/ServiceCheckDaemon/Set-IcingaRegisteredServiceCheckConfig.psm1 b/lib/daemons/ServiceCheckDaemon/Set-IcingaRegisteredServiceCheckConfig.psm1 index 9edc6b5..7e7e25d 100644 --- a/lib/daemons/ServiceCheckDaemon/Set-IcingaRegisteredServiceCheckConfig.psm1 +++ b/lib/daemons/ServiceCheckDaemon/Set-IcingaRegisteredServiceCheckConfig.psm1 @@ -10,7 +10,7 @@ function Set-IcingaRegisteredServiceCheckConfig() $Services = Get-IcingaRegisteredServiceChecks; if ($Services.ContainsKey($ServiceId) -eq $FALSE) { - Write-Host 'Service Id was not found'; + Write-IcingaConsoleError 'Service Id was not found'; return; } @@ -31,8 +31,8 @@ function Set-IcingaRegisteredServiceCheckConfig() } if ($Modified) { - Write-Host 'Service configuration was successfully updated'; + Write-IcingaConsoleNotice 'Service configuration was successfully updated'; } else { - Write-Host 'No arguments were specified to update the service configuraiton'; + Write-IcingaConsoleWarning 'No arguments were specified to update the service configuration'; } } diff --git a/lib/daemons/ServiceCheckDaemon/Show-IcingaRegisteredServiceChecks.psm1 b/lib/daemons/ServiceCheckDaemon/Show-IcingaRegisteredServiceChecks.psm1 index 69af178..6dc248c 100644 --- a/lib/daemons/ServiceCheckDaemon/Show-IcingaRegisteredServiceChecks.psm1 +++ b/lib/daemons/ServiceCheckDaemon/Show-IcingaRegisteredServiceChecks.psm1 @@ -3,8 +3,8 @@ function Show-IcingaRegisteredServiceChecks() $Services = Get-IcingaRegisteredServiceChecks; foreach ($service in $Services.Keys) { - Write-Host ([string]::Format('Service Id: {0}', $service)); - Write-Host ( + Write-IcingaConsoleNotice ([string]::Format('Service Id: {0}', $service)); + Write-IcingaConsoleNotice ( $Services[$service] | Out-String ); } diff --git a/lib/daemons/ServiceCheckDaemon/Unregister-IcingaServiceCheck.psm1 b/lib/daemons/ServiceCheckDaemon/Unregister-IcingaServiceCheck.psm1 index 9285a11..02f4a96 100644 --- a/lib/daemons/ServiceCheckDaemon/Unregister-IcingaServiceCheck.psm1 +++ b/lib/daemons/ServiceCheckDaemon/Unregister-IcingaServiceCheck.psm1 @@ -12,5 +12,5 @@ function Unregister-IcingaServiceCheck() Remove-IcingaPowerShellConfig -Path $Path; - Write-Host 'Icinga Service Check has been configured'; + Write-IcingaConsolePlain 'Icinga Service Check has been configured'; } diff --git a/lib/help/help/Get-IcingaHelpThresholds.psm1 b/lib/help/help/Get-IcingaHelpThresholds.psm1 index eb79706..388e8b4 100644 --- a/lib/help/help/Get-IcingaHelpThresholds.psm1 +++ b/lib/help/help/Get-IcingaHelpThresholds.psm1 @@ -14,7 +14,7 @@ function Get-IcingaHelpThresholds() return; } - Write-Host + Write-IcingaConsolePlain ' Icinga is providing a basic handling for thresholds to make it easier to check if certain values of metrics should rise an event or not. By default, you are always fine to specify simple numeric values for thresholds throughout the entire Check-Plugins. diff --git a/lib/icinga/enums/Icinga_IcingaEnums.psm1 b/lib/icinga/enums/Icinga_IcingaEnums.psm1 index 0ffac3d..1b11ac1 100644 --- a/lib/icinga/enums/Icinga_IcingaEnums.psm1 +++ b/lib/icinga/enums/Icinga_IcingaEnums.psm1 @@ -18,6 +18,13 @@ 3 = '[UNKNOWN]'; }; +[hashtable]$IcingaExitCodeColor = @{ + 0 = 'Green'; + 1 = 'Yellow'; + 2 = 'Red'; + 3 = 'Magenta'; +}; + [hashtable]$IcingaMeasurementUnits = @{ 's' = 'seconds'; 'ms' = 'milliseconds'; @@ -41,6 +48,7 @@ [hashtable]$IcingaEnums = @{ IcingaExitCode = $IcingaExitCode; IcingaExitCodeText = $IcingaExitCodeText; + IcingaExitCodeColor = $IcingaExitCodeColor; IcingaMeasurementUnits = $IcingaMeasurementUnits; } diff --git a/lib/icinga/exception/Exit-IcingaThrowException.psm1 b/lib/icinga/exception/Exit-IcingaThrowException.psm1 index b7a1304..95a63df 100644 --- a/lib/icinga/exception/Exit-IcingaThrowException.psm1 +++ b/lib/icinga/exception/Exit-IcingaThrowException.psm1 @@ -71,7 +71,7 @@ function Exit-IcingaThrowException() ); if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) { - Write-Host $OutputMessage; + Write-IcingaConsolePlain $OutputMessage; exit $IcingaEnums.IcingaExitCode.Unknown; } } diff --git a/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 b/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 index c9a8746..ab593bc 100644 --- a/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 +++ b/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 @@ -5,7 +5,7 @@ function Write-IcingaPluginOutput() ); if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) { - Write-Host $Output; + Write-IcingaConsolePlain $Output; } else { if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) { $global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginCache'] += $Output; diff --git a/lib/icinga/plugin/Write-IcingaPluginPerfData.psm1 b/lib/icinga/plugin/Write-IcingaPluginPerfData.psm1 index be86233..ddb4a83 100644 --- a/lib/icinga/plugin/Write-IcingaPluginPerfData.psm1 +++ b/lib/icinga/plugin/Write-IcingaPluginPerfData.psm1 @@ -17,7 +17,7 @@ function Write-IcingaPluginPerfData() if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) { [string]$PerfDataOutput = (Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache); - Write-Host ([string]::Format('| {0}', $PerfDataOutput)); + Write-IcingaConsolePlain ([string]::Format('| {0}', $PerfDataOutput)); } else { [void](Get-IcingaPluginPerfDataContent -PerfData $PerformanceData -CheckResultCache $CheckResultCache -AsObject $TRUE); }