mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2026-02-16 17:18:04 -05:00
Merge pull request #745 from Icinga:fix/service_checks_not_possible_with_brackets_in_name
Fix: Service provider for brackets in service names Fixes an issue for service provider with service names not interpreted correctly in case it contains `[]`
This commit is contained in:
commit
7dce5547db
4 changed files with 48 additions and 34 deletions
|
|
@ -16,6 +16,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
* [#729](https://github.com/Icinga/icinga-powershell-framework/issues/729) Fixes `Update-Icinga` to print an error in case a component is not installed, instead of silently continue
|
* [#729](https://github.com/Icinga/icinga-powershell-framework/issues/729) Fixes `Update-Icinga` to print an error in case a component is not installed, instead of silently continue
|
||||||
* [#734](https://github.com/Icinga/icinga-powershell-framework/issues/734) Fixes a scenario on which a JEA service could become orphaned while manually stopping the Icinga for Windows service, without gracefully shutting down JEA
|
* [#734](https://github.com/Icinga/icinga-powershell-framework/issues/734) Fixes a scenario on which a JEA service could become orphaned while manually stopping the Icinga for Windows service, without gracefully shutting down JEA
|
||||||
* [#735](https://github.com/Icinga/icinga-powershell-framework/pull/735) Fixes an issue with filter for EventLog events, which did not properly handle multiple event id includes, causing empty results
|
* [#735](https://github.com/Icinga/icinga-powershell-framework/pull/735) Fixes an issue with filter for EventLog events, which did not properly handle multiple event id includes, causing empty results
|
||||||
|
* [#745](https://github.com/Icinga/icinga-powershell-framework/pull/745) Fixes an issue for service provider with service names not interpreted correctly in case it contains `[]`
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,14 @@ function Get-IcingaServices()
|
||||||
[array]$Exclude = @()
|
[array]$Exclude = @()
|
||||||
);
|
);
|
||||||
|
|
||||||
$ServiceInformation = Get-Service -Name $Service -ErrorAction SilentlyContinue;
|
$ServiceInformation = Get-Service;
|
||||||
$ServiceWmiInfo = $null;
|
$ServiceWmiInfo = $null;
|
||||||
|
|
||||||
if ($Service.Count -eq 0) {
|
if ($Service.Count -eq 0) {
|
||||||
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service;
|
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service;
|
||||||
} else {
|
} else {
|
||||||
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service |
|
try {
|
||||||
|
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service |
|
||||||
ForEach-Object {
|
ForEach-Object {
|
||||||
foreach ($svc in $Service) {
|
foreach ($svc in $Service) {
|
||||||
if ($_.Name -Like $svc) {
|
if ($_.Name -Like $svc) {
|
||||||
|
|
@ -19,6 +20,11 @@ function Get-IcingaServices()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} | Select-Object StartName, Name, ExitCode, StartMode, PathName;
|
} | Select-Object StartName, Name, ExitCode, StartMode, PathName;
|
||||||
|
} catch {
|
||||||
|
Exit-IcingaThrowException -InputString $_.Exception.Message -StringPattern 'wildcard' -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.RegexError;
|
||||||
|
Exit-IcingaThrowException -CustomMessage $_.Exception.Message -ExceptionType 'Input' -ExceptionThrown $_.Exception.Message;
|
||||||
|
return $null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($null -eq $ServiceInformation) {
|
if ($null -eq $ServiceInformation) {
|
||||||
|
|
@ -27,7 +33,7 @@ function Get-IcingaServices()
|
||||||
|
|
||||||
[hashtable]$ServiceData = @{ };
|
[hashtable]$ServiceData = @{ };
|
||||||
|
|
||||||
foreach ($service in $ServiceInformation) {
|
foreach ($si in $ServiceInformation) {
|
||||||
|
|
||||||
[array]$DependentServices = $null;
|
[array]$DependentServices = $null;
|
||||||
[array]$DependingServices = $null;
|
[array]$DependingServices = $null;
|
||||||
|
|
@ -37,12 +43,12 @@ function Get-IcingaServices()
|
||||||
[int]$StartModeId = 5;
|
[int]$StartModeId = 5;
|
||||||
[string]$StartMode = 'Unknown';
|
[string]$StartMode = 'Unknown';
|
||||||
|
|
||||||
if ((Test-IcingaArrayFilter -InputObject $Service.ServiceName -Exclude $Exclude) -eq $FALSE) {
|
if ((Test-IcingaArrayFilter -InputObject $si.ServiceName -Include $Service -Exclude $Exclude) -eq $FALSE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($wmiService in $ServiceWmiInfo) {
|
foreach ($wmiService in $ServiceWmiInfo) {
|
||||||
if ($wmiService.Name -eq $service.ServiceName) {
|
if ($wmiService.Name -eq $si.ServiceName) {
|
||||||
$ServiceUser = $wmiService.StartName;
|
$ServiceUser = $wmiService.StartName;
|
||||||
$ServicePath = $wmiService.PathName;
|
$ServicePath = $wmiService.PathName;
|
||||||
$ServiceExitCode = $wmiService.ExitCode;
|
$ServiceExitCode = $wmiService.ExitCode;
|
||||||
|
|
@ -55,7 +61,7 @@ function Get-IcingaServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
#Dependent / Child
|
#Dependent / Child
|
||||||
foreach ($dependency in $service.DependentServices) {
|
foreach ($dependency in $si.DependentServices) {
|
||||||
if ($null -eq $DependentServices) {
|
if ($null -eq $DependentServices) {
|
||||||
$DependentServices = @();
|
$DependentServices = @();
|
||||||
}
|
}
|
||||||
|
|
@ -63,7 +69,7 @@ function Get-IcingaServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
#Depends / Parent
|
#Depends / Parent
|
||||||
foreach ($dependency in $service.ServicesDependedOn) {
|
foreach ($dependency in $si.ServicesDependedOn) {
|
||||||
if ($null -eq $DependingServices) {
|
if ($null -eq $DependingServices) {
|
||||||
$DependingServices = @();
|
$DependingServices = @();
|
||||||
}
|
}
|
||||||
|
|
@ -71,29 +77,29 @@ function Get-IcingaServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
$ServiceData.Add(
|
$ServiceData.Add(
|
||||||
$service.Name, @{
|
$si.Name, @{
|
||||||
'metadata' = @{
|
'metadata' = @{
|
||||||
'DisplayName' = $service.DisplayName;
|
'DisplayName' = $si.DisplayName;
|
||||||
'ServiceName' = $service.ServiceName;
|
'ServiceName' = $si.ServiceName;
|
||||||
'Site' = $service.Site;
|
'Site' = $si.Site;
|
||||||
'Container' = $service.Container;
|
'Container' = $si.Container;
|
||||||
'ServiceHandle' = $service.ServiceHandle;
|
'ServiceHandle' = $si.ServiceHandle;
|
||||||
'Dependent' = $DependentServices;
|
'Dependent' = $DependentServices;
|
||||||
'Depends' = $DependingServices;
|
'Depends' = $DependingServices;
|
||||||
};
|
};
|
||||||
'configuration' = @{
|
'configuration' = @{
|
||||||
'CanPauseAndContinue' = $service.CanPauseAndContinue;
|
'CanPauseAndContinue' = $si.CanPauseAndContinue;
|
||||||
'CanShutdown' = $service.CanShutdown;
|
'CanShutdown' = $si.CanShutdown;
|
||||||
'CanStop' = $service.CanStop;
|
'CanStop' = $si.CanStop;
|
||||||
'Status' = @{
|
'Status' = @{
|
||||||
'raw' = [int]$service.Status;
|
'raw' = [int]$si.Status;
|
||||||
'value' = $service.Status;
|
'value' = $si.Status;
|
||||||
};
|
};
|
||||||
'ServiceType' = @{
|
'ServiceType' = @{
|
||||||
'raw' = [int]$service.ServiceType;
|
'raw' = [int]$si.ServiceType;
|
||||||
'value' = $service.ServiceType;
|
'value' = $si.ServiceType;
|
||||||
};
|
};
|
||||||
'ServiceHandle' = $service.ServiceHandle;
|
'ServiceHandle' = $si.ServiceHandle;
|
||||||
'StartType' = @{
|
'StartType' = @{
|
||||||
'raw' = $StartModeId;
|
'raw' = $StartModeId;
|
||||||
'value' = $StartMode;
|
'value' = $StartMode;
|
||||||
|
|
|
||||||
|
|
@ -88,21 +88,27 @@ function Test-IcingaArrayFilter()
|
||||||
|
|
||||||
return $FilteredArray;
|
return $FilteredArray;
|
||||||
} else {
|
} else {
|
||||||
foreach ($entry in $Exclude) {
|
try {
|
||||||
if (([string]$InputObject).ToLower() -Like ([string]$entry).ToLower()) {
|
foreach ($entry in $Exclude) {
|
||||||
return $FALSE;
|
if (([string]$InputObject).ToLower() -Like ([string]$entry).ToLower()) {
|
||||||
|
return $FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($Include.Count -eq 0) {
|
if ($Include.Count -eq 0) {
|
||||||
return $TRUE;
|
return $TRUE;
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($entry in $Include) {
|
|
||||||
if (([string]$InputObject).ToLower() -Like ([string]$entry).ToLower()) {
|
|
||||||
$IncludeFound = $TRUE;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($entry in $Include) {
|
||||||
|
if (([string]$InputObject).ToLower() -Like ([string]$entry).ToLower()) {
|
||||||
|
$IncludeFound = $TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Exit-IcingaThrowException -InputString $_.Exception.Message -StringPattern 'wildcard' -ExceptionType 'Input' -ExceptionThrown $IcingaExceptions.Inputs.RegexError;
|
||||||
|
Exit-IcingaThrowException -CustomMessage $_.Exception.Message -ExceptionType 'Input' -ExceptionThrown $_.Exception.Message;
|
||||||
|
return $FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $IncludeFound;
|
return $IncludeFound;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@
|
||||||
CimClassNameUnknown = 'The provided class name you try to fetch with Get-CimInstance is not known on this system.';
|
CimClassNameUnknown = 'The provided class name you try to fetch with Get-CimInstance is not known on this system.';
|
||||||
WmiObjectClassUnknown = 'The provided class name you try to fetch with Get-WmiObject is not known on this system.';
|
WmiObjectClassUnknown = 'The provided class name you try to fetch with Get-WmiObject is not known on this system.';
|
||||||
MSSQLCredentialHandling = 'The connection to MSSQL was not possible because your login credential was not correct.';
|
MSSQLCredentialHandling = 'The connection to MSSQL was not possible because your login credential was not correct.';
|
||||||
MSSQLCommandMissing = 'Failed to build a SQL query'
|
MSSQLCommandMissing = 'Failed to build a SQL query';
|
||||||
|
RegexError = 'A request was not handled properly because a provided regex could not be interpreted. Please validate your regex and try again. In case you are trying to access a ressource containing [], you will have to escape each symbol by using `. Example: myservice`[`]';
|
||||||
};
|
};
|
||||||
|
|
||||||
[hashtable]$Configuration = @{
|
[hashtable]$Configuration = @{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue