Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/MonitoringTools/Public/Get-SystemHealth.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ function Get-SystemHealth {
Returns CPU usage, disk free space and recent event log summary.
The combined snapshot is also written to the structured log.
#>
[CmdletBinding(SupportsShouldProcess=$true)]
[CmdletBinding(SupportsShouldProcess=$true)]
param()

if (-not $PSCmdlet.ShouldProcess('system health')) { return }

$computer = if ($env:COMPUTERNAME) { $env:COMPUTERNAME } else { $env:HOSTNAME }
$timestamp = (Get-Date).ToString('o')

Expand Down
12 changes: 12 additions & 0 deletions tests/MonitoringTools/Get-SystemHealth.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,16 @@ Describe 'Get-SystemHealth function' {
$result.DiskInfo | Should -Be $disk
$result.EventLogSummary | Should -Be $events
}

Safe-It 'does not query health when -WhatIf specified' {
Mock Get-CPUUsage {} -ModuleName MonitoringTools
Mock Get-DiskSpaceInfo {} -ModuleName MonitoringTools
Mock Get-EventLogSummary {} -ModuleName MonitoringTools

Get-SystemHealth -WhatIf

Assert-MockCalled Get-CPUUsage -Times 0 -ModuleName MonitoringTools
Assert-MockCalled Get-DiskSpaceInfo -Times 0 -ModuleName MonitoringTools
Assert-MockCalled Get-EventLogSummary -Times 0 -ModuleName MonitoringTools
}
}
Loading