matchsig
Checks whether the string value of a field is included in the specified pattern group, and filters records based on the match result.
Command properties
| Property | Description |
|---|---|
| Command type | Transforming |
| Required permission | None |
| License usage | N/A |
| Parallel execution | Supported |
| Distributed execution | Runs on Data Node (mapper) |
Syntax
In the syntax above, name is available starting with 4.0.2609.0.
Options
guid=STR- GUID of the pattern group to use for matching. In the 5.0 series (through 5.0.2605.2), this is the only way to specify the target. In the 4.0 series (4.0.2609.0 and later), this option cannot be used together with
name, and you must specify eitherguidorname. name=STR- Name of the pattern group to use for matching (cannot be used together with
guid). You must specify either theguidornameoption. This option is available starting with 4.0.2609.0. field=STR- Name of the string field to match against the pattern group.
invert=BOOL- When set to
t, outputs only records that do not match the pattern group. (Default:f) verify=BOOL- When set to
f, skips pattern group validation at the parse stage. (Default:t)
Input fields
| Field | Type | Required | Description |
|---|---|---|---|
Field specified by field option | string | Required | String to match against the pattern. If the value is null, the record is treated as non-matching. |
Output fields
The fields of the input record are passed through unchanged. The following field is added to records where the pattern matches.
| Field | Type | Description |
|---|---|---|
_matchsig_result | array | List of matched patterns. Each element is an object containing the rule, expr, and expr2 values of a matched pattern. |
If invert=t is specified, the output records are the non-matching ones, so this field is not added.
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 300001 | Invalid GUID. | The guid option value is not in a valid GUID format. This code is also reported when the guid option is not specified. The error code for a missing guid differs by series — the 5.0 series (through 5.0.2605.2) reports 300001; the 4.0 series (4.0.2609.0 and later) splits this case out into 300052 instead. |
| 300002 | Specify field option in the matchsig command. | The field option is missing. |
| 300003 | Pattern group not found. | An error occurred while looking up the pattern group by the name option, which is available only in 4.0.2609.0 and later). A pattern group not found by guid is not reported with this code at parse time, even when verify=t. |
| 300052 | Specify 'guid' or 'name' option in the matchsig command. | Neither the guid nor the name option is specified. Available starting with 4.0.2609.0, which has the name option. |
| 300053 | Pattern group not found by name. | No pattern group exists with the name specified in the name option. Available starting with 4.0.2609.0, which has the name option. |
| 300054 | Duplicate pattern group name. | More than one pattern group exists with the name specified in the name option. Available starting with 4.0.2609.0, which has the name option. |
| 300055 | Specify only one of 'guid' or 'name' option in the matchsig command. | Both the guid and name options are specified. Available starting with 4.0.2609.0, which has the name option. |
Runtime errors
| Error code | Message | Description |
|---|---|---|
| - | pattern group not found: <guid> | Occurs when the pattern group for the specified GUID cannot be found at the start of execution (no formal error code). This can also occur when verify=f skips the check at the parse stage. |
Description
The matchsig command checks whether the string value of the specified field in input records matches the patterns defined in the pattern group. Only matching records are output. When invert=t is specified, only non-matching records are output.
Use the guid option to specify the pattern group to use for matching. In the 4.0 series (4.0.2609.0 and later), you can also use the name option; the command looks up the group by that name to resolve its GUID, and specifying both guid and name, or omitting both, causes an error, as does specifying a name that does not exist or that matches more than one group.
If the field value is null, the record is treated as non-matching. Non-null values are converted to strings before pattern matching.
In a distributed environment, filtering runs on the Data Node.
Examples
-
Filter using a pattern group
json "[{'line': 'GET /login HTTP/1.1'}, {'line': 'POST /api/data HTTP/1.1'}, {'line': 'hello world'}]" | matchsig guid=550e8400-e29b-41d4-a716-446655440000 field=lineOutputs only records where the
linefield value matches the specified pattern group. -
Extract records not matching a pattern group
json "[{'line': 'GET /login HTTP/1.1'}, {'line': 'POST /api/data HTTP/1.1'}, {'line': 'hello world'}]" | matchsig guid=550e8400-e29b-41d4-a716-446655440000 field=line invert=tUses the
invert=toption to output only records that do not match the pattern group. -
Specifying a pattern group by name (4.0 series, 4.0.2609.0 and later)
table limit=1000 WEB_APACHE_SAMPLE | matchsig name=sql_injection field=uriMatches using a pattern group specified by name instead of GUID.
Change history
| Target | Introduced in |
|---|---|
The matchsig command | Before Sonar 4.0 |
The name option | 4.0.2609.0 |