Skip to content

Commit c5b23f3

Browse files
authored
Merge pull request #393 from Icinga:feature/adds_support_to_partition_plugin_for_mandatory_partitions
Feature: Adds support for mandatory partitions to Invoke-IcingaCheckPartitionSpace Adds support to Invoke-IcingaCheckPartitionSpace to define mandatory partitions which should always be present
2 parents 1a186d2 + 12218e5 commit c5b23f3

File tree

6 files changed

+85
-13
lines changed

6 files changed

+85
-13
lines changed

config/director/Invoke-IcingaCheckPartitionSpace.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

config/director/Plugins_Bundle.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

config/icinga/Invoke-IcingaCheckPartitionSpace.conf

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
55
"-Verbosity" = {
66
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])"
77
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
8-
order = 6
8+
order = 7
99
}
1010
"-ThresholdInterval" = {
1111
set_if = {{
@@ -93,6 +93,29 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
9393
}}
9494
order = 5
9595
}
96+
"-RequiredPartition" = {
97+
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"
98+
value = {{
99+
var arr = macro("$IcingaCheckPartitionSpace_Array_RequiredPartition$");
100+
if (len(arr) == 0) {
101+
return "@()";
102+
}
103+
var psarr = arr.map(
104+
x => if (typeof(x) == String) {
105+
var argLen = len(x);
106+
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
107+
x;
108+
} else {
109+
"'" + x + "'";
110+
}
111+
} else {
112+
x;
113+
}
114+
).join(",");
115+
return "@(" + psarr + ")";
116+
}}
117+
order = 6
118+
}
96119
"-SkipUnknown" = {
97120
set_if = "$IcingaCheckPartitionSpace_Switchparameter_SkipUnknown$"
98121
order = 99
@@ -102,6 +125,9 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
102125
"Verbosity" = {
103126
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
104127
}
128+
"RequiredPartition" = {
129+
value = "$IcingaCheckPartitionSpace_Array_RequiredPartition$"
130+
}
105131
"ThresholdInterval" = {
106132
value = "$IcingaCheckPartitionSpace_String_ThresholdInterval$"
107133
}

config/icinga/Plugins_Bundle.conf

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
533533
"-Verbosity" = {
534534
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])"
535535
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
536-
order = 6
536+
order = 7
537537
}
538538
"-ThresholdInterval" = {
539539
set_if = {{
@@ -621,6 +621,29 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
621621
}}
622622
order = 5
623623
}
624+
"-RequiredPartition" = {
625+
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"
626+
value = {{
627+
var arr = macro("$IcingaCheckPartitionSpace_Array_RequiredPartition$");
628+
if (len(arr) == 0) {
629+
return "@()";
630+
}
631+
var psarr = arr.map(
632+
x => if (typeof(x) == String) {
633+
var argLen = len(x);
634+
if (argLen != 0 && x.substr(0,1) == "'" && x.substr(argLen - 1, argLen) == "'") {
635+
x;
636+
} else {
637+
"'" + x + "'";
638+
}
639+
} else {
640+
x;
641+
}
642+
).join(",");
643+
return "@(" + psarr + ")";
644+
}}
645+
order = 6
646+
}
624647
"-SkipUnknown" = {
625648
set_if = "$IcingaCheckPartitionSpace_Switchparameter_SkipUnknown$"
626649
order = 99
@@ -630,6 +653,9 @@ object CheckCommand "Invoke-IcingaCheckPartitionSpace" {
630653
"Verbosity" = {
631654
value = "$IcingaCheckPartitionSpace_Int32_Verbosity$"
632655
}
656+
"RequiredPartition" = {
657+
value = "$IcingaCheckPartitionSpace_Array_RequiredPartition$"
658+
}
633659
"ThresholdInterval" = {
634660
value = "$IcingaCheckPartitionSpace_String_ThresholdInterval$"
635661
}
@@ -3543,7 +3569,7 @@ object CheckCommand "Invoke-IcingaCheckUNCPath" {
35433569
order = 10
35443570
}
35453571
"-CriticalTotal" = {
3546-
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"
3572+
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"
35473573
value = "$IcingaCheckUNCPath_Object_CriticalTotal$"
35483574
order = 9
35493575
}
@@ -4810,7 +4836,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
48104836

48114837
arguments += {
48124838
"-WarningRollups" = {
4813-
description = "The warning threshold for the total pending update count on the Windows machine"
4839+
description = "The warning threshold for the rollup update count on the Windows machine"
48144840
value = "$IcingaCheckUpdates_Object_WarningRollups$"
48154841
order = 7
48164842
}
@@ -4856,7 +4882,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
48564882
order = 100
48574883
}
48584884
"-WarningOther" = {
4859-
description = "The warning threshold for the total pending update count on the Windows machine"
4885+
description = "The warning threshold for all other updates on the Windows machine"
48604886
value = "$IcingaCheckUpdates_Object_WarningOther$"
48614887
order = 11
48624888
}
@@ -4866,7 +4892,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
48664892
order = 3
48674893
}
48684894
"-CriticalDefender" = {
4869-
description = "The critical threshold for the total pending update count on the Windows machine"
4895+
description = "The critical threshold for the Microsoft Defender update count on the Windows machine"
48704896
value = "$IcingaCheckUpdates_Object_CriticalDefender$"
48714897
order = 10
48724898
}
@@ -4908,7 +4934,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
49084934
order = 2
49094935
}
49104936
"-WarningSecurity" = {
4911-
description = "The warning threshold for the total pending update count on the Windows machine"
4937+
description = "The warning threshold for the security update count on the Windows machine"
49124938
value = "$IcingaCheckUpdates_Object_WarningSecurity$"
49134939
order = 5
49144940
}

