matchnet
Checks whether the IP address field value of input records is included in the specified subnet group, and filters matching records.
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 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 eitherguidorname. name=STR- Name of the subnet group to match against (cannot be used together with
guid). You must specify either theguidornameoption. 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
fieldorfieldsoption. fields=FIELD, ...- List of IP address field names to match, separated by commas (
,). If specified together withfield, both sets of fields are used. You must specify either thefieldorfieldsoption. 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_resultfield.f: Does not output subnet information.
Input fields
| Field | Type | Required | Description |
|---|---|---|---|
Field specified by field or fields | string, IP address, or integer | Required | IPv4 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.
| Field | Type | Description |
|---|---|---|
_matchnet_result | object | Matched subnet information. Contains id, start_ip, end_ip, cidr, and description keys. |
subnet_field | string | Name of the field on which the match was determined (one of the fields specified by field or fields) |
subnet_value | string, IP address, or integer | Original value of the field on which the match was determined (retains the input field's original type) |
subnet_invert | boolean | Value of the invert option |
Keys in the _matchnet_result map:
| Key | Type | Description |
|---|---|---|
id | integer | Subnet entry ID |
start_ip | string | Start IP address of the subnet |
end_ip | string | End IP address of the subnet |
cidr | integer | CIDR prefix length |
description | string | Subnet description (only when configured) |
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 300025 | Specify '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. |
| 300026 | Specify 'field' option in the matchnet command. | Neither the field nor the fields option was specified. |
| 300027 | The GUID in the matchnet command is invalid format. | The guid option value is not a valid GUID format. |
| 300028 | Subnet group not found. | No subnet group exists for the specified guid (validated only when verify=t). |
| 300029 | Cannot load subnet group. | An error occurred while loading subnet group data. |
| 300040 | Specify '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. |
| 300041 | Subnet 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. |
| 300042 | Duplicate 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. |
| 300046 | Specify 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
-
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_ipOutputs only records where the
src_ipfield value is included in the specified subnet group. -
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=tOutputs only records where the
src_ipfield value is not included in the subnet group. -
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=tAdds a
_matchnet_resultfield to matching records, outputting the start IP, end IP, CIDR, and description of the matched subnet as a map. -
Skip subnet group validation
json "[{'src_ip': '192.0.2.1'}]" | matchnet guid=550e8400-e29b-41d4-a716-446655440000 field=src_ip verify=fRuns without verifying the existence of the subnet group at parse time.
-
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_ipMatches using a subnet group specified by name instead of GUID.
Change history
| Target | Introduced in |
|---|---|
The matchnet command | Before Sonar 4.0 |
The name option | 4.0.2609.0 |