Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#207](https://github.com/Icinga/icinga-powershell-framework/pull/207) Adds new Argument `-LabelName` to `New-IcingaCheck`, allowing the developer to provide custom label names for checks and override the default based on the check name.
* [#210](https://github.com/Icinga/icinga-powershell-framework/pull/210) Updates the Icinga DSL for building PowerShell arrays to ensure all string values are properly escaped with `'`. In case the user already wrapped commands with `'` by himself, this will not have an effect as we only add single quotes for escaping if they are not present already
* [#211](https://github.com/Icinga/icinga-powershell-framework/pull/211) Adds feature to uninstall single components for Icinga for Windows or to uninstall everything and start entirely from new
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Added support to fetch network interface for `Register-IcingaDirectorSelfServiceHost` directly from provided director url
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Added support for Icinga Framework Code Cache file being deleted once the feature is disabled
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Added support to suppress any console output for the current PowerShell session by using `Disable-IcingaFrameworkConsoleOutput` and to enable it again by using `Enable-IcingaFrameworkConsoleOutput`
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Added support for `-Release` argument for `Get-IcingaFrameworkServiceBinary` suppressing questions and using GitHub as source directly if set
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Added support to color console output by using `Write-IcingaConsolePlain` with the new argument `-ForeColor`
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Added new feature to write Icinga for Windows console headers more easily, better structured and formatted with `Write-IcingaConsoleHeader` by adding line content as array elements
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Fixed possible crash on `Get-IcingaAgentFeatures` if PowerShell is not running as administrator and therefor the command `icinga2 feature list` can not be processed
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Fixed `ConvertTo-IcingaSecureString` to return `$null` for empty strings instead of throwing an exception

### Bugfixes

Expand All @@ -30,6 +38,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Experimental

* [#204](https://github.com/Icinga/icinga-powershell-framework/pull/204) Adds experimental feature to forward checks executed by the Icinga Agent to an internal REST-Api, to reduce the performance impact on systems with lower resources available
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Adds new experimental feature `Management Console` for better and easier management for Icinga for Windows and improved automation and deployed.

## 1.3.1 (2021-02-04)

Expand Down
10 changes: 7 additions & 3 deletions icinga-powershell-framework.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
GUID = 'fcd7a805-a41b-49f9-afee-9d17a2b76d42'
Author = 'Lord Hepipud'
CompanyName = 'Icinga GmbH'
Copyright = '(c) 2020 Icinga GmbH | MIT'
Copyright = '(c) 2021 Icinga GmbH | MIT'
Description = 'Icinga for Windows module which allows to entirely monitor the Windows Host system.'
PowerShellVersion = '4.0'
NestedModules = @(
Expand All @@ -27,7 +27,9 @@
'.\lib\web\Disable-IcingaProgressPreference.psm1',
'.\lib\core\tools\New-IcingaNewLine.psm1',
'.\lib\core\logging\Write-IcingaConsolePlain.psm1',
'.\lib\core\tools\Test-IcingaFunction.psm1'
'.\lib\core\tools\Test-IcingaFunction.psm1',
'.\lib\core\tools\Write-IcingaConsoleHeader.psm1',
'.\lib\core\framework\Test-IcingaFrameworkConsoleOutput.psm1'
)
FunctionsToExport = @(
'Use-Icinga',
Expand Down Expand Up @@ -63,7 +65,9 @@
'Disable-IcingaProgressPreference',
'New-IcingaNewLine',
'Write-IcingaConsolePlain',
'Test-IcingaFunction'
'Test-IcingaFunction',
'Write-IcingaConsoleHeader',
'Test-IcingaFrameworkConsoleOutput'
)
CmdletsToExport = @('*')
VariablesToExport = '*'
Expand Down
32 changes: 21 additions & 11 deletions icinga-powershell-framework.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -326,33 +326,38 @@ function Invoke-IcingaCommand()
[CmdletBinding()]
param (
$ScriptBlock,
[switch]$SkipHeader = $FALSE,
[switch]$SkipHeader = $FALSE,
[switch]$Manage = $FALSE,
[array]$ArgumentList = @()
);

Import-LocalizedData `
-BaseDirectory $PSScriptRoot `
-BaseDirectory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework') `
-FileName 'icinga-powershell-framework.psd1' `
-BindingVariable IcingaFrameworkData;

# Print a header informing our user that loaded the Icinga Framework with a specific
# version. We can also skip the header by using $SKipHeader
if ([string]::IsNullOrEmpty($ScriptBlock) -And $SkipHeader -eq $FALSE) {
Write-Output '******************************************************';
Write-Output ([string]::Format('** Icinga PowerShell Framework {0}', $IcingaFrameworkData.PrivateData.Version));
Write-Output ([string]::Format('** Copyright {0}', $IcingaFrameworkData.Copyright));
Write-Output ([string]::Format('** User environment {0}\{1}', $env:USERDOMAIN, $env:USERNAME));
if ([string]::IsNullOrEmpty($ScriptBlock) -And $SkipHeader -eq $FALSE -And $Manage -eq $FALSE) {
[array]$Headers = @(
'Icinga for Windows $FrameworkVersion',
'Copyright $Copyright',
'User environment $UserDomain\$Username'
);

if (Get-IcingaFrameworkCodeCache) {
Write-Output ([string]::Format('** Note: Icinga Framework Code Caching is enabled'));
$Headers += [string]::Format('Note: Icinga Framework Code Caching is enabled');
}
Write-Output '******************************************************';

Write-IcingaConsoleHeader -HeaderLines $Headers;
}

powershell.exe -NoExit -Command {
$Script = $args[0];
$RootPath = $args[1];
$Version = $args[2];
$IcingaShellArgs = $args[3];
$Manage = $args[3];
$IcingaShellArgs = $args[4];

# Load our Icinga Framework
Use-Icinga;
Expand All @@ -362,6 +367,11 @@ function Invoke-IcingaCommand()
# Set the location to the Icinga Framework module folder
Set-Location $RootPath;

if ($Manage) {
Install-Icinga;
exit $LASTEXITCODE;
}

# If we added a block to execute, do it right here and exit the shell
# with the last exit code of the command
if ([string]::IsNullOrEmpty($Script) -eq $FALSE) {
Expand All @@ -375,7 +385,7 @@ function Invoke-IcingaCommand()
return "> "
}

} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version, $ArgumentList;
} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version, ([bool]$Manage), $ArgumentList;
}

function Start-IcingaShellAsUser()
Expand Down
12 changes: 9 additions & 3 deletions lib/apis/Register-IcingaDirectorSelfServiceHost.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ function Register-IcingaDirectorSelfServiceHost()
$ProgressPreference = "SilentlyContinue";
$DirectorConfigJson = $null;

if ([string]::IsNullOrEmpty($Endpoint) -eq $FALSE) {
$Interface = Get-IcingaNetworkInterface $Endpoint;
$DirectorConfigJson = [string]::Format('{0} "address":"{2}" {1}', '{', '}', $Interface);
if ([string]::IsNullOrEmpty($Endpoint)) {
if ($DirectorUrl.Contains('https://') -Or $DirectorUrl.Contains('http://')) {
$Endpoint = $DirectorUrl.Split('/')[2];
} else {
$Endpoint = $DirectorUrl.Split('/')[0];
}
}

$Interface = Get-IcingaNetworkInterface $Endpoint;
$DirectorConfigJson = [string]::Format('{0} "address":"{2}" {1}', '{', '}', $Interface);

$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/register-host?name={0}&key={1}', $Hostname, $ApiKey));

$response = Invoke-IcingaWebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST' -Body $DirectorConfigJson;
Expand Down
5 changes: 5 additions & 0 deletions lib/core/framework/Disable-IcingaFrameworkCodeCache.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
function Disable-IcingaFrameworkCodeCache()
{
Set-IcingaPowerShellConfig -Path 'Framework.CodeCaching' -Value $FALSE;

# Remove the cache file in case it exists and the feature is disabled
if (Test-Path -Path (Get-IcingaFrameworkCodeCacheFile)) {
Remove-ItemSecure -Path (Get-IcingaFrameworkCodeCacheFile) -Force | Out-Null;
}
}
25 changes: 25 additions & 0 deletions lib/core/framework/Disable-IcingaFrameworkConsoleOutput.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<#
.SYNOPSIS
Allows to disable any console output for this PowerShell session
.DESCRIPTION
Allows to disable any console output for this PowerShell session
.FUNCTIONALITY
Allows to disable any console output for this PowerShell session
.EXAMPLE
PS>Disable-IcingaFrameworkConsoleOutput;
.LINK
https://github.com/Icinga/icinga-powershell-framework
#>

function Disable-IcingaFrameworkConsoleOutput()
{
if ($null -eq $global:Icinga) {
$global:Icinga = @{ };
}

if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) {
$global:Icinga.Add('DisableConsoleOutput', $TRUE);
} else {
$global:Icinga.DisableConsoleOutput = $TRUE;
}
}
25 changes: 25 additions & 0 deletions lib/core/framework/Enable-IcingaFrameworkConsoleOutput.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<#
.SYNOPSIS
Allows to enable any console output for this PowerShell session
.DESCRIPTION
Allows to enable any console output for this PowerShell session
.FUNCTIONALITY
Allows to enable any console output for this PowerShell session
.EXAMPLE
PS>Enable-IcingaFrameworkConsoleOutput;
.LINK
https://github.com/Icinga/icinga-powershell-framework
#>

function Enable-IcingaFrameworkConsoleOutput()
{
if ($null -eq $global:Icinga) {
$global:Icinga = @{ };
}

if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) {
$global:Icinga.Add('DisableConsoleOutput', $FALSE);
} else {
$global:Icinga.DisableConsoleOutput = $FALSE;
}
}
7 changes: 4 additions & 3 deletions lib/core/framework/Get-IcingaFrameworkServiceBinary.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ function Get-IcingaFrameworkServiceBinary()
{
param(
[string]$FrameworkServiceUrl,
[string]$ServiceDirectory
[string]$ServiceDirectory,
[switch]$Release = $FALSE
);

Set-IcingaTLSVersion;
$ProgressPreference = "SilentlyContinue";

if ([string]::IsNullOrEmpty($FrameworkServiceUrl)) {
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you provide a custom source of the service binary?' -Default 'n').result -eq 1) {
if ([string]::IsNullOrEmpty($FrameworkServiceUrl) -Or $Release) {
if ($Release -Or (Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you provide a custom source of the service binary?' -Default 'n').result -eq 1) {
$LatestRelease = (Invoke-IcingaWebRequest -Uri 'https://github.com/Icinga/icinga-powershell-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
$FrameworkServiceUrl = $LatestRelease.Replace('/tag/', '/download/');
$Tag = $FrameworkServiceUrl.Split('/')[-1];
Expand Down
25 changes: 25 additions & 0 deletions lib/core/framework/Test-IcingaFrameworkConsoleOutput.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<#
.SYNOPSIS
Allows to test if console output can be written or not for this PowerShell session
.DESCRIPTION
Allows to test if console output can be written or not for this PowerShell session
.FUNCTIONALITY
Allows to test if console output can be written or not for this PowerShell session
.EXAMPLE
PS>Enable-IcingaFrameworkConsoleOutput;
.LINK
https://github.com/Icinga/icinga-powershell-framework
#>

function Test-IcingaFrameworkConsoleOutput()
{
if ($null -eq $global:Icinga) {
return $TRUE;
}

if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) {
return $TRUE;
}

return (-Not ($global:Icinga.DisableConsoleOutput));
}
7 changes: 7 additions & 0 deletions lib/core/icingaagent/getters/Get-IcingaAgentFeatures.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ function Get-IcingaAgentFeatures()
$Binary = Get-IcingaAgentBinary;
$ConfigResult = Start-IcingaProcess -Executable $Binary -Arguments 'feature list';

if ($ConfigResult.ExitCode -ne 0) {
return @{
'Enabled' = @();
'Disabled' = @();
}
}

$DisabledFeatures = (
$ConfigResult.Message.SubString(
0,
Expand Down
Loading