doc/31-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1717

1818
### Enhancements
1919

20+
* [#288](https://github.com/Icinga/icinga-powershell-plugins/issues/288) Adds support to `Invoke-IcingaCheckPartitionSpace` to define mandatory partitions which should always be present
2021
* [#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
2122

2223
# 1.11.1 (2023-11-07)

plugins/Invoke-IcingaCheckUsedPartitionSpace.psm1

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
.PARAMETER Exclude
6060
Used to specify an array of partitions to be excluded.
6161
e.g. 'C:','D:'
62+
.PARAMETER RequiredPartition
63+
Allows to define a list of partitions which should be included in the check.
64+
e.g. 'C:','D:'
65+
66+
In case they are missing, the plugin will report CRITICAL
6267
.PARAMETER Include
6368
Used to specify an array of partitions to be included. If not set, the check expects that all not excluded partitions should be checked.
6469
e.g. 'C:','D:'
@@ -93,6 +98,7 @@ function Invoke-IcingaCheckPartitionSpace()
9398
$Critical = $null,
9499
[array]$Include = @(),
95100
[array]$Exclude = @(),
101+
[array]$RequiredPartition = @(),
96102
[switch]$IgnoreEmptyChecks = $FALSE,
97103
[switch]$NoPerfData = $FALSE,
98104
[switch]$SkipUnknown = $FALSE,
@@ -101,8 +107,9 @@ function Invoke-IcingaCheckPartitionSpace()
101107
[int]$Verbosity = 0
102108
);
103109

104-
$Disks = Get-IcingaPartitionSpace;
105-
$DiskPackage = $null;
110+
$Disks = Get-IcingaPartitionSpace;
111+
$DiskPackage = $null;
112+
[array]$KnownPartitions = @();
106113

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

113120
foreach ($partition in $Disks.Keys) {
114-
$partition = $Disks[$partition];
115-
$ProcessPartition = $TRUE;
121+
$partition = $Disks[$partition];
122+
$ProcessPartition = $TRUE;
123+
$PartitionMandatory = $FALSE;
116124

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

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

131+
[array]$KnownPartitions += $FormattedLetter;
132+
123133
foreach ($entry in $Include) {
124134
$ProcessPartition = $FALSE;
125135
if ($entry.Replace(':', '').Replace('\', '').Replace('/', '').ToLower() -eq $FormattedLetter) {
@@ -159,6 +169,15 @@ function Invoke-IcingaCheckPartitionSpace()
159169
$DiskPackage.AddCheck($IcingaCheck);
160170
}
161171

172+
foreach ($mandatoryPartition in $RequiredPartition) {
173+
$reqPartition = $mandatoryPartition.Replace(':', '').Replace('\', '').Replace('/', '').ToLower();
174+
175+
if ($KnownPartitions.Contains($reqPartition) -eq $FALSE) {
176+
$IcingaCheck = (New-IcingaCheck -Name ([string]::Format('Partition {0}', $reqPartition.ToUpper())) -Value 'Mandatory partition not found on host' -NoPerfData).SetCritical();
177+
$DiskPackage.AddCheck($IcingaCheck);
178+
}
179+
}
180+
162181
return (New-IcingaCheckResult -Check $DiskPackage -NoPerfData $NoPerfData -Compile);
163182
}
164183

0 commit comments

Comments
 (0)