icinga-powershell-plugins
icinga-powershell-plugins copied to clipboard
Invoke-IcingaCheckService - square brackets in service-name cannot be masked
trafficstars
A service with two square brackets in its non-displayname cannot be found by the check-command. Masking the first bracket with a backtick works, but not for the second one:
- Example
Invoke-IcingaCheckService -Verbosity 2 -Service 'Example [support.example.com]'
[UNKNOWN] Services: 1 Unknown [UNKNOWN] Example [support.example.com]: Service not found (0)
\_ [UNKNOWN] Example [support.example.com]: Service not found: 0
| 'example_supportexamplecom_service_not_found'=;; 'pending_paused_services'=;; 'running_services'=;; 'pending_continued_services'=;; 'stopped_services'=;; 'pending_started_services'=;; 'service_count'=;; 'pending_stopped_services'=;; 'paused_services'=;;
3
- Example
Invoke-IcingaCheckService -Verbosity 2 -Service 'Example `[support.example.com`]'
[UNKNOWN] Services: 1 Unknown [UNKNOWN] Example `[support.example.com`]: Service not found (0)
\_ [UNKNOWN] Example `[support.example.com`]: Service not found: 0
| 'example_supportexamplecom_service_not_found'=;; 'pending_paused_services'=;; 'running_services'=;; 'pending_continued_services'=;; 'stopped_services'=;; 'pending_started_services'=;; 'service_count'=;; 'pending_stopped_services'=;; 'paused_services'=;;
3
- Example
Invoke-IcingaCheckService -Verbosity 2 -Service 'Example `[support.example.com]'
[UNKNOWN] Services: 1 Unknown 1 Ok [UNKNOWN] Example `[support.example.com]: Service not found (0)
\_ [UNKNOWN] Example `[support.example.com]: Service not found: 0
\_ [OK] Service "Example [support.example.com] (Example [support.example.com])": Running
| 'service_example_supportexamplecom_example_supportexamplecom'=4;;4 'pending_paused_services'=0;; 'running_services'=0;; 'pending_continued_services'=0;; 'stopped_services'=0;; 'pending_started_services'=0;; 'service_count'=1;; 'pending_stopped_services'=0;; 'paused_services'=0;; 'example_supportexamplecom_service_not_found'=;;
3
- Example
Invoke-IcingaCheckService -Verbosity 2 -Service 'Example `[support.example.com*'
[OK] Services: 1 Ok
\_ [OK] Service "Example [support.example.com] (Example [support.example.com])": Running
| 'pending_paused_services'=0;; 'running_services'=0;; 'pending_continued_services'=0;; 'stopped_services'=0;; 'pending_started_services'=0;; 'service_count'=1;; 'pending_stopped_services'=0;; 'paused_services'=0;; 'service_example_supportexamplecom_example_supportexamplecom'=4;;4
0
It seems to be an issue of the underlying cmdlet "Get-Service" used by the check which shows the following output for the test-cases: 1.
Get-Service -Name 'Example [support.example.com]'
=> no result/output
Get-Service -Name 'Example `[support.example.com`]'
Get-Service : Cannot find any service with service name 'Example `[support.example.com`]'.
At line:1 char:1
+ Get-Service -Name 'Example `[support.example.com`]'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Example `[support.example.com`]:String) [Get-Service], ServiceCom
mandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand
Get-Service -Name 'Example `[support.example.com]'
Status Name DisplayName
------ ---- -----------
Running Example... Example...
Get-Service -Name 'Example `[support.example.com*'
Status Name DisplayName
------ ---- -----------
Running Example... Example...
Please don't blame me for this dumb naming of a service - it is a commercial product :-( Any hints for a correct masking are appreciated.