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 { diff --git a/lib/core/framework/Show-IcingaTimer.psm1 b/lib/core/framework/Show-IcingaTimer.psm1 index e6fd310..ed0be28 100644 --- a/lib/core/framework/Show-IcingaTimer.psm1 +++ b/lib/core/framework/Show-IcingaTimer.psm1 @@ -25,15 +25,37 @@ function Show-IcingaTimer() { param ( - [string]$Name = 'DefaultTimer' + [string]$Name = 'DefaultTimer', + [switch]$ShowAll = $FALSE ); $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; + } - return $TimerObject.Elapsed.TotalSeconds; + $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; + } } 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; }