From 00be1105547816852ddaf434c3b7d32a4b02641f Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Wed, 5 Aug 2020 19:48:18 +0200 Subject: [PATCH 1/4] Adds `Namespace` argument for Get-IcingaWindowsInformation for additional filtering Fixes #94 --- doc/31-Changelog.md | 1 + lib/core/framework/Get-IcingaWindowsInformation.psm1 | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 3f26dc8..bb71316 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -21,6 +21,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#76](https://github.com/Icinga/icinga-powershell-framework/issues/76) Adds support to test for required .NET Framework Version 4.6.0 or above before trying to install the Icinga Agent * [#87](https://github.com/Icinga/icinga-powershell-framework/issues/87) Adds wrapper command to test new code or functionality of Framework and/or plugins * [#88](https://github.com/Icinga/icinga-powershell-framework/issues/88) Adds Start/Stop timer functionality for performance analysis +* [#94](https://github.com/Icinga/icinga-powershell-framework/issues/94) Adds `Namespace` argument for Get-IcingaWindowsInformation for additional filtering ### Bugfixes diff --git a/lib/core/framework/Get-IcingaWindowsInformation.psm1 b/lib/core/framework/Get-IcingaWindowsInformation.psm1 index 97c10e8..e223cbb 100644 --- a/lib/core/framework/Get-IcingaWindowsInformation.psm1 +++ b/lib/core/framework/Get-IcingaWindowsInformation.psm1 @@ -3,6 +3,7 @@ function Get-IcingaWindowsInformation() param ( [string]$ClassName, $Filter, + $Namespace, [switch]$ForceWMI = $FALSE ); @@ -15,6 +16,11 @@ function Get-IcingaWindowsInformation() 'Filter', $Filter ); } + if ([string]::IsNullOrEmpty($Namespace) -eq $FALSE) { + $Arguments.Add( + 'Namespace', $Namespace + ); + } if ($ForceWMI -eq $FALSE -And (Get-Command 'Get-CimInstance' -ErrorAction SilentlyContinue)) { try { From f3bebdbdbc3be0be1f2cb8ec39b402d7c0464258 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Thu, 6 Aug 2020 00:02:26 +0200 Subject: [PATCH 2/4] Fixes missing Name argument for Test-IcingaTimer --- lib/core/framework/Start-IcingaTimer.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/framework/Start-IcingaTimer.psm1 b/lib/core/framework/Start-IcingaTimer.psm1 index 8344712..9671b6a 100644 --- a/lib/core/framework/Start-IcingaTimer.psm1 +++ b/lib/core/framework/Start-IcingaTimer.psm1 @@ -26,7 +26,7 @@ function Start-IcingaTimer() [string]$Name = 'DefaultTimer' ); - if ((Test-IcingaTimer)) { + if ((Test-IcingaTimer -Name $Name)) { Write-IcingaConsoleNotice 'The timer with the name "{0}" is already active' -Objects $Name; return; } From dcafde1ea76b76fafbe237c9170d10aa68a2a8e5 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Thu, 6 Aug 2020 00:03:17 +0200 Subject: [PATCH 3/4] Adds support to show all timers with Show-IcingaTimers --- lib/core/framework/Show-IcingaTimer.psm1 | 26 ++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/core/framework/Show-IcingaTimer.psm1 b/lib/core/framework/Show-IcingaTimer.psm1 index e6fd310..7a5b430 100644 --- a/lib/core/framework/Show-IcingaTimer.psm1 +++ b/lib/core/framework/Show-IcingaTimer.psm1 @@ -25,7 +25,8 @@ function Show-IcingaTimer() { param ( - [string]$Name = 'DefaultTimer' + [string]$Name = 'DefaultTimer', + [switch]$ShowAll = $FALSE ); $TimerObject = Get-IcingaTimer -Name $Name; @@ -35,5 +36,26 @@ function Show-IcingaTimer() return; } - return $TimerObject.Elapsed.TotalSeconds; + if (-Not $ShowAll) { + $TimerOutput = New-Object -TypeName PSObject; + $TimerOutput | Add-Member -MemberType NoteProperty -Name 'Timer Name' -Value $Name; + $TimerOutput | Add-Member -MemberType NoteProperty -Name 'Elapsed Seconds' -Value $TimerObject.Elapsed.TotalSeconds; + + $TimerOutput | Format-Table -AutoSize; + } else { + $TimerObjects = Get-IcingaHashtableItem -Key 'IcingaTimers' -Hashtable $global:IcingaDaemonData; + + [array]$MultiOutput = @(); + + foreach ($TimerName in $TimerObjects.Keys) { + $TimerObject = $TimerObjects[$TimerName].Timer; + + $TimerOutput = New-Object -TypeName PSObject; + $TimerOutput | Add-Member -MemberType NoteProperty -Name 'Timer Name' -Value $TimerName; + $TimerOutput | Add-Member -MemberType NoteProperty -Name 'Elapsed Seconds' -Value $TimerObject.Elapsed.TotalSeconds; + $MultiOutput += $TimerOutput; + } + + $MultiOutput | Format-Table -AutoSize; + } } From 4898009e8675190f4f04ddd6df1dd83a0b99b436 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Thu, 6 Aug 2020 00:17:17 +0200 Subject: [PATCH 4/4] Fixes issue on show timer while no default timer was started on ShowAll --- lib/core/framework/Show-IcingaTimer.psm1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/core/framework/Show-IcingaTimer.psm1 b/lib/core/framework/Show-IcingaTimer.psm1 index 7a5b430..ed0be28 100644 --- a/lib/core/framework/Show-IcingaTimer.psm1 +++ b/lib/core/framework/Show-IcingaTimer.psm1 @@ -31,12 +31,12 @@ function Show-IcingaTimer() $TimerObject = Get-IcingaTimer -Name $Name; - if ($null -eq $TimerObject) { - Write-IcingaConsoleNotice 'A timer with the name "{0}" does not exist' -Objects $Name; - return; - } - if (-Not $ShowAll) { + if ($null -eq $TimerObject) { + Write-IcingaConsoleNotice 'A timer with the name "{0}" does not exist' -Objects $Name; + return; + } + $TimerOutput = New-Object -TypeName PSObject; $TimerOutput | Add-Member -MemberType NoteProperty -Name 'Timer Name' -Value $Name; $TimerOutput | Add-Member -MemberType NoteProperty -Name 'Elapsed Seconds' -Value $TimerObject.Elapsed.TotalSeconds;