Match Event Fields Against Lookup Table Values Adding Specific Columns

Compare event IP fields with CIDR ranges in lookup table using the match() function with mode parameter

Query

logscale
match(file="cidr-file.csv", column="cidr-block", field=ip, mode=cidr, include=["info","type"])

Introduction

The match() function is useful for comparing or combining data from multiple sources. The match() function allows searching and enriching data using CSV or JSON files, working as a filter or join operation in queries.

In this example, the match() function is used to match event IP addresses against the column cidr-block of the cidr-file.csv file, adding specific columns details to the events.

The query matches IP addresses against CIDR blocks (CIDR subnets) and adds specific network information from the columns info and type to the output rows.

Example incoming event data might look like this:

@timestampipaction
2024-01-15T09:00:00.000Z10.0.1.25login
2024-01-15T09:01:00.000Z192.168.1.100connect
2024-01-15T09:02:00.000Z172.16.5.12access

Example cidr-file.csv file data might look like this:

cidr-blockinfotypelocationdepartment
10.0.1.0/24Internal NetworkcorporateHQIT
192.168.1.0/24Development NetworktestLabEngineering
172.16.0.0/16Production NetworkcriticalDCOperations

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[\Add Field/] result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    match(file="cidr-file.csv", column="cidr-block", field=ip, mode=cidr, include=["info","type"])

    Uses CIDR ranges matching to match the cidr-block column of the cidr-file.csv lookup table file against the IP addresses (ip field) in the events, and adds specific network information to the output rows.

    It will only add the specified columns of the matching row. The column names become new field names.

    Note that when the mode parameter is set to cidr, then the event is matched if the field contains an IP address within the CIDR subnet. If multiple subnets match, the most specific one is selected, or an arbitrary one, if there are multiple equally specific subnets.

  3. Event Result set.

Summary and Results

The query is used to match IP addresses against CIDR blocks and add specific network information from the columns info and type to the output rows.

The query helps analyze network traffic and security events by mapping IP addresses to network segments.

Sample output from the incoming example data:

@timestampipactioninfotype
2024-01-15T09:00:00.000Z10.0.1.25loginInternal Networkcorporate
2024-01-15T09:01:00.000Z192.168.1.100connectDevelopment Networktest
2024-01-15T09:02:00.000Z172.16.5.12accessProduction Networkcritical

Note how only the specified fields from the cidr-file.csv file appear in output.