Skip to content

Commit b9eb54d

Browse files
authored
Merge pull request #213 from Icinga:feature/icinga_for_windows_management_console
Feature: Adds experimental Feature "Management Console" Adds new experimental feature `Management Console` for better and easier management for Icinga for Windows and improved automation and deployed. In addition following changes were made: * Added support to fetch network interface for `Register-IcingaDirectorSelfServiceHost` directly from provided director url * Added support for Icinga Framework Code Cache file being deleted once the feature is disabled * 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` * Added support for `-Release` argument for `Get-IcingaFrameworkServiceBinary` suppressing questions and using GitHub as source directly if set * Added support to color console output by using `Write-IcingaConsolePlain` with the new argument `-ForeColor` * 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 * Fixed possible crash on `Get-IcingaAgentFeatures` if PowerShell is not running as administrator and therefor the command `icinga2 feature list` can not be processed * Fixed `ConvertTo-IcingaSecureString` to return `$null` for empty strings instead of throwing an exception
2 parents 6cbd3ce + c4f6fcc commit b9eb54d

File tree

103 files changed

+3844
-26
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+3844
-26
lines changed

doc/31-Changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2121
* [#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.
2222
* [#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
2323
* [#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
24+
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Added support to fetch network interface for `Register-IcingaDirectorSelfServiceHost` directly from provided director url
25+
* [#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
26+
* [#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`
27+
* [#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
28+
* [#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`
29+
* [#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
30+
* [#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
31+
* [#213](https://github.com/Icinga/icinga-powershell-framework/pull/213) Fixed `ConvertTo-IcingaSecureString` to return `$null` for empty strings instead of throwing an exception
2432

2533
### Bugfixes
2634

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

3240
* [#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
41+
* [#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.
3342

3443
## 1.3.1 (2021-02-04)
3544

icinga-powershell-framework.psd1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
GUID = 'fcd7a805-a41b-49f9-afee-9d17a2b76d42'
55
Author = 'Lord Hepipud'
66
CompanyName = 'Icinga GmbH'
7-
Copyright = '(c) 2020 Icinga GmbH | MIT'
7+
Copyright = '(c) 2021 Icinga GmbH | MIT'
88
Description = 'Icinga for Windows module which allows to entirely monitor the Windows Host system.'
99
PowerShellVersion = '4.0'
1010
NestedModules = @(
@@ -27,7 +27,9 @@
2727
'.\lib\web\Disable-IcingaProgressPreference.psm1',
2828
'.\lib\core\tools\New-IcingaNewLine.psm1',
2929
'.\lib\core\logging\Write-IcingaConsolePlain.psm1',
30-
'.\lib\core\tools\Test-IcingaFunction.psm1'
30+
'.\lib\core\tools\Test-IcingaFunction.psm1',
31+
'.\lib\core\tools\Write-IcingaConsoleHeader.psm1',
32+
'.\lib\core\framework\Test-IcingaFrameworkConsoleOutput.psm1'
3133
)
3234
FunctionsToExport = @(
3335
'Use-Icinga',
@@ -63,7 +65,9 @@
6365
'Disable-IcingaProgressPreference',
6466
'New-IcingaNewLine',
6567
'Write-IcingaConsolePlain',
66-
'Test-IcingaFunction'
68+
'Test-IcingaFunction',
69+
'Write-IcingaConsoleHeader',
70+
'Test-IcingaFrameworkConsoleOutput'
6771
)
6872
CmdletsToExport = @('*')
6973
VariablesToExport = '*'

icinga-powershell-framework.psm1

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,33 +326,38 @@ function Invoke-IcingaCommand()
326326
[CmdletBinding()]
327327
param (
328328
$ScriptBlock,
329-
[switch]$SkipHeader = $FALSE,
329+
[switch]$SkipHeader = $FALSE,
330+
[switch]$Manage = $FALSE,
330331
[array]$ArgumentList = @()
331332
);
332333

333334
Import-LocalizedData `
334-
-BaseDirectory $PSScriptRoot `
335+
-BaseDirectory (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework') `
335336
-FileName 'icinga-powershell-framework.psd1' `
336337
-BindingVariable IcingaFrameworkData;
337338

338339
# Print a header informing our user that loaded the Icinga Framework with a specific
339340
# version. We can also skip the header by using $SKipHeader
340-
if ([string]::IsNullOrEmpty($ScriptBlock) -And $SkipHeader -eq $FALSE) {
341-
Write-Output '******************************************************';
342-
Write-Output ([string]::Format('** Icinga PowerShell Framework {0}', $IcingaFrameworkData.PrivateData.Version));
343-
Write-Output ([string]::Format('** Copyright {0}', $IcingaFrameworkData.Copyright));
344-
Write-Output ([string]::Format('** User environment {0}\{1}', $env:USERDOMAIN, $env:USERNAME));
341+
if ([string]::IsNullOrEmpty($ScriptBlock) -And $SkipHeader -eq $FALSE -And $Manage -eq $FALSE) {
342+
[array]$Headers = @(
343+
'Icinga for Windows $FrameworkVersion',
344+
'Copyright $Copyright',
345+
'User environment $UserDomain\$Username'
346+
);
347+
345348
if (Get-IcingaFrameworkCodeCache) {
346-
Write-Output ([string]::Format('** Note: Icinga Framework Code Caching is enabled'));
349+
$Headers += [string]::Format('Note: Icinga Framework Code Caching is enabled');
347350
}
348-
Write-Output '******************************************************';
351+
352+
Write-IcingaConsoleHeader -HeaderLines $Headers;
349353
}
350354

351355
powershell.exe -NoExit -Command {
352356
$Script = $args[0];
353357
$RootPath = $args[1];
354358
$Version = $args[2];
355-
$IcingaShellArgs = $args[3];
359+
$Manage = $args[3];
360+
$IcingaShellArgs = $args[4];
356361

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

370+
if ($Manage) {
371+
Install-Icinga;
372+
exit $LASTEXITCODE;
373+
}
374+
365375
# If we added a block to execute, do it right here and exit the shell
366376
# with the last exit code of the command
367377
if ([string]::IsNullOrEmpty($Script) -eq $FALSE) {
@@ -375,7 +385,7 @@ function Invoke-IcingaCommand()
375385
return "> "
376386
}
377387

378-
} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version, $ArgumentList;
388+
} -Args $ScriptBlock, $PSScriptRoot, $IcingaFrameworkData.PrivateData.Version, ([bool]$Manage), $ArgumentList;
379389
}
380390

381391
function Start-IcingaShellAsUser()

lib/apis/Register-IcingaDirectorSelfServiceHost.psm1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ function Register-IcingaDirectorSelfServiceHost()
5353
$ProgressPreference = "SilentlyContinue";
5454
$DirectorConfigJson = $null;
5555

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

64+
$Interface = Get-IcingaNetworkInterface $Endpoint;
65+
$DirectorConfigJson = [string]::Format('{0} "address":"{2}" {1}', '{', '}', $Interface);
66+
6167
$EndpointUrl = Join-WebPath -Path $DirectorUrl -ChildPath ([string]::Format('/self-service/register-host?name={0}&key={1}', $Hostname, $ApiKey));
6268

6369
$response = Invoke-IcingaWebRequest -Uri $EndpointUrl -UseBasicParsing -Headers @{ 'accept' = 'application/json'; 'X-Director-Accept' = 'application/json' } -Method 'POST' -Body $DirectorConfigJson;

lib/core/framework/Disable-IcingaFrameworkCodeCache.psm1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
function Disable-IcingaFrameworkCodeCache()
1717
{
1818
Set-IcingaPowerShellConfig -Path 'Framework.CodeCaching' -Value $FALSE;
19+
20+
# Remove the cache file in case it exists and the feature is disabled
21+
if (Test-Path -Path (Get-IcingaFrameworkCodeCacheFile)) {
22+
Remove-ItemSecure -Path (Get-IcingaFrameworkCodeCacheFile) -Force | Out-Null;
23+
}
1924
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<#
2+
.SYNOPSIS
3+
Allows to disable any console output for this PowerShell session
4+
.DESCRIPTION
5+
Allows to disable any console output for this PowerShell session
6+
.FUNCTIONALITY
7+
Allows to disable any console output for this PowerShell session
8+
.EXAMPLE
9+
PS>Disable-IcingaFrameworkConsoleOutput;
10+
.LINK
11+
https://github.com/Icinga/icinga-powershell-framework
12+
#>
13+
14+
function Disable-IcingaFrameworkConsoleOutput()
15+
{
16+
if ($null -eq $global:Icinga) {
17+
$global:Icinga = @{ };
18+
}
19+
20+
if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) {
21+
$global:Icinga.Add('DisableConsoleOutput', $TRUE);
22+
} else {
23+
$global:Icinga.DisableConsoleOutput = $TRUE;
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<#
2+
.SYNOPSIS
3+
Allows to enable any console output for this PowerShell session
4+
.DESCRIPTION
5+
Allows to enable any console output for this PowerShell session
6+
.FUNCTIONALITY
7+
Allows to enable any console output for this PowerShell session
8+
.EXAMPLE
9+
PS>Enable-IcingaFrameworkConsoleOutput;
10+
.LINK
11+
https://github.com/Icinga/icinga-powershell-framework
12+
#>
13+
14+
function Enable-IcingaFrameworkConsoleOutput()
15+
{
16+
if ($null -eq $global:Icinga) {
17+
$global:Icinga = @{ };
18+
}
19+
20+
if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) {
21+
$global:Icinga.Add('DisableConsoleOutput', $FALSE);
22+
} else {
23+
$global:Icinga.DisableConsoleOutput = $FALSE;
24+
}
25+
}

lib/core/framework/Get-IcingaFrameworkServiceBinary.psm1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ function Get-IcingaFrameworkServiceBinary()
2828
{
2929
param(
3030
[string]$FrameworkServiceUrl,
31-
[string]$ServiceDirectory
31+
[string]$ServiceDirectory,
32+
[switch]$Release = $FALSE
3233
);
3334

3435
Set-IcingaTLSVersion;
3536
$ProgressPreference = "SilentlyContinue";
3637

37-
if ([string]::IsNullOrEmpty($FrameworkServiceUrl)) {
38-
if ((Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you provide a custom source of the service binary?' -Default 'n').result -eq 1) {
38+
if ([string]::IsNullOrEmpty($FrameworkServiceUrl) -Or $Release) {
39+
if ($Release -Or (Get-IcingaAgentInstallerAnswerInput -Prompt 'Do you provide a custom source of the service binary?' -Default 'n').result -eq 1) {
3940
$LatestRelease = (Invoke-IcingaWebRequest -Uri 'https://github.com/Icinga/icinga-powershell-service/releases/latest' -UseBasicParsing).BaseResponse.ResponseUri.AbsoluteUri;
4041
$FrameworkServiceUrl = $LatestRelease.Replace('/tag/', '/download/');
4142
$Tag = $FrameworkServiceUrl.Split('/')[-1];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<#
2+
.SYNOPSIS
3+
Allows to test if console output can be written or not for this PowerShell session
4+
.DESCRIPTION
5+
Allows to test if console output can be written or not for this PowerShell session
6+
.FUNCTIONALITY
7+
Allows to test if console output can be written or not for this PowerShell session
8+
.EXAMPLE
9+
PS>Enable-IcingaFrameworkConsoleOutput;
10+
.LINK
11+
https://github.com/Icinga/icinga-powershell-framework
12+
#>
13+
14+
function Test-IcingaFrameworkConsoleOutput()
15+
{
16+
if ($null -eq $global:Icinga) {
17+
return $TRUE;
18+
}
19+
20+
if ($global:Icinga.ContainsKey('DisableConsoleOutput') -eq $FALSE) {
21+
return $TRUE;
22+
}
23+
24+
return (-Not ($global:Icinga.DisableConsoleOutput));
25+
}

lib/core/icingaagent/getters/Get-IcingaAgentFeatures.psm1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ function Get-IcingaAgentFeatures()
33
$Binary = Get-IcingaAgentBinary;
44
$ConfigResult = Start-IcingaProcess -Executable $Binary -Arguments 'feature list';
55

6+
if ($ConfigResult.ExitCode -ne 0) {
7+
return @{
8+
'Enabled' = @();
9+
'Disabled' = @();
10+
}
11+
}
12+
613
$DisabledFeatures = (
714
$ConfigResult.Message.SubString(
815
0,

0 commit comments

Comments
 (0)