mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Added tool function to increase digit count
* Added new function Format-IcingaDigitCount to fill digits with leading 0 depending on missing values * Added this function to CPU check
This commit is contained in:
parent
0fed0f938c
commit
423791750a
2 changed files with 25 additions and 2 deletions
22
lib/core/tools/Format-IcingaDigitCount.psm1
Normal file
22
lib/core/tools/Format-IcingaDigitCount.psm1
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
function Format-IcingaDigitCount()
|
||||
{
|
||||
param(
|
||||
[string]$Value,
|
||||
[int]$Digits
|
||||
);
|
||||
|
||||
if ([string]::IsNullOrEmpty($Value)) {
|
||||
return $Value;
|
||||
}
|
||||
|
||||
$CurrentLength = $Value.Length;
|
||||
if ($CurrentLength -ge $Digits) {
|
||||
return $Value;
|
||||
}
|
||||
|
||||
while ($Value.Length -lt $Digits) {
|
||||
$Value = [string]::Format('0{0}', $Value);
|
||||
}
|
||||
|
||||
return $Value;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
Import-IcingaLib core\perfcounter;
|
||||
Import-IcingaLib core\tools;
|
||||
Import-IcingaLib icinga\plugin;
|
||||
|
||||
function Invoke-IcingaCheckCPU()
|
||||
|
|
@ -16,12 +17,12 @@ function Invoke-IcingaCheckCPU()
|
|||
|
||||
if ($CpuCounter.Counters.Count -ne 0) {
|
||||
foreach ($counter in $CpuCounter.Counters) {
|
||||
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Core #{0}', $counter.Instance)) -Value $counter.Value().Value -Unit '%';
|
||||
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Core #{0}', (Format-IcingaDigitCount $counter.Instance -Digits 3))) -Value $counter.Value().Value -Unit '%';
|
||||
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
$CpuPackage.AddCheck($IcingaCheck);
|
||||
}
|
||||
} else {
|
||||
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Core #{0}',$Core)) -Value $CpuCounter.Value().Value -Unit '%';
|
||||
$IcingaCheck = New-IcingaCheck -Name ([string]::Format('Core #{0}', (Format-IcingaDigitCount $Core -Digits 3))) -Value $CpuCounter.Value().Value -Unit '%';
|
||||
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||
$CpuPackage.AddCheck($IcingaCheck);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue