matchblackip
Compares IP address field values of input records against a specified address group (IP blocklist) and filters records that match.
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 address group to compare 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 address group to compare against (cannot be used together with
guid). You must specify either theguidornameoption. This option is available starting with 4.0.2609.0. fields=FIELD, ...- List of IP address field names to compare. Separate multiple fields with commas (
,). invert=BOOL- Whether to invert the comparison result. (Default:
f)
t: Outputs records not included in the address groupf: Outputs records included in the address group
verify=BOOL- Whether to validate the existence of the address group. (Default:
t)
t: Validates that the address group exists at parse timef: Skips address group validation
Input fields
| Field | Type | Required | Description |
|---|---|---|---|
Value specified by fields | string or IP address | Required | IP address to compare. Must be a string or InetAddress type; null values or other types are skipped. |
Output fields
When invert=f (default), the following fields are appended to records that match the address group:
| Field | Type | Description |
|---|---|---|
| blackip_guid | string | GUID of the matched address group |
| blackip_name | string | Name of the matched address group |
| blackip_reason | string | Description of the matched IP address |
| blackip_invert | boolean | Value of the invert option (false) |
| blackip_field | string | Name of the field where the match was found |
When invert=t, the following fields are appended to records that do not match the address group:
| Field | Type | Description |
|---|---|---|
| blackip_guid | string | GUID of the address group |
| blackip_name | string | Name of the address group |
| blackip_invert | boolean | Value of the invert option (true) |
Error codes
Parse errors
| Error code | Message | Description |
|---|---|---|
| 300034 | Specify 'guid' option in the matchblackip command. | The guid option is not specified. The error code differs by series — the 5.0 series (through 5.0.2605.2) reports 300034; the 4.0 series (4.0.2609.0 and later) reports 300048 instead. |
| 300035 | The GUID in the matchblackip command is invalid format. | The guid option value is not a valid GUID. |
| 300036 | Specify 'fields' option in the matchblackip command. | The fields option was not specified. |
| 300037 | IP blacklist not found. | No address group exists for the specified GUID (validated only when verify=t). |
| 300048 | Specify 'guid' or 'name' option in the matchblackip command. | Neither the guid nor the name option is specified. Available starting with 4.0.2609.0, which has the name option. |
| 300049 | Address group not found by name. | No address group exists with the name specified in the name option. Available starting with 4.0.2609.0, which has the name option. |
| 300050 | Duplicate address group name. | More than one address group exists with the name specified in the name option. Available starting with 4.0.2609.0, which has the name option. |
| 300051 | Specify only one of 'guid' or 'name' option in the matchblackip 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 matchblackip command compares IP address values from the fields specified by the fields option against an address group. When multiple fields are specified in fields, they are checked in order; when a match is found in the first matching field, the record is immediately output and the remaining fields are not checked.
Use the guid option to specify the address group to compare 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.
If a field value is null or is not a string or InetAddress type, that field is skipped. If no match is found across all fields, the record is discarded.
When invert=t is specified, only records with no match across all fields are output.
When verify=f is specified, the existence of the address group is not validated at parse time. Use this option in real-time stream queries where the address group is synchronized at a later time.
In distributed environments, filtering runs on Data Nodes.
Examples
-
Filter records that match the address group
json "[{'src_ip': '192.0.2.1'}, {'src_ip': '192.0.2.2'}, {'src_ip': '198.51.100.5'}]" | matchblackip guid=550e8400-e29b-41d4-a716-446655440000 fields=src_ipOutputs only records where the
src_ipfield matches the specified address group. -
Specify multiple fields to compare
json "[{'src_ip': '192.0.2.1', 'dst_ip': '198.51.100.10'}]" | matchblackip guid=550e8400-e29b-41d4-a716-446655440000 fields=src_ip,dst_ipCompares
src_ipanddst_ipfields in order; outputs the record if either matches the address group. -
Filter records not in the address group
json "[{'src_ip': '192.0.2.1'}, {'src_ip': '203.0.113.50'}]" | matchblackip guid=550e8400-e29b-41d4-a716-446655440000 fields=src_ip invert=tOutputs only records where the
src_ipfield is not included in the address group. -
Skip address group validation
json "[{'src_ip': '192.0.2.1'}]" | matchblackip guid=550e8400-e29b-41d4-a716-446655440000 fields=src_ip verify=fRuns without validating the existence of the address group at parse time.
-
Specifying an address group by name (4.0 series, 4.0.2609.0 and later)
table limit=1000 WEB_APACHE_SAMPLE | matchblackip name=known_attackers fields=src_ipCompares using an address group specified by name instead of GUID.
Change history
| Target | Introduced in |
|---|---|
The matchblackip command | Before Sonar 4.0 |
The name option | 4.0.2609.0 |