Skip to content

Convert-IcingaPluginThresholds - doeing weird things with some strings #503

Closed
@stevie-sy

Description

@stevie-sy

While writing own checks I figured out that the function "Convert-IcingaPluginThresholds" doing weird things with some string. But this is more a thing from PowerShell than from the Framework. Because in my opinion e.g. this line is the root cause:

} elseif (($ThresholdValue -Match "(^[\d\.]*) ?(ms|s|m|h|d|w|M|y)")) {

This Regex-Test with "Server-001" or "ServerMS-001" returns always true. The reason I don't understand, because the regex looks fine to me. As well regex101.com returns "no match".

Even though the "s" is at the beginning of the first test string and "ms" is in the middle of the second test string, is the regex check with "-match" returns true. But it shouldn't. And as a result the block will be proceed and the String value with included numbers will be converted in a strange result. In further consequence the check write some weird check output.

Test example:

$output = "Serverms-001"
$Package = New-IcingaCheckPackage -Name 'Test' -OperatorAnd -IgnoreEmptyPackage -Verbose $Verbosity    
$icingaCheck = New-IcingaCheck -Name "Output" -Value $output     
$Package.AddCheck($icingaCheck) 
return (New-IcingaCheckResult -Check $ExternalCLIPackage -NoPerfData $NoPerfData -Compile);

Returns:

[OK] Test
\_ [OK] Output: -1ms
| 'output'=-0.001s;; 
0

Tested with:
W2012R2 - PS 4.0
W2016 - PS 5.1.14393.4583
W2019 - PS 5.1.17763.2268
W2022 - PS 5.1.20348.558

image

As you can see, sometimes only a unit is returned and sometimes the value gets converted.

I have no idea how to fix it or write a work arround

Metadata

Metadata

Assignees

Labels

BugThere is an issue present

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions