mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
* Added new function Format-IcingaDigitCount to fill digits with leading 0 depending on missing values * Added this function to CPU check
31 lines
1.3 KiB
PowerShell
31 lines
1.3 KiB
PowerShell
Import-IcingaLib core\perfcounter;
|
|
Import-IcingaLib core\tools;
|
|
Import-IcingaLib icinga\plugin;
|
|
|
|
function Invoke-IcingaCheckCPU()
|
|
{
|
|
param(
|
|
$Warning,
|
|
$Critical,
|
|
$Core = '*',
|
|
[switch]$NoPerfData,
|
|
$Verbose
|
|
);
|
|
|
|
$CpuCounter = New-IcingaPerformanceCounter -Counter ([string]::Format('\Processor({0})\% processor time', $Core));
|
|
$CpuPackage = New-IcingaCheckPackage -Name 'CPU Load' -OperatorAnd -Verbos $Verbose;
|
|
|
|
if ($CpuCounter.Counters.Count -ne 0) {
|
|
foreach ($counter in $CpuCounter.Counters) {
|
|
$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}', (Format-IcingaDigitCount $Core -Digits 3))) -Value $CpuCounter.Value().Value -Unit '%';
|
|
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
|
$CpuPackage.AddCheck($IcingaCheck);
|
|
}
|
|
|
|
exit (New-IcingaCheckResult -Name 'CPU Load' -Check $CpuPackage -NoPerfData $NoPerfData -Compile);
|
|
}
|