Merge pull request #846 from Icinga:fix/match_and_notmatch_checks_fail_on_special_characters

Fix: Plugin error for match and not match with special characters

Fixes plugin execution error while using any `%IfNotMatch`/`%IfNotLike`/`%IfMatch`/`%IfLike` check function for strings containing special characters like `:`
This commit is contained in:
Lord Hepipud 2025-12-30 16:15:57 +01:00 committed by GitHub
commit 326d1fe3e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 19 deletions

View file

@ -13,6 +13,10 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Bugfixes
* [#814](https://github.com/Icinga/icinga-powershell-framework/pull/814) Fixes random chars function to truly generate unpredictable character sequences and to replace `Get-Random` which is not entirely secure
* [#815](https://github.com/Icinga/icinga-powershell-framework/pull/815) Fixes a possible crash for `Test-IcingaAddTypeExist`, causing the Icinga for Windows installation to fail when third party components are checked which are malfunctioning
* [#816](https://github.com/Icinga/icinga-powershell-framework/issues/816) Fixes plugin execution error while using any `%IfNotMatch`/`%IfNotLike`/`%IfMatch`/`%IfLike` check function for strings containing special characters like `:`
* [#829](https://github.com/Icinga/icinga-powershell-framework/pull/829) Fixes `Set-IcingaCacheData` to properly remove cache files in case `$null` is passed as value
* [#833](https://github.com/Icinga/icinga-powershell-framework/issues/833) Fixes registry lookup for Icinga Agent installation to check if the required `DisplayName` attribute is defined before checking
* [#834](https://github.com/Icinga/icinga-powershell-framework/issues/834) Fixes security catalog compilation error on non-english Windows versions, while properly skipping checks on system SID's and improves security by always adding the `SeDenyNetworkLogonRight` and `SeDenyInteractiveLogonRight` privilege section for the JEA user SID
* [#835](https://github.com/Icinga/icinga-powershell-framework/pull/835) Fixes JEA compiler to always enforce a rebuild of the Framework to ensure integrity of JEA profiles
@ -25,16 +29,6 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#838](https://github.com/Icinga/icinga-powershell-framework/pull/838) Enhances Icinga for Windows to never load and user PowerShell profiles
* [#841](https://github.com/Icinga/icinga-powershell-framework/pull/841) Adds new [INFO] state for notice and un-checked monitoring objects
## 1.13.4 (tbd)
[Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/42)
### Bugfixes
* [#814](https://github.com/Icinga/icinga-powershell-framework/pull/814) Fixes random chars function to truly generate unpredictable character sequences and to replace `Get-Random` which is not entirely secure
* [#815](https://github.com/Icinga/icinga-powershell-framework/pull/815) Fixes a possible crash for `Test-IcingaAddTypeExist`, causing the Icinga for Windows installation to fail when third party components are checked which are malfunctioning
* [#829](https://github.com/Icinga/icinga-powershell-framework/pull/829) Fixes `Set-IcingaCacheData` to properly remove cache files in case `$null` is passed as value
## 1.13.3 (2025-05-08)
[Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/39)

View file

@ -28,6 +28,12 @@
.FUNCTIONALITY
Converts values with units to the lowest unit of this category.
Accepts Icinga Thresholds.
.PARAMETER Threshold
The threshold value to convert. Supports Icinga plugin threshold
syntax.
.PARAMETER RawValue
If set, the function will return the raw value without any conversion.
This is required for match/not match checks as example
.EXAMPLE
PS>Convert-IcingaPluginThresholds -Threshold '20d';
@ -128,7 +134,8 @@
function Convert-IcingaPluginThresholds()
{
param (
[string]$Threshold = $null
[string]$Threshold = $null,
[switch]$RawValue = $false
);
[hashtable]$RetValue = @{
@ -142,7 +149,10 @@ function Convert-IcingaPluginThresholds()
'IsDateTime' = $FALSE;
};
if ([string]::IsNullOrEmpty($Threshold)) {
# Always ensure Value is set, because we just want the raw value
if ([string]::IsNullOrEmpty($Threshold) -or $RawValue) {
$RetValue.Value = $Threshold;
return $RetValue;
}

View file

@ -21,7 +21,7 @@ function Get-IcingaRandomChars()
# Generate random bytes
$CryptoProvider.GetBytes($ByteValue);
$RandomNumber = [BitConverter]::ToUInt32($ByteValue, 0);
# Ensure the random number is within the valid range to avoid maximum security
# Ensure the random number is within the valid range to ensure maximum security
} while ($RandomNumber -ge $maxValid);
# Calculate the index for the symbol array

View file

@ -103,13 +103,20 @@ function Compare-IcingaPluginThresholds()
try {
# Fix possible numeric value comparison issues
$TestInput = Test-IcingaDecimal $InputValue;
$BaseInput = Test-IcingaDecimal $BaseValue;
$MoTData = @{
[bool]$RawValue = $false;
$TestInput = Test-IcingaDecimal $InputValue;
$BaseInput = Test-IcingaDecimal $BaseValue;
$MoTData = @{
'Label' = $PerfDataLabel;
'Interval' = $TimeInterval;
};
# Ensure we never do threshold conversions for match/not match checks
# This ensures that string values are properly compared to each other
if ($Matches -or $NotMatches) {
$RawValue = $true;
}
# Ensure we do not include our checks for which we do not write any performance data
# Metrics over time will not work for those, as the metrics are not stored.
# There just set the variable to null which means they won't be processed
@ -130,9 +137,9 @@ function Compare-IcingaPluginThresholds()
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Message' -Value '';
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'IsOK' -Value $FALSE;
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'HasError' -Value $FALSE;
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Threshold' -Value (Convert-IcingaPluginThresholds -Threshold $Threshold);
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Minimum' -Value (Convert-IcingaPluginThresholds -Threshold $Minium);
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Maximum' -Value (Convert-IcingaPluginThresholds -Threshold $Maximum);
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Threshold' -Value (Convert-IcingaPluginThresholds -Threshold $Threshold -RawValue:$RawValue);
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Minimum' -Value (Convert-IcingaPluginThresholds -Threshold $Minium -RawValue:$RawValue);
$IcingaThresholds | Add-Member -MemberType NoteProperty -Name 'Maximum' -Value (Convert-IcingaPluginThresholds -Threshold $Maximum -RawValue:$RawValue);
if ($TestInput.Decimal) {
$ConvertedValue = Convert-IcingaPluginThresholds -Threshold ([string]::Format('{0}{1}', $InputValue, $Unit));