Skip to content

Commit

Permalink
Adds support to Invoke-IcingaCheckPartitionSpace to define mandatory …
Browse files Browse the repository at this point in the history
…partitions which should always be present
  • Loading branch information
LordHepipud committed Mar 25, 2024
1 parent 1a186d2 commit 12218e5
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/director/Invoke-IcingaCheckPartitionSpace.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/director/Plugins_Bundle.json

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion config/icinga/Invoke-IcingaCheckPartitionSpace.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
"-Verbosity" = {
description = "Changes the behavior of the plugin output which check states are printed: 0 (default): Only service checks/packages with state not OK will be printed 1: Only services with not OK will be printed including OK checks of affected check packages including Package config 2: Everything will be printed regardless of the check state 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK])"
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
order = 6
order = 7
}
"-ThresholdInterval" = {
set_if = {{
Expand Down Expand Up @@ -93,6 +93,29 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
}}
order = 5
}
"-RequiredPartition" = {
description = "Allows to define a list of partitions which should be included in the check. e.g. 'C:','D:' In case they are missing, the plugin will report CRITICAL"
value = {{
var arr = macro("$IcingaCheckPartitionSpace_Array_RequiredPartition$");
if (len(arr) == 0) {
return "@()";
}
var psarr = arr.map(
x => if (typeof(x) == String) {
var argLen = len(x);
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
x;
} else {
"'" + x + "'";
}
} else {
x;
}
).join(",");
return "@(" + psarr + ")";
}}
order = 6
}
"-SkipUnknown" = {
set_if = "$IcingaCheckPartitionSpace_Switchparameter_SkipUnknown$"
order = 99
Expand All @@ -102,6 +125,9 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
"Verbosity" = {
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
}
"RequiredPartition" = {
value = "$IcingaCheckPartitionSpace_Array_RequiredPartition$"
}
"ThresholdInterval" = {
value = "$IcingaCheckPartitionSpace_String_ThresholdInterval$"
}
Expand Down
38 changes: 32 additions & 6 deletions config/icinga/Plugins_Bundle.conf
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
"-Verbosity" = {
description = "Changes the behavior of the plugin output which check states are printed: 0 (default): Only service checks/packages with state not OK will be printed 1: Only services with not OK will be printed including OK checks of affected check packages including Package config 2: Everything will be printed regardless of the check state 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK])"
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
order = 6
order = 7
}
"-ThresholdInterval" = {
set_if = {{
Expand Down Expand Up @@ -621,6 +621,29 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
}}
order = 5
}
"-RequiredPartition" = {
description = "Allows to define a list of partitions which should be included in the check. e.g. 'C:','D:' In case they are missing, the plugin will report CRITICAL"
value = {{
var arr = macro("$IcingaCheckPartitionSpace_Array_RequiredPartition$");
if (len(arr) == 0) {
return "@()";
}
var psarr = arr.map(
x => if (typeof(x) == String) {
var argLen = len(x);
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
x;
} else {
"'" + x + "'";
}
} else {
x;
}
).join(",");
return "@(" + psarr + ")";
}}
order = 6
}
"-SkipUnknown" = {
set_if = "$IcingaCheckPartitionSpace_Switchparameter_SkipUnknown$"
order = 99
Expand All @@ -630,6 +653,9 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
"Verbosity" = {
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
}
"RequiredPartition" = {
value = "$IcingaCheckPartitionSpace_Array_RequiredPartition$"
}
"ThresholdInterval" = {
value = "$IcingaCheckPartitionSpace_String_ThresholdInterval$"
}
Expand Down Expand Up @@ -3543,7 +3569,7 @@ object CheckCommand "Invoke-IcingaCheckUNCPath" {
order = 10
}
"-CriticalTotal" = {
description = "A warning threshold for the shares total free space in byte units, like '50GB:' Please note that this value is decreasing over time, therefor you will have to use the plugin handler and add ':' at the end of your input to check for 'current value < threshold' like in the previous example Allowed units: B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB"
description = "A critical threshold for the shares free space in either % or byte units, like '20%:' or '50GB:' Please note that this value is decreasing over time, therefor you will have to use the plugin handler and add ':' at the end of your input to check for 'current value < threshold' like in the previous example Allowed units: %, B, KB, MB, GB, TB, PB, KiB, MiB, GiB, TiB, PiB"
value = "$IcingaCheckUNCPath_Object_CriticalTotal$"
order = 9
}
Expand Down Expand Up @@ -4810,7 +4836,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {

arguments += {
"-WarningRollups" = {
description = "The warning threshold for the total pending update count on the Windows machine"
description = "The warning threshold for the rollup update count on the Windows machine"
value = "$IcingaCheckUpdates_Object_WarningRollups$"
order = 7
}
Expand Down Expand Up @@ -4856,7 +4882,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
order = 100
}
"-WarningOther" = {
description = "The warning threshold for the total pending update count on the Windows machine"
description = "The warning threshold for all other updates on the Windows machine"
value = "$IcingaCheckUpdates_Object_WarningOther$"
order = 11
}
Expand All @@ -4866,7 +4892,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
order = 3
}
"-CriticalDefender" = {
description = "The critical threshold for the total pending update count on the Windows machine"
description = "The critical threshold for the Microsoft Defender update count on the Windows machine"
value = "$IcingaCheckUpdates_Object_CriticalDefender$"
order = 10
}
Expand Down Expand Up @@ -4908,7 +4934,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
order = 2
}
"-WarningSecurity" = {
description = "The warning threshold for the total pending update count on the Windows machine"
description = "The warning threshold for the security update count on the Windows machine"
value = "$IcingaCheckUpdates_Object_WarningSecurity$"
order = 5
}
Expand Down
1 change: 1 addition & 0 deletions doc/31-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic

