matchnet

Checks whether the IP address field value of input records is included in the specified subnet group, and filters matching records.

Command properties

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

Syntax

matchnet [guid=STR] [name=STR] [field=FIELD] [fields=FIELD, ...] [invert=BOOL] [verify=BOOL] [tag=BOOL]

In the syntax above, name is available starting with 4.0.2609.0.

Options

guid=STR
GUID of the subnet group to match against. 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 subnet group to match against (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=FIELD
Name of the IP address field to match. You must specify either the field or fields option.
fields=FIELD, ...
List of IP address field names to match, separated by commas (,). If specified together with field, both sets of fields are used. You must specify either the field or fields option.
invert=BOOL
Whether to invert the match result. (Default: f)
  • t: Outputs records not included in the subnet group.
  • f: Outputs records included in the subnet group.
verify=BOOL
Whether to verify that the subnet group exists. (Default: t)
  • t: Verifies that the subnet group exists at parse time.
  • f: Skips subnet group validation.
tag=BOOL
Whether to output matched subnet information. (Default: f)
  • t: Assigns matched subnet information as a map to the _matchnet_result field.
  • f: Does not output subnet information.

Input fields

FieldTypeRequiredDescription
Field specified by field or fieldsstring, IP address, or integerRequiredIPv4 address to match. If multiple fields are specified, they are checked in the order specified. With invert=f (default), the record is output immediately once a matching field is found, without checking the remaining fields. With invert=t, the record is output immediately once a non-matching field is found, without checking the remaining fields — that is, the record is excluded from the result only if every field is included in the subnet group. If a value is null or of an unsupported type, that field is skipped and the next field is checked. IPv6 address strings are treated as non-matching.

Output fields

When tag=t is specified, the output record includes subnet_field, subnet_value, and subnet_invert, and _matchnet_result is added only when the record matches a subnet.

FieldTypeDescription
_matchnet_resultobjectMatched subnet information. Contains id, start_ip, end_ip, cidr, and description keys.
subnet_fieldstringName of the field on which the match was determined (one of the fields specified by field or fields)
subnet_valuestring, IP address, or integerOriginal value of the field on which the match was determined (retains the input field's original type)
subnet_invertbooleanValue of the invert option

Keys in the _matchnet_result map:

KeyTypeDescription
idintegerSubnet entry ID
start_ipstringStart IP address of the subnet
end_ipstringEnd IP address of the subnet
cidrintegerCIDR prefix length
descriptionstringSubnet description (only when configured)

Error codes

Parse errors
Error codeMessageDescription
300025Specify 'guid' option in the matchnet command.The guid option is not specified. The error code differs by series — the 5.0 series (through 5.0.2605.2) reports 300025; the 4.0 series (4.0.2609.0 and later) reports 300040 instead.
300026Specify 'field' option in the matchnet command.Neither the field nor the fields option was specified.
300027The GUID in the matchnet command is invalid format.The guid option value is not a valid GUID format.
300028Subnet group not found.No subnet group exists for the specified guid (validated only when verify=t).
300029Cannot load subnet group.An error occurred while loading subnet group data.
300040Specify 'guid' or 'name' option in the matchnet command.Neither the guid nor the name option is specified. Available starting with 4.0.2609.0, which has the name option.
300041Subnet group not found by name.No subnet group exists with the name specified in the name option. Available starting with 4.0.2609.0, which has the name option.
300042Duplicate subnet group name.More than one subnet group exists with the name specified in the name option. Available starting with 4.0.2609.0, which has the name option.
300046Specify only one of 'guid' or 'name' option in the matchnet command.Both the guid and name options are specified. Available starting with 4.0.2609.0, which has the name option.
Runtime errors

None

Description

The matchnet command checks whether the IP address value of the field specified by the field or fields option is included in the subnets defined in the subnet group. Only IPv4 addresses are supported. If the field value is null, an IPv6 address, or an unsupported type, the record is treated as non-matching.

Use the guid option to specify the subnet group to match against. 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.

When tag=t is specified, detailed information about the matched subnet (start IP, end IP, CIDR, description) is assigned as a map to the _matchnet_result field.

When invert=t is specified, only records not included in the subnet group are output. When multiple fields are specified, invert=f (default) determines the output as soon as it finds a matching field, but invert=t conversely determines the output as soon as it finds a non-matching field — meaning a record is excluded from the result only if every field is included in the subnet group.

When verify=f is specified, the existence of the subnet group is not verified at parse time. Use this when the subnet group is synchronized later in a real-time stream query.

If the subnet group is updated during execution, the new subnet information is automatically reflected. In a distributed environment, filtering runs on the Data Node.

Examples

  1. Filter records included in a subnet group

    json "[{'src_ip': '192.0.2.1'}, {'src_ip': '198.51.100.5'}, {'src_ip': '203.0.113.10'}]"
    | matchnet guid=550e8400-e29b-41d4-a716-446655440000 field=src_ip
    

    Outputs only records where the src_ip field value is included in the specified subnet group.

  2. Filter records not included in a subnet group

    json "[{'src_ip': '192.0.2.1'}, {'src_ip': '198.51.100.5'}]"
    | matchnet guid=550e8400-e29b-41d4-a716-446655440000 field=src_ip invert=t
    

    Outputs only records where the src_ip field value is not included in the subnet group.

  3. Include matched subnet information

    json "[{'src_ip': '192.0.2.1'}, {'src_ip': '198.51.100.5'}]"
    | matchnet guid=550e8400-e29b-41d4-a716-446655440000 field=src_ip tag=t
    

    Adds a _matchnet_result field to matching records, outputting the start IP, end IP, CIDR, and description of the matched subnet as a map.

  4. Skip subnet group validation

    json "[{'src_ip': '192.0.2.1'}]"
    | matchnet guid=550e8400-e29b-41d4-a716-446655440000 field=src_ip verify=f
    

    Runs without verifying the existence of the subnet group at parse time.

  5. Specifying a subnet group by name (4.0 series, 4.0.2609.0 and later)

    table limit=1000 WEB_APACHE_SAMPLE
    | matchnet name=internal_subnets field=src_ip
    

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

Change history

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