Skip to content
Merged
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
31 changes: 29 additions & 2 deletions plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down