This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck_load.ps1
59 lines (52 loc) · 1.45 KB
/
check_load.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<#
.Synopsis
PowerShell adoption of check_load from Icinga
.DESCRIPTION
More Information on https://github.com/LordHepipud/icinga2-powershell-plugins
.EXAMPLE
check_load.ps1 -w 20 -c 40
.NOTES
This plugin requires the Icinga 2 PerfCounter Lib from
https://github.com/LordHepipud/icinga2-perfcounter-lib
#>
param(
# The warning threshold in percent for the current load
[Alias('w')]
[float]$Warning = 0,
# The critical threshold in percent for the current load
[Alias('c')]
[float]$Critical = 0,
# Print detailed debug informations of the script
[Alias('d')]
[Switch]$Debug = $FALSE
)
if ($Debug) {
Set-PSDebug -Trace 2
}
function Icinga2CheckLoad
{
param(
[float]$Warning = 0,
[float]$Critical = 0
)
$CPUCounter = Get-Icinga2Counter -CounterArray @(
'\Processor(_Total)\% Processor Time'
)
[float]$CPULoad = $CPUCounter['\Processor(_Total)\% Processor Time'].value;
[string]$Severity = 'OK';
[int]$ExitCode = 0;
if ($Critical -ne 0 -And $CPULoad -ge $Critical) {
$Severity = 'CRITICAL';
$ExitCode = 2;
} elseif ($Warning -ne 0 -And $CPULoad -ge $Warning) {
$Severity = 'WARNING';
$ExitCode = 1;
}
Write-Host ([string]::Format('LOAD {0} {1}% | load={1}%;{2};{3};0;100',
$Severity,
$CPULoad,
$Warning,
$Critical
));
}
exit Icinga2CheckLoad -Warning $Warning -Critical $Critical;