diff --git a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 index b8332713..3175341f 100644 --- a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 +++ b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 @@ -51,8 +51,9 @@ function Invoke-IcingaCheckUsedPartitionSpace() [int]$Verbosity = 0 ); - $DiskFree = Get-IcingaDiskPartitions; - $DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -OperatorAnd -Verbos $Verbosity; + $DiskFree = Get-IcingaDiskPartitions; + $DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -OperatorAnd -Verbose $Verbosity; + $DiskBytePackage = New-IcingaCheckPackage -Name 'Used Partition Space in Bytes' -Verbose $Verbosity -Hidden; foreach ($Letter in $DiskFree.Keys) { if ($Include.Count -ne 0) { @@ -69,9 +70,35 @@ function Invoke-IcingaCheckUsedPartitionSpace() } } + $Unit = Get-UnitPrefixIEC $DiskFree.([string]::Format($Letter))."Size"; + $PerfUnit = Get-UnitPrefixSI $DiskFree.([string]::Format($Letter))."Size"; + $Bytes = [math]::Round(($DiskFree.([string]::Format($Letter))."Size") * (100-($DiskFree.([string]::Format($Letter))."Free Space")) / 100); + $ByteString = [string]::Format('{0}B', $Bytes); + $ByteValueConverted = Convert-Bytes -Value $ByteString -Unit $Unit; + $DiskSizeBytes = $DiskFree[$Letter]['Size']; + if ($null -eq $DiskSizeBytes) { + $DiskSizeBytes = 0; + } + $DiskSize = Convert-Bytes -Value ([string]::Format('{0}B', $DiskSizeBytes)) -Unit $Unit; + $DiskTotalWarning = $null; + $DiskTotalCritical = $null; + + if ($null -ne $Warning -And $DiskSize.Value -ne 0) { + $DiskTotalWarning = $DiskSize.Value / 100 * $Warning; + } + if ($null -ne $Critical -And $DiskSize.Value -ne 0) { + $DiskTotalCritical = $DiskSize.Value / 100 * $Critical; + } + + $IcingaCheckByte = New-IcingaCheck -Name ([string]::Format( 'Used Space Partition {0}', $Letter )) -Value $ByteValueConverted.Value -Unit $PerfUnit -Minimum 0 -Maximum $DiskSize.Value; + $IcingaCheckByte.WarnOutOfRange($DiskTotalWarning).CritOutOfRange($DiskTotalCritical) | Out-Null; + $DiskBytePackage.AddCheck($IcingaCheckByte); + $IcingaCheck = New-IcingaCheck -Name ([string]::Format('Partition {0}', $Letter)) -Value (100-($DiskFree.([string]::Format($Letter))."Free Space")) -Unit '%'; $IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null; $DiskPackage.AddCheck($IcingaCheck); + + $DiskPackage.AddCheck($DiskBytePackage); } return (New-IcingaCheckResult -Check $DiskPackage -NoPerfData $NoPerfData -Compile);