|
1 | 1 | function Show-IcingaRegisteredServiceChecks() |
2 | 2 | { |
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 | + ); |
4 | 8 |
|
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 += ''; |
10 | 38 | } |
| 39 | + |
| 40 | + Write-Output $ServiceSummary; |
11 | 41 | } |
0 commit comments