Skip to content

Commit 1a186d2

Browse files
authored
Merge pull request #378 from Icinga:feature/allow_service_plugin_to_report_not_found_as_critical
Feature: Adds support for Invoke-IcingaCheckService to report not found services as CRITICAL instead of UNKNOWN Allows users to change the plugin output behavior for Invoke-IcingaCheckService, to report CRITICAL instead of UNKNOWN in case a service could not be found on the system
2 parents 611d8a7 + be4cfbf commit 1a186d2

File tree

7 files changed

+84
-11
lines changed

7 files changed

+84
-11
lines changed

config/director/Invoke-IcingaCheckService.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-IcingaCheckService.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ object CheckCommand "Invoke-IcingaCheckService" {
5050
"-Verbosity" = {
5151
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])"
5252
value = "$IcingaCheckService_Int32_Verbosity$"
53+
order = 7
54+
}
55+
"-OverrideNotFound" = {
56+
set_if = {{
57+
var str = macro("$IcingaCheckService_String_OverrideNotFound$"); if (len(str) == 0) { return false; }; return true;
58+
}}
59+
description = "This argument will allow you to override the default behavior of the plugin in case a service was not found on the system. By default, it will report UNKNOWN but you can set with this argument if the service state should be OK, WARNING or CRITICAL instead"
60+
value = {{
61+
var str = macro("$IcingaCheckService_String_OverrideNotFound$");
62+
var argLen = len(str);
63+
if (argLen == 0) {
64+
return;
65+
}
66+
if (argLen != 0 && str.substr(0,1) == "'" && str.substr(argLen - 1, argLen) == "'") {
67+
return str;
68+
}
69+
return ("'" + str + "'");
70+
}}
5371
order = 6
5472
}
5573
"-Status" = {
@@ -144,6 +162,9 @@ object CheckCommand "Invoke-IcingaCheckService" {
144162
"Status" = {
145163
value = "$IcingaCheckService_String_Status$"
146164
}
165+
"OverrideNotFound" = {
166+
value = "$IcingaCheckService_String_OverrideNotFound$"
167+
}
147168
"Exclude" = {
148169
value = "$IcingaCheckService_Array_Exclude$"
149170
}

config/icinga/Plugins_Bundle.conf

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,7 +3497,7 @@ object CheckCommand "Invoke-IcingaCheckUNCPath" {
34973497

34983498
arguments += {
34993499
"-WarningTotal" = {
3500-
description = "A warning 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"
3500+
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"
35013501
value = "$IcingaCheckUNCPath_Object_WarningTotal$"
35023502
order = 8
35033503
}
@@ -4122,6 +4122,24 @@ object CheckCommand "Invoke-IcingaCheckService" {
41224122
"-Verbosity" = {
41234123
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])"
41244124
value = "$IcingaCheckService_Int32_Verbosity$"
4125+
order = 7
4126+
}
4127+
"-OverrideNotFound" = {
4128+
set_if = {{
4129+
var str = macro("$IcingaCheckService_String_OverrideNotFound$"); if (len(str) == 0) { return false; }; return true;
4130+
}}
4131+
description = "This argument will allow you to override the default behavior of the plugin in case a service was not found on the system. By default, it will report UNKNOWN but you can set with this argument if the service state should be OK, WARNING or CRITICAL instead"
4132+
value = {{
4133+
var str = macro("$IcingaCheckService_String_OverrideNotFound$");
4134+
var argLen = len(str);
4135+
if (argLen == 0) {
4136+
return;
4137+
}
4138+
if (argLen != 0 && str.substr(0,1) == "'" && str.substr(argLen - 1, argLen) == "'") {
4139+
return str;
4140+
}
4141+
return ("'" + str + "'");
4142+
}}
41254143
order = 6
41264144
}
41274145
"-Status" = {
@@ -4216,6 +4234,9 @@ object CheckCommand "Invoke-IcingaCheckService" {
42164234
"Status" = {
42174235
value = "$IcingaCheckService_String_Status$"
42184236
}
4237+
"OverrideNotFound" = {
4238+
value = "$IcingaCheckService_String_OverrideNotFound$"
4239+
}
42194240
"Exclude" = {
42204241
value = "$IcingaCheckService_Array_Exclude$"
42214242
}
@@ -4807,12 +4828,12 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
48074828
order = 99
48084829
}
48094830
"-CriticalOther" = {
4810-
description = "The critical threshold for the total pending update count on the Windows machine"
4831+
description = "The critical threshold for all other updates on the Windows machine"
48114832
value = "$IcingaCheckUpdates_Object_CriticalOther$"
48124833
order = 12
48134834
}
48144835
"-WarningDefender" = {
4815-
description = "The warning threshold for the Microsoft Defender update count on the Windows machine"
4836+
description = "The warning threshold for the total pending update count on the Windows machine"
48164837
value = "$IcingaCheckUpdates_Object_WarningDefender$"
48174838
order = 9
48184839
}
@@ -4850,7 +4871,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
48504871
order = 10
48514872
}
48524873
"-CriticalRollups" = {
4853-
description = "The critical threshold for the total pending update count on the Windows machine"
4874+
description = "The critical threshold for the rollup update count on the Windows machine"
48544875
value = "$IcingaCheckUpdates_Object_CriticalRollups$"
48554876
order = 8
48564877
}
@@ -4892,7 +4913,7 @@ object CheckCommand "Invoke-IcingaCheckUpdates" {
48924913
order = 5
48934914
}
48944915
"-CriticalSecurity" = {
4895-
description = "The critical threshold for the total pending update count on the Windows machine"
4916+
description = "The critical threshold for the security update count on the Windows machine"
48964917
value = "$IcingaCheckUpdates_Object_CriticalSecurity$"
48974918
order = 6
48984919
}

doc/31-Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2121

2222
# 1.11.1 (2023-11-07)
2323

24+
* [#378](https://github.com/Icinga/icinga-powershell-plugins/pull/378) Adds support for `Invoke-IcingaCheckService` to change the output for not found services from UNKNOWN to OK, WARNING or CRITICAL instead
25+
26+
# 1.11.1 (tbd)
27+
2428
### Bugfixes
2529

2630
* [#358](https://github.com/Icinga/icinga-powershell-plugins/issues/358) Fixes broken Icinga plain configuration

doc/plugins/13-Invoke-IcingaCheckService.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ To execute this plugin you will require to grant the following user permissions.
2929
| Status | String | false | Running | Status for the specified service or services to check against. |
3030
| FilterStartupType | Array | false | @() | Allows to include only services with a specific startup type inside the monitoring,<br /> in case you check for a list of specific services by using `-Service` |
3131
| MitigateUnknown | SwitchParameter | false | False | This will tell the plugin to return OK instead of UNKNOWN, in case no service was added to this<br /> check |
32+
| OverrideNotFound | String | false | Unknown | This argument will allow you to override the default behavior of the plugin in case a service was not found on the<br /> system. By default, it will report UNKNOWN but you can set with this argument if the service state should be<br /> OK, WARNING or CRITICAL instead |
3233
| Verbosity | Int32 | false | 0 | Changes the behavior of the plugin output which check states are printed:<br /> 0 (default): Only service checks/packages with state not OK will be printed<br /> 1: Only services with not OK will be printed including OK checks of affected check packages including Package config<br /> 2: Everything will be printed regardless of the check state<br /> 3: Identical to Verbose 2, but prints in addition the check package configuration e.g (All must be [OK]) |
3334
| NoPerfData | SwitchParameter | false | False | Disables the performance data output of this plugin |
3435
| ThresholdInterval | String | | | Change the value your defined threshold checks against from the current value to a collected time threshold of the Icinga for Windows daemon, as described [here](https://icinga.com/docs/icinga-for-windows/latest/doc/service/10-Register-Service-Checks/). An example for this argument would be 1m or 15m which will use the average of 1m or 15m for monitoring. |

plugins/Invoke-IcingaCheckService.psm1

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
.PARAMETER MitigateUnknown
5252
This will tell the plugin to return OK instead of UNKNOWN, in case no service was added to this
5353
check
54+
.PARAMETER OverrideNotFound
55+
This argument will allow you to override the default behavior of the plugin in case a service was not found on the
56+
system. By default, it will report UNKNOWN but you can set with this argument if the service state should be
57+
OK, WARNING or CRITICAL instead
5458
.PARAMETER NoPerfData
5559
Disables the performance data output of this plugin
5660
.PARAMETER Verbosity
@@ -67,7 +71,6 @@
6771
https://github.com/Icinga/icinga-powershell-plugins
6872
.NOTES
6973
#>
70-
7174
function Invoke-IcingaCheckService()
7275
{
7376
param (
@@ -78,6 +81,8 @@ function Invoke-IcingaCheckService()
7881
[ValidateSet('Boot', 'System', 'Automatic', 'Manual', 'Disabled', 'Unknown')]
7982
[array]$FilterStartupType = @(),
8083
[switch]$MitigateUnknown = $FALSE,
84+
[ValidateSet('Ok', 'Warning', 'Critical', 'Unknown')]
85+
[string]$OverrideNotFound = 'Unknown',
8186
[ValidateSet(0, 1, 2, 3)]
8287
[int]$Verbosity = 0,
8388
[switch]$NoPerfData
@@ -167,9 +172,30 @@ function Invoke-IcingaCheckService()
167172
continue;
168173
}
169174

170-
$ServicesPackage.AddCheck(
171-
(New-IcingaCheck -Name ([string]::Format('{0}: Service not found', $ServiceArg)) -NoPerfData).SetUnknown()
172-
);
175+
$ServiceNotFound = $null;
176+
$UnknownName = [string]::Format('{0}:', $ServiceArg);
177+
$UnknownValue = 'Service not found';
178+
179+
switch ($OverrideNotFound.ToLower()) {
180+
'ok' {
181+
$ServiceNotFound = (New-IcingaCheck -Name $UnknownName -Value $UnknownValue -NoPerfData).SetOk();
182+
break;
183+
};
184+
'warning' {
185+
$ServiceNotFound = (New-IcingaCheck -Name $UnknownName -Value $UnknownValue -NoPerfData).SetWarning();
186+
break;
187+
};
188+
'critical' {
189+
$ServiceNotFound = (New-IcingaCheck -Name $UnknownName -Value $UnknownValue -NoPerfData).SetCritical();
190+
break;
191+
};
192+
default {
193+
$ServiceNotFound = (New-IcingaCheck -Name $UnknownName -Value $UnknownValue -NoPerfData).SetUnknown();
194+
break;
195+
};
196+
}
197+
198+
$ServicesPackage.AddCheck($ServiceNotFound);
173199
}
174200
}
175201

0 commit comments

Comments
 (0)