Skip to content

Commit 026de51

Browse files
authored
Merge pull request #10 from Icinga/enhancement/values_UsedPartitionSpace
Add Output usage for UsedPartition
2 parents f8aab34 + 60b433d commit 026de51

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ function Invoke-IcingaCheckUsedPartitionSpace()
5151
[int]$Verbosity = 0
5252
);
5353

54-
$DiskFree = Get-IcingaDiskPartitions;
55-
$DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -OperatorAnd -Verbos $Verbosity;
54+
$DiskFree = Get-IcingaDiskPartitions;
55+
$DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -OperatorAnd -Verbose $Verbosity;
56+
$DiskBytePackage = New-IcingaCheckPackage -Name 'Used Partition Space in Bytes' -Verbose $Verbosity -Hidden;
5657

5758
foreach ($Letter in $DiskFree.Keys) {
5859
if ($Include.Count -ne 0) {
@@ -69,9 +70,35 @@ function Invoke-IcingaCheckUsedPartitionSpace()
6970
}
7071
}
7172

73+
$Unit = Get-UnitPrefixIEC $DiskFree.([string]::Format($Letter))."Size";
74+
$PerfUnit = Get-UnitPrefixSI $DiskFree.([string]::Format($Letter))."Size";
75+
$Bytes = [math]::Round(($DiskFree.([string]::Format($Letter))."Size") * (100-($DiskFree.([string]::Format($Letter))."Free Space")) / 100);
76+
$ByteString = [string]::Format('{0}B', $Bytes);
77+
$ByteValueConverted = Convert-Bytes -Value $ByteString -Unit $Unit;
78+
$DiskSizeBytes = $DiskFree[$Letter]['Size'];
79+
if ($null -eq $DiskSizeBytes) {
80+
$DiskSizeBytes = 0;
81+
}
82+
$DiskSize = Convert-Bytes -Value ([string]::Format('{0}B', $DiskSizeBytes)) -Unit $Unit;
83+
$DiskTotalWarning = $null;
84+
$DiskTotalCritical = $null;
85+
86+
if ($null -ne $Warning -And $DiskSize.Value -ne 0) {
87+
$DiskTotalWarning = $DiskSize.Value / 100 * $Warning;
88+
}
89+
if ($null -ne $Critical -And $DiskSize.Value -ne 0) {
90+
$DiskTotalCritical = $DiskSize.Value / 100 * $Critical;
91+
}
92+
93+
$IcingaCheckByte = New-IcingaCheck -Name ([string]::Format( 'Used Space Partition {0}', $Letter )) -Value $ByteValueConverted.Value -Unit $PerfUnit -Minimum 0 -Maximum $DiskSize.Value;
94+
$IcingaCheckByte.WarnOutOfRange($DiskTotalWarning).CritOutOfRange($DiskTotalCritical) | Out-Null;
95+
$DiskBytePackage.AddCheck($IcingaCheckByte);
96+
7297
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Partition {0}', $Letter)) -Value (100-($DiskFree.([string]::Format($Letter))."Free Space")) -Unit '%';
7398
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
7499
$DiskPackage.AddCheck($IcingaCheck);
100+
101+
$DiskPackage.AddCheck($DiskBytePackage);
75102
}
76103

77104
return (New-IcingaCheckResult -Check $DiskPackage -NoPerfData $NoPerfData -Compile);

0 commit comments

Comments
 (0)