2019-08-20 11:02:58 -04:00
|
|
|
Import-IcingaLib icinga\plugin;
|
|
|
|
|
Import-IcingaLib provider\windows;
|
|
|
|
|
Import-IcingaLib core\tools;
|
|
|
|
|
|
2019-10-28 11:10:27 -04:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Checks how long a Windows system has been up for.
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
InvokeIcingaCheckUptime returns either 'OK', 'WARNING' or 'CRITICAL', based on the thresholds set.
|
|
|
|
|
e.g 'C:\Users\Icinga\Backup' the system has been running for 10 days, WARNING is set to 15d, CRITICAL is set to 30d. In this case the check will return OK.
|
|
|
|
|
More Information on https://github.com/LordHepipud/icinga-module-windows
|
|
|
|
|
.FUNCTIONALITY
|
|
|
|
|
This module is intended to check how long a Windows system has been up for.
|
|
|
|
|
Based on the thresholds set the status will change between 'OK', 'WARNING' or 'CRITICAL'. The function will return one of these given codes.
|
|
|
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> Invoke-IcingaCheckUptime -Warning 18d -Critical 20d
|
|
|
|
|
[WARNING]: Check package "Windows Uptime: Days: 19 Hours: 13 Minutes: 48 Seconds: 29" is [WARNING]
|
|
|
|
|
| 'Windows Uptime'=1691309,539176s;1555200;1728000
|
|
|
|
|
.PARAMETER IcingaCheckUsers_String_Warning
|
|
|
|
|
Used to specify a Warning threshold. In this case a string.
|
|
|
|
|
Allowed units include: ms, s, m, h, d, w, M, y
|
|
|
|
|
.PARAMETER IcingaCheckUsers_String_Critical
|
|
|
|
|
Used to specify a Critical threshold. In this case a string.
|
|
|
|
|
Allowed units include: ms, s, m, h, d, w, M, y
|
|
|
|
|
.INPUTS
|
|
|
|
|
System.String
|
|
|
|
|
.OUTPUTS
|
|
|
|
|
System.String
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/LordHepipud/icinga-module-windows
|
|
|
|
|
.NOTES
|
|
|
|
|
#>
|
|
|
|
|
|
2019-08-20 11:02:58 -04:00
|
|
|
function Invoke-IcingaCheckUptime()
|
|
|
|
|
{
|
|
|
|
|
param(
|
2019-10-29 05:18:20 -04:00
|
|
|
[string]$Warning = $null,
|
|
|
|
|
[string]$Critical = $null,
|
2019-08-20 11:02:58 -04:00
|
|
|
[switch]$NoPerfData,
|
2019-10-29 05:18:20 -04:00
|
|
|
[ValidateSet(0, 1, 2, 3)]
|
|
|
|
|
[int]$Verbosity = 0
|
|
|
|
|
);
|
2019-08-20 11:02:58 -04:00
|
|
|
|
|
|
|
|
$WindowsData = Get-IcingaWindows;
|
|
|
|
|
$Name = ([string]::Format('Windows Uptime: {0}', (ConvertFrom-TimeSpan -Seconds $WindowsData.windows.metadata.uptime.value)));
|
|
|
|
|
|
|
|
|
|
$IcingaCheck = New-IcingaCheck -Name 'Windows Uptime' -Value $WindowsData.windows.metadata.uptime.value -Unit 's';
|
|
|
|
|
$IcingaCheck.WarnOutOfRange(
|
|
|
|
|
(ConvertTo-SecondsFromIcingaThresholds -Threshold $Warning)
|
|
|
|
|
).CritOutOfRange(
|
|
|
|
|
(ConvertTo-SecondsFromIcingaThresholds -Threshold $Critical)
|
|
|
|
|
) | Out-Null;
|
|
|
|
|
|
2019-10-29 05:18:20 -04:00
|
|
|
$CheckPackage = New-IcingaCheckPackage -Name $Name -OperatorAnd -Checks $IcingaCheck -Verbose $Verbosity;
|
2019-08-20 11:02:58 -04:00
|
|
|
|
2019-09-25 13:57:19 -04:00
|
|
|
return (New-IcingaCheckresult -Check $CheckPackage -NoPerfData $NoPerfData -Compile);
|
2019-08-20 11:02:58 -04:00
|
|
|
}
|