mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Added Pending Windows Update check
This commit is contained in:
parent
7426ce0be2
commit
49b1beee5a
1 changed files with 54 additions and 0 deletions
54
lib/plugins/Invoke-IcingaCheckUpdates.psm1
Normal file
54
lib/plugins/Invoke-IcingaCheckUpdates.psm1
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
Import-IcingaLib icinga\plugin;
|
||||||
|
Import-IcingaLib provider\updates;
|
||||||
|
|
||||||
|
function Invoke-IcingaCheckUpdates()
|
||||||
|
{
|
||||||
|
param (
|
||||||
|
[array]$UpdateFilter,
|
||||||
|
$Warning,
|
||||||
|
$Critical,
|
||||||
|
[switch]$NoPerfData,
|
||||||
|
[int]$Verbose
|
||||||
|
);
|
||||||
|
|
||||||
|
$PendingUpdates = Get-IcingaUpdatesPending;
|
||||||
|
|
||||||
|
$UpdateCount = New-IcingaCheckPackage -Name 'Pending Update Count' -OperatorAnd;
|
||||||
|
$UpdateList = New-IcingaCheckPackage -Name 'Update List' -OperatorAnd;
|
||||||
|
$PendingCount = 0;
|
||||||
|
|
||||||
|
if ($UpdateFilter.Count -ne 0) {
|
||||||
|
foreach ($Filter in $UpdateFilter) {
|
||||||
|
foreach ($Update in $PendingUpdates.updates.Keys) {
|
||||||
|
if ($Update -Like $Filter) {
|
||||||
|
$PendingCount += 1;
|
||||||
|
$UpdateList.AddCheck(
|
||||||
|
(New-IcingaCheck -Name $Update -Value 'pending' -NoPerfData)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($PendingCount -eq 0) {
|
||||||
|
$UpdateList.AddCheck(
|
||||||
|
(New-IcingaCheck -Name 'No update' -Value 'pending' -NoPerfData)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$PendingCount = $PendingUpdates.count;
|
||||||
|
foreach ($Update in $PendingUpdates.updates.Keys) {
|
||||||
|
$UpdateList.AddCheck(
|
||||||
|
(New-IcingaCheck -Name $Update -Value 'pending' -NoPerfData)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$IcingaCheck = New-IcingaCheck -Name 'Pending Update Count' -Value $PendingCount;
|
||||||
|
$IcingaCheck.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
||||||
|
$UpdateCount.AddCheck($IcingaCheck);
|
||||||
|
|
||||||
|
$UpdatePackage = New-IcingaCheckPackage -Name 'Updates' -OperatorAnd -Verbose $Verbose -Checks @(
|
||||||
|
$UpdateCount, $UpdateList
|
||||||
|
);
|
||||||
|
|
||||||
|
exit (New-IcingaCheckResult -Name 'Pending Updates' -Check $UpdatePackage -NoPerfData $NoPerfData -Compile);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue