From 0ba6f46c8e019ad17ec7272ea555317a56d128c2 Mon Sep 17 00:00:00 2001 From: Crited <45196568+Crited@users.noreply.github.com> Date: Fri, 7 Feb 2020 15:17:05 +0100 Subject: [PATCH 1/4] Add Output usage for UsedPartition #5 Adds according hidden output for the check, that uses the highest possible prefix. --- plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 index b8332713..cf3a5184 100644 --- a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 +++ b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 @@ -53,6 +53,8 @@ function Invoke-IcingaCheckUsedPartitionSpace() $DiskFree = Get-IcingaDiskPartitions; $DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -OperatorAnd -Verbos $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 +71,19 @@ function Invoke-IcingaCheckUsedPartitionSpace() } } + $Unit = Get-UnitPrefixIEC $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; + + $IcingaCheckByte = New-IcingaCheck -Name ([string]::Format( 'Used Partition Space in {0} for Partition {1}', $Unit, $Letter )) -Value $ByteValueConverted.Value -Unit $Unit; + $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); From 8ad871e0f94731608c27828f2ce1338b23e7b54e Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 10 Feb 2020 16:35:09 +0100 Subject: [PATCH 2/4] Fixes partition check for min/max, perf data unit and code styling --- .../Invoke-IcingaCheckUsedPartitionSpace.psm1 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 index cf3a5184..58398434 100644 --- a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 +++ b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 @@ -51,11 +51,10 @@ 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 -Verbos $Verbosity; $DiskBytePackage = New-IcingaCheckPackage -Name 'Used Partition Space in Bytes' -Verbose $Verbosity -Hidden; - foreach ($Letter in $DiskFree.Keys) { if ($Include.Count -ne 0) { $Include = $Include.trim(' :/\'); @@ -71,18 +70,20 @@ function Invoke-IcingaCheckUsedPartitionSpace() } } - $Unit = Get-UnitPrefixIEC $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); + $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; + $DiskSize = Convert-Bytes -Value ([string]::Format('{0}B', $DiskFree.([string]::Format($Letter))."Size")) -Unit $Unit; - $IcingaCheckByte = New-IcingaCheck -Name ([string]::Format( 'Used Partition Space in {0} for Partition {1}', $Unit, $Letter )) -Value $ByteValueConverted.Value -Unit $Unit; + $IcingaCheckByte = New-IcingaCheck -Name ([string]::Format( 'Used Space Partition {0}', $Letter )) -Value $ByteValueConverted.Value -Unit $PerfUnit -Minimum 0 -Maximum $DiskSize.Value; $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); } From 7d0ab37bba35aa1a691815c5e5b006a6d1c6db52 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Tue, 11 Feb 2020 09:22:33 +0100 Subject: [PATCH 3/4] Fixes -Verbose argument naming --- plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 index 58398434..22c39673 100644 --- a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 +++ b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 @@ -52,7 +52,7 @@ function Invoke-IcingaCheckUsedPartitionSpace() ); $DiskFree = Get-IcingaDiskPartitions; - $DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -OperatorAnd -Verbos $Verbosity; + $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) { From 60b433df8a2fd9d633a726d55a3a692f9fbed601 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Tue, 11 Feb 2020 09:46:18 +0100 Subject: [PATCH 4/4] Adds warning / critical perf data for used partition space --- .../Invoke-IcingaCheckUsedPartitionSpace.psm1 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 index 22c39673..3175341f 100644 --- a/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 +++ b/plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1 @@ -75,9 +75,23 @@ function Invoke-IcingaCheckUsedPartitionSpace() $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; - $DiskSize = Convert-Bytes -Value ([string]::Format('{0}B', $DiskFree.([string]::Format($Letter))."Size")) -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 '%';