Skip to content

Commit 162c3df

Browse files
authored
Add explicit datatype string for units
Fixes issue, where Convert-Bytes throws error, because $Value is not a string.
1 parent 88eb859 commit 162c3df

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

plugins/Invoke-IcingaCheckMemory.psm1

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
PS>Invoke-IcingaCheckMemory -Verbosity 3 -Warning 60 -Critical 80
1414
[WARNING]: % Memory Check 78.74 is greater than 60
1515
.EXAMPLE
16-
PS> Invoke-IcingaCheckMemory -WarningPercent 0:30 -CriticalPercent 0:50
16+
PS> Invoke-IcingaCheckMemory -WarningPercent 30 -CriticalPercent 50
1717
[WARNING] Check package "Memory Usage" - [WARNING] Memory Percent Used
1818
\_ [WARNING] Memory Percent Used: Value "48.07%" is greater than threshold "30%"
1919
| 'memory_percent_used'=48.07%;0:30;0:50;0;100 'used_bytes'=3.85GB;;;0;8
@@ -55,12 +55,12 @@
5555
function Invoke-IcingaCheckMemory()
5656
{
5757
param(
58-
[string]$Critical = $null,
59-
[string]$Warning = $null,
60-
$CriticalPercent = $null,
61-
$WarningPercent = $null,
58+
[string]$Critical = $null,
59+
[string]$Warning = $null,
60+
$CriticalPercent = $null,
61+
$WarningPercent = $null,
6262
[ValidateSet(0, 1, 2, 3)]
63-
[int]$Verbosity = 0,
63+
[int]$Verbosity = 0,
6464
[switch]$NoPerfData
6565
);
6666

@@ -69,23 +69,23 @@ function Invoke-IcingaCheckMemory()
6969

7070
# Auto-Detect?
7171
If (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 50)) -ge 1) {
72-
$CalcUnit = 'PiB';
73-
$Unit = "PB";
72+
[string]$CalcUnit = 'PiB';
73+
[string]$Unit = "PB";
7474
} elseif (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 40)) -ge 1) {
75-
$CalcUnit = 'TiB';
76-
$Unit = "TB";
75+
[string]$CalcUnit = 'TiB';
76+
[string]$Unit = "TB";
7777
} elseif (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 30)) -ge 1) {
78-
$CalcUnit = 'GiB';
79-
$Unit = "GB";
78+
[string]$CalcUnit = 'GiB';
79+
[string]$Unit = "GB";
8080
} elseif (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 20)) -ge 1) {
81-
$CalcUnit = 'MiB';
82-
$Unit = "MB";
81+
[string]$CalcUnit = 'MiB';
82+
[string]$Unit = "MB";
8383
} elseif (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 10)) -ge 1) {
84-
$CalcUnit = 'KiB';
85-
$Unit = "KB";
84+
[string]$CalcUnit = 'KiB';
85+
[string]$Unit = "KB";
8686
} else {
87-
$CalcUnit = 'B';
88-
$Unit = "B";
87+
[string]$CalcUnit = 'B';
88+
[string]$Unit = "B";
8989
}
9090

9191
If ([string]::IsNullOrEmpty($Critical) -eq $FALSE) {

0 commit comments

Comments
 (0)