Skip to content

Commit 080ea6f

Browse files
authored
Merge pull request #246 from Icinga:fix/service_check_display_name_filtering
Fix: Wrong UNKNOWN while using service display name While using the service display name for `Invoke-IcingaCheckService`, the correct service is added, but also an unknown because we only checked if the service is present by it's name instead of the display name. This will now resolve this issue and allow the monitoring by using the name and the display name with proper results.
2 parents fbd52b9 + 3818a9c commit 080ea6f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

doc/31-Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ documentation before upgrading to a new release.
77

88
Released closed milestones can be found on [GitHub](https://github.com/Icinga/icinga-powershell-plugins/milestones?state=closed).
99

10+
## 1.8.0 (2022-02-08)
11+
12+
[Issue and PRs](https://github.com/Icinga/icinga-powershell-plugins/milestone/11?closed=1)
13+
14+
* [#246](https://github.com/Icinga/icinga-powershell-plugins/pull/246) Fixes wrong `UNKNOWN` on `Invoke-IcingaCheckService` while using service display name with the `-Service` argument instead of the service name
15+
1016
## 1.7.0 (2021-11-09)
1117

1218
[Issue and PRs](https://github.com/Icinga/icinga-powershell-plugins/milestone/10?closed=1)

plugins/Invoke-IcingaCheckService.psm1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ function Invoke-IcingaCheckService()
144144
if ($ServiceArg.Contains('*')) {
145145
continue;
146146
}
147+
148+
# As we can use the DisplayName of a service inside the filter, we need to compare the DisplayName with
149+
# our provided filter as well
150+
[bool]$ServiceKnown = $FALSE;
151+
152+
foreach ($fetchedService in $FetchedServices.Keys) {
153+
$fetchedService = $FetchedServices[$fetchedService];
154+
155+
if ($fetchedService.metadata.DisplayName -eq $ServiceArg) {
156+
$ServiceKnown = $TRUE;
157+
break;
158+
}
159+
}
160+
161+
if ($ServiceKnown) {
162+
continue;
163+
}
164+
147165
$ServicesPackage.AddCheck(
148166
(New-IcingaCheck -Name ([string]::Format('{0}: Service not found', $ServiceArg))).SetUnknown()
149167
);

0 commit comments

Comments
 (0)