### Enhancements

* [#288](https://github.com/Icinga/icinga-powershell-plugins/issues/288) Adds support to `Invoke-IcingaCheckPartitionSpace` to define mandatory partitions which should always be present
* [#366](https://github.com/Icinga/icinga-powershell-plugins/issues/366) Adds support to `Invoke-IcingaCheckCPU` to report top CPU consuming process information as well as a switch to change the overall load from average to sum

# 1.11.1 (2023-11-07)
Expand Down
27 changes: 23 additions & 4 deletions plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
.PARAMETER Exclude
Used to specify an array of partitions to be excluded.
e.g. 'C:','D:'
.PARAMETER RequiredPartition
Allows to define a list of partitions which should be included in the check.
e.g. 'C:','D:'
In case they are missing, the plugin will report CRITICAL
.PARAMETER Include
Used to specify an array of partitions to be included. If not set, the check expects that all not excluded partitions should be checked.
e.g. 'C:','D:'
Expand Down Expand Up @@ -93,6 +98,7 @@ function Invoke-IcingaCheckPartitionSpace()
$Critical = $null,
[array]$Include = @(),
[array]$Exclude = @(),
[array]$RequiredPartition = @(),
[switch]$IgnoreEmptyChecks = $FALSE,
[switch]$NoPerfData = $FALSE,
[switch]$SkipUnknown = $FALSE,
Expand All @@ -101,8 +107,9 @@ function Invoke-IcingaCheckPartitionSpace()
[int]$Verbosity = 0
);

$Disks = Get-IcingaPartitionSpace;
$DiskPackage = $null;
$Disks = Get-IcingaPartitionSpace;
$DiskPackage = $null;
[array]$KnownPartitions = @();

if ($CheckUsedSpace) {
$DiskPackage = New-IcingaCheckPackage -Name 'Used Partition Space' -Verbose $Verbosity -IgnoreEmptyPackage:$IgnoreEmptyChecks -OperatorAnd -AddSummaryHeader;
Expand All @@ -111,15 +118,18 @@ function Invoke-IcingaCheckPartitionSpace()
}

foreach ($partition in $Disks.Keys) {
$partition = $Disks[$partition];
$ProcessPartition = $TRUE;
$partition = $Disks[$partition];
$ProcessPartition = $TRUE;
$PartitionMandatory = $FALSE;

if ([string]::IsNullOrEmpty($partition.DriveLetter)) {
continue;
}

$FormattedLetter = $partition.DriveLetter.Replace(':', '').ToLower();

[array]$KnownPartitions += $FormattedLetter;

foreach ($entry in $Include) {
$ProcessPartition = $FALSE;
if ($entry.Replace(':', '').Replace('\', '').Replace('/', '').ToLower() -eq $FormattedLetter) {
Expand Down Expand Up @@ -159,6 +169,15 @@ function Invoke-IcingaCheckPartitionSpace()
$DiskPackage.AddCheck($IcingaCheck);
}

foreach ($mandatoryPartition in $RequiredPartition) {
$reqPartition = $mandatoryPartition.Replace(':', '').Replace('\', '').Replace('/', '').ToLower();

if ($KnownPartitions.Contains($reqPartition) -eq $FALSE) {
$IcingaCheck = (New-IcingaCheck -Name ([string]::Format('Partition {0}', $reqPartition.ToUpper())) -Value 'Mandatory partition not found on host' -NoPerfData).SetCritical();
$DiskPackage.AddCheck($IcingaCheck);
}
}

return (New-IcingaCheckResult -Check $DiskPackage -NoPerfData $NoPerfData -Compile);
}

Expand Down

0 comments on commit 12218e5

Please sign in to comment.