Skip to content

Commit 9bcd221

Browse files
authored
Merge pull request #450 from Icinga:feature/improve_show_commands
Feature: Improve show commands and extend Show-Icinga Improves show command `Show-IcingaRegisteredServiceChecks` to use new layout for displaying information and adds new command `Show-IcingaRegisteredBackgroundDaemons`, following the same layout and possiblity. In addition extends `Show-Icinga` by both commands and adds debug and api forwarder features to environment list.
2 parents 7299517 + 586b55a commit 9bcd221

File tree

10 files changed

+156
-47
lines changed

10 files changed

+156
-47
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
4242
* [#440](https://github.com/Icinga/icinga-powershell-framework/pull/440) Adds upgrade notification if Icinga for Windows Service binary older than v1.2.0 is used, which will not work with Icinga for Windows v1.8.0 or later
4343
* [#445](https://github.com/Icinga/icinga-powershell-framework/pull/445) Adds command `Repair-IcingaService` to repair Icinga Agent service in case it was broken during upgrades, mostly caused by `The specified service has been marked for deletion`
4444
* [#448](https://github.com/Icinga/icinga-powershell-framework/pull/448) Adds support to sort arrays without ScriptBlocks
45+
* [#450](https://github.com/Icinga/icinga-powershell-framework/pull/450) Improves show command `Show-IcingaRegisteredServiceChecks`, adds new command `Show-IcingaRegisteredBackgroundDaemons` and extends `Show-Icinga` by both commands and adds debug and api forwarder features to environment list
4546

4647
## 1.7.1 (2021-11-11)
4748

doc/110-Installation/05-Background-Daemons.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@ Register-IcingaBackgroundDaemon `
6262
To print a list of configured background daemons, you can run
6363

6464
```powershell
65-
Get-IcingaBackgroundDaemons;
65+
Show-IcingaRegisteredBackgroundDaemons;
66+
```
67+
68+
```powershell
69+
List of configured background daemons on this system.
70+
71+
Start-IcingaServiceCheckDaemon
72+
-----------
73+
No arguments defined
6674
```
6775

6876
## Restart PowerShell Service

doc/110-Installation/06-Collect-Metrics-over-Time.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,24 @@ Register-IcingaServiceCheck `
8585

8686
### Show Registered Service Checks
8787

88-
To fetch a list of currently registerd service checks, you can run the following command:
88+
To fetch a list of currently registered service checks, you can run the following command:
8989

9090
```powershell
9191
Show-IcingaRegisteredServiceChecks;
9292
```
9393

9494
```powershell
95-
[Notice]: Service Id: 1332191811682909517982372151451071972043015735175
96-
[Notice]:
97-
Name Value
98-
---- -----
99-
CheckCommand Invoke-IcingaCheckPerfCounter
100-
Interval 15
101-
Arguments @{-PerfCounter=System.Object[]}
102-
Id 1332191811682909517982372151451071972043015735175
103-
TimeIndexes {1, 3, 5, 10...}
95+
List of configured background service checks on this system.
96+
=> https://icinga.com/docs/icinga-for-windows/latest/doc/110-Installation/06-Collect-Metrics-over-Time/
97+
98+
Invoke-IcingaCheckPerfCounter
99+
-----------
100+
Arguments => -PerfCounter '\Processor(*)\% Processor Time', '\Memory\% committed bytes in use', '\Memory\Available Bytes'
101+
CheckCommand => Invoke-IcingaCheckPerfCounter
102+
Id => 1332191811682909517982372151451071972043015735175
103+
Interval => 15
104+
TimeIndexes => 1, 3, 5, 10, 15, 20
105+
104106
```
105107

106108
You will then receive a list of all configured plugins, including their configuration and `service id`.

lib/core/installer/tools/Write-IcingaManagementConsoleCommand.psm1

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,9 @@ function Write-IcingaManagementConsoleCommand()
2525
}
2626
}
2727

28-
foreach ($cmdArg in $DefinedArgs.Keys) {
29-
$PrintValue = $DefinedArgs[$cmdArg];
30-
[string]$StringArg = ([string]$cmdArg).Replace('-', '');
31-
if ($PrintValue.GetType().Name -eq 'Boolean') {
32-
if ((Get-Command $PrintCommand).Parameters.$StringArg.ParameterType.Name -eq 'SwitchParameter') {
33-
$PrintValue = '';
34-
} else {
35-
if ($PrintValue) {
36-
$PrintValue = '$TRUE';
37-
} else {
38-
$PrintValue = '$FALSE';
39-
}
40-
}
41-
} elseif ($PrintValue.GetType().Name -eq 'String') {
42-
$PrintValue = (ConvertFrom-IcingaArrayToString -Array $PrintValue -AddQuotes -UseSingleQuotes);
43-
}
44-
if ([string]::IsNullOrEmpty($PrintValue)) {
45-
$PrintArguments += ([string]::Format('{0} ', $cmdArg));
46-
} else {
47-
$PrintArguments += ([string]::Format('{0} {1} ', $cmdArg, $PrintValue));
48-
}
49-
}
50-
28+
$PrintArguments = ConvertTo-IcingaCommandArgumentString -Command $PrintCommand -CommandArguments $DefinedArgs;
5129
$PrintArguments = $PrintArguments.Replace('$DefaultValues$', ((ConvertFrom-IcingaArrayToString -Array $Values -AddQuotes)));
5230

53-
while ($PrintArguments[-1] -eq ' ') {
54-
$PrintArguments = $PrintArguments.SubString(0, $PrintArguments.Length - 1);
55-
}
56-
5731
if ([string]::IsNullOrEmpty($PrintArguments) -eq $FALSE) {
5832
$PrintArguments = [string]::Format(' {0}', $PrintArguments);
5933
}

lib/core/repository/Show-Icinga.psm1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,16 @@ function Show-Icinga()
9191
$Output += ([string]::Format('Operating System Version => {0}', $WindowsInformation.Version));
9292
$Output += ([string]::Format('JEA Context => {0}', $JEAContext));
9393
$Output += ([string]::Format('JEA Session File => {0}', $JEASessionFile));
94+
$Output += ([string]::Format('Api Check Forwarder => {0}', (Get-IcingaFrameworkApiChecks)));
95+
$Output += ([string]::Format('Debug Mode => {0}', (Get-IcingaFrameworkDebugMode)));
9496
$Output += '';
9597
$Output += 'Icinga for Windows Certificate';
9698
$Output += '';
9799
$Output += $IcingaForWindowsCert;
98-
99100
$Output += '';
101+
102+
$Output += (Show-IcingaRegisteredBackgroundDaemons);
103+
$Output += (Show-IcingaRegisteredServiceChecks);
100104
$Output += (Show-IcingaRepository);
101105

102106
Write-Output $Output;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function ConvertTo-IcingaCommandArgumentString()
2+
{
3+
param (
4+
[string]$Command = '',
5+
$CommandArguments = $null
6+
);
7+
8+
[hashtable]$Arguments = @{ };
9+
10+
if ($CommandArguments -Is [PSCustomObject]) {
11+
foreach ($entry in $CommandArguments.PSObject.Properties) {
12+
$Arguments.Add($entry.Name, $entry.Value);
13+
}
14+
} elseif ($CommandArguments -Is [hashtable]) {
15+
$Arguments = $CommandArguments;
16+
} else {
17+
return '';
18+
}
19+
20+
foreach ($cmdArg in $Arguments.Keys) {
21+
$PrintValue = $Arguments[$cmdArg];
22+
[string]$StringArg = ([string]$cmdArg).Replace('-', '');
23+
24+
if ($PrintValue.GetType().Name -eq 'Boolean') {
25+
if ((Get-Command $Command).Parameters.$StringArg.ParameterType.Name -eq 'SwitchParameter') {
26+
$PrintValue = '';
27+
} else {
28+
if ($PrintValue) {
29+
$PrintValue = '$TRUE';
30+
} else {
31+
$PrintValue = '$FALSE';
32+
}
33+
}
34+
} elseif ($PrintValue.GetType().Name -eq 'String') {
35+
$PrintValue = (ConvertFrom-IcingaArrayToString -Array $PrintValue -AddQuotes -UseSingleQuotes);
36+
} elseif ($PrintValue.GetType().Name -eq 'Object[]') {
37+
$PrintValue = (ConvertFrom-IcingaArrayToString -Array $PrintValue -AddQuotes -UseSingleQuotes);
38+
}
39+
if ([string]::IsNullOrEmpty($PrintValue)) {
40+
$PrintArguments += ([string]::Format('{0} ', $cmdArg));
41+
} else {
42+
$PrintArguments += ([string]::Format('{0} {1} ', $cmdArg, $PrintValue));
43+
}
44+
}
45+
46+
while ($PrintArguments[-1] -eq ' ') {
47+
$PrintArguments = $PrintArguments.SubString(0, $PrintArguments.Length - 1);
48+
}
49+
50+
return $PrintArguments;
51+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Show-IcingaRegisteredBackgroundDaemons()
2+
{
3+
[array]$DaemonSummary = @(
4+
'List of configured background daemons on this system.',
5+
''
6+
);
7+
8+
[hashtable]$DaemonList = Get-IcingaBackgroundDaemons;
9+
10+
foreach ($daemon in $DaemonList.Keys) {
11+
12+
$DaemonSummary += $daemon;
13+
$DaemonSummary += '-----------';
14+
$DaemonConfig = $DaemonList[$daemon];
15+
16+
[int]$MaxLength = (Get-IcingaMaxTextLength -TextArray $DaemonConfig.Keys) - 1;
17+
[array]$DaemonData = @();
18+
19+
foreach ($daemonArgument in $DaemonConfig.Keys) {
20+
$daemonValue = $DaemonConfig[$daemonArgument];
21+
$PrintName = Add-IcingaWhiteSpaceToString -Text $daemonArgument -Length $MaxLength;
22+
$DaemonData += [string]::Format('{0} => {1}', $PrintName, $daemonValue);
23+
}
24+
25+
if ($DaemonConfig.Count -eq 0) {
26+
$DaemonSummary += 'No arguments defined';
27+
}
28+
29+
$DaemonSummary += $DaemonData | Sort-Object;
30+
$DaemonSummary += '';
31+
}
32+
33+
if ($DaemonList.Count -eq 0) {
34+
$DaemonSummary += 'No background daemons configured';
35+
$DaemonSummary += '';
36+
}
37+
38+
Write-Output $DaemonSummary;
39+
}

lib/daemons/ServiceCheckDaemon/tools/Register-IcingaServiceCheck.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ function Register-IcingaServiceCheck()
1919
Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.Interval', $Path)) -Value $Interval;
2020
Set-IcingaPowerShellConfig -Path ([string]::Format('{0}.TimeIndexes', $Path)) -Value $TimeIndexes;
2121

22-
Write-IcingaConsoleNotice 'Icinga Service Check has been configured';
22+
Write-IcingaConsoleNotice 'Icinga background service check has been added';
2323
}
Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
function Show-IcingaRegisteredServiceChecks()
22
{
3-
$Services = Get-IcingaRegisteredServiceChecks;
3+
[array]$ServiceSummary = @(
4+
'List of configured background service checks on this system.',
5+
'=> https://icinga.com/docs/icinga-for-windows/latest/doc/110-Installation/06-Collect-Metrics-over-Time/',
6+
''
7+
);
48

5-
foreach ($service in $Services.Keys) {
6-
Write-IcingaConsoleNotice ([string]::Format('Service Id: {0}', $service));
7-
Write-IcingaConsoleNotice (
8-
$Services[$service] | Out-String
9-
);
9+
[hashtable]$ServiceList = Get-IcingaRegisteredServiceChecks;
10+
11+
foreach ($serviceId in $ServiceList.Keys) {
12+
$serviceDetails = $ServiceList[$serviceId];
13+
14+
$ServiceSummary += $serviceDetails.CheckCommand;
15+
$ServiceSummary += '-----------';
16+
17+
[int]$MaxLength = (Get-IcingaMaxTextLength -TextArray $serviceDetails.Keys) - 1;
18+
[array]$ServiceData = @();
19+
20+
foreach ($serviceArguments in $serviceDetails.Keys) {
21+
$serviceValue = $serviceDetails[$serviceArguments];
22+
$PrintName = Add-IcingaWhiteSpaceToString -Text $serviceArguments -Length $MaxLength;
23+
if ($serviceValue -Is [array]) {
24+
$serviceValue = [string]::Join(', ', $serviceValue);
25+
} elseif ($serviceValue -Is [PSCustomObject]) {
26+
$serviceValue = ConvertTo-IcingaCommandArgumentString -Command $serviceDetails.CheckCommand -CommandArguments $serviceValue;
27+
}
28+
$ServiceData += [string]::Format('{0} => {1}', $PrintName, $serviceValue);
29+
}
30+
31+
$ServiceSummary += $ServiceData | Sort-Object;
32+
$ServiceSummary += '';
33+
}
34+
35+
if ($ServiceList.Count -eq 0) {
36+
$ServiceSummary += 'No background service checks configured';
37+
$ServiceSummary += '';
1038
}
39+
40+
Write-Output $ServiceSummary;
1141
}

lib/daemons/ServiceCheckDaemon/tools/Unregister-IcingaServiceCheck.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ function Unregister-IcingaServiceCheck()
1212

1313
Remove-IcingaPowerShellConfig -Path $Path;
1414

15-
Write-IcingaConsolePlain 'Icinga Service Check has been configured';
15+
Write-IcingaConsoleNotice 'Icinga background service check has been removed';
1616
}

0 commit comments

Comments
 (0)