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

PropertyDescription
Command typeTransforming
Required permissionNone
License usageN/A
Parallel executionSupported
Distributed executionRuns on Data Node (mapper)

Syntax

matchsig [guid=STR] [name=STR] field=STR [invert=BOOL] [verify=BOOL]

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 either guid or name.
name=STR
Name of the pattern group to use for matching (cannot be used together with guid). You must specify either the guid or name option. 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

FieldTypeRequiredDescription
Field specified by field optionstringRequiredString 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.

FieldTypeDescription
_matchsig_resultarrayList 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 codeMessageDescription
300001Invalid 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.
300002Specify field option in the matchsig command.The field option is missing.
300003Pattern 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.
300052Specify '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.
300053Pattern 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.
300054Duplicate 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.
300055Specify 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 codeMessageDescription
-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

  1. 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=line
    

    Outputs only records where the line field value matches the specified pattern group.

  2. 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=t
    

    Uses the invert=t option to output only records that do not match the pattern group.

  3. 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=uri
    

    Matches using a pattern group specified by name instead of GUID.

Change history

TargetIntroduced in
The matchsig commandBefore Sonar 4.0
The name option4.0.2609.0