Quote from: tomaskir on September 12, 2019, 02:36:19 AMQuote from: Tursiops on September 12, 2019, 02:16:29 AM
Just a practical note on this one:Quote1. We have switched from TRE to PCRE as regular expression engine. In most cases this should go unnoticed, but in certain cases regular expressions may stop working or produce unexpected results.
A side effect of this change is that if you are matching a regular expression, even without a capture group, $1, $2, etc. will be reset to null values.
An transform script example of where that might cause an issue:Code Selectif ( $1 ~= "^Hello\s+World" ) {
return $1;
} else {
return "Something Else";
}
In prior versions of NetXMS, if the DCI returned "Hello World", the transform script would have returned exactly that.
With version 3, the transform script will return null.
You will need to change your script to something like this:Code Selectvalue = $1;
if ( value ~= "^Hello\s+World" ) {
return value;
} else {
return "Something Else";
}
Is this a known and expected change or a bug?
This will break A LOT of my NXSL scripts...
That's complicated issue. Current implementation is a bit messy with $n variables after matching. Consider the following code:
Code Select
v = "error 43";
if (v ~= "(error|warning) ([0-9]+)")
println("Step 1: $1=".$1." $2=".$2);
if (v ~= "(error .*|info ([0-9]+))")
println("Step 2: $1=".$1." $2=".$2);
In NetXMS 2.2 $2 will be equal "43" on step 2, which is kind of misleading. It was because implementation in 2.2 silently skipping unmatched capture groups. Implementation in 3.0 resets all unused $n variables, which has side effect of clearing $1 if there were no capture groups at all. Looks like it was bad decision to use same names for capture groups and script arguments.
I want to gradually clean up inconsistencies in NXSL, and that could lead to break up of some things. I think that for now I can introduce server configuration variable (off by default) that will prevent resetting of unused capture group variables. Also I will introduce separated naming for script arguments and capture groups so scripts could be migrated over time to non-overlapping variable naming. Also for transformation scripts I think it is worth passing raw value not only as first argument to the script but also as global variable, like $rawValue.
Best regards,
Victor
Ну и конечно всегда можно сделать пожертвование через PayPal на