Fixes service provider for brackets in service names

This commit is contained in:
Lord Hepipud 2024-08-15 15:05:43 +02:00
parent fad86f9493
commit 0ca3ed5029
4 changed files with 48 additions and 34 deletions

View file

@ -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
* [#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
* [#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

View file

@ -5,13 +5,14 @@ function Get-IcingaServices()
[array]$Exclude = @()
);
$ServiceInformation = Get-Service -Name $Service -ErrorAction SilentlyContinue;
$ServiceInformation = Get-Service;
$ServiceWmiInfo = $null;
if ($Service.Count -eq 0) {
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service;
} else {
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service |
try {
$ServiceWmiInfo = Get-IcingaWindowsInformation Win32_Service |
ForEach-Object {
foreach ($svc in $Service) {
if ($_.Name -Like $svc) {
@ -19,6 +20,11 @@ function Get-IcingaServices()
}
}
} | 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) {
@ -27,7 +33,7 @@ function Get-IcingaServices()
[hashtable]$ServiceData = @{ };
foreach ($service in $ServiceInformation) {
foreach ($si in $ServiceInformation) {
[array]$DependentServices = $null;
[array]$DependingServices = $null;
@ -37,12 +43,12 @@ function Get-IcingaServices()
[int]$StartModeId = 5;
[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;
}
foreach ($wmiService in $ServiceWmiInfo) {
if ($wmiService.Name -eq $service.ServiceName) {
if ($wmiService.Name -eq $si.ServiceName) {
$ServiceUser = $wmiService.StartName;
$ServicePath = $wmiService.PathName;
$ServiceExitCode = $wmiService.ExitCode;
@ -55,7 +61,7 @@ function Get-IcingaServices()
}
#Dependent / Child
foreach ($dependency in $service.DependentServices) {
foreach ($dependency in $si.DependentServices) {
if ($null -eq $DependentServices) {
$DependentServices = @();
}
@ -63,7 +69,7 @@ function Get-IcingaServices()
}
#Depends / Parent
foreach ($dependency in $service.ServicesDependedOn) {
foreach ($dependency in $si.ServicesDependedOn) {
if ($null -eq $DependingServices) {
$DependingServices = @();
}
@ -71,29 +77,29 @@ function Get-IcingaServices()
}
$ServiceData.Add(
$service.Name, @{
$si.Name, @{
'metadata' = @{
'DisplayName' = $service.DisplayName;
'ServiceName' = $service.ServiceName;
'Site' = $service.Site;
'Container' = $service.Container;
'ServiceHandle' = $service.ServiceHandle;
'DisplayName' = $si.DisplayName;
'ServiceName' = $si.ServiceName;
'Site' = $si.Site;
'Container' = $si.Container;
'ServiceHandle' = $si.ServiceHandle;
'Dependent' = $DependentServices;
'Depends' = $DependingServices;
};
'configuration' = @{
'CanPauseAndContinue' = $service.CanPauseAndContinue;
'CanShutdown' = $service.CanShutdown;
'CanStop' = $service.CanStop;
'CanPauseAndContinue' = $si.CanPauseAndContinue;
'CanShutdown' = $si.CanShutdown;
'CanStop' = $si.CanStop;
'Status' = @{
'raw' = [int]$service.Status;
'value' = $service.Status;
'raw' = [int]$si.Status;
'value' = $si.Status;
};
'ServiceType' = @{
'raw' = [int]$service.ServiceType;
'value' = $service.ServiceType;
'raw' = [int]$si.ServiceType;
'value' = $si.ServiceType;
};
'ServiceHandle' = $service.ServiceHandle;
'ServiceHandle' = $si.ServiceHandle;
'StartType' = @{
'raw' = $StartModeId;
'value' = $StartMode;

View file

@ -88,21 +88,27 @@ function Test-IcingaArrayFilter()
return $FilteredArray;
} else {
foreach ($entry in $Exclude) {
if (([string]$InputObject).ToLower() -Like ([string]$entry).ToLower()) {
return $FALSE;
try {
foreach ($entry in $Exclude) {
if (([string]$InputObject).ToLower() -Like ([string]$entry).ToLower()) {
return $FALSE;
}
}
}
if ($Include.Count -eq 0) {
return $TRUE;
}
foreach ($entry in $Include) {
if (([string]$InputObject).ToLower() -Like ([string]$entry).ToLower()) {
$IncludeFound = $TRUE;
break;
if ($Include.Count -eq 0) {
return $TRUE;
}
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;

View file

@ -31,7 +31,8 @@
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.';
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 = @{