Match Event Fields Against Patterns in Lookup Table Values

Compare event fields with column values containing patterns in a lookup table using the match() function with glob pattern matching

Query

logscale
id =~ match(file="users.csv", column=userid, mode=glob, ignoreCase=true)

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 with glob pattern matching (defined by the mode parameter) to match event IDs against the column userid of the users.csv file, adding the matching user details to the events.

Example incoming event data might look like this:

@timestampidactionsource_ip
2024-01-15T09:00:00.000ZADMIN-123login10.0.0.1
2024-01-15T09:01:00.000Zdev-user-456code_push10.0.0.2
2024-01-15T09:02:00.000ZTEST_789test_run10.0.0.3
2024-01-15T09:03:00.000Zsupport-001ticket_update10.0.0.4
2024-01-15T09:04:00.000Zunknown-userlogin_attempt10.0.0.5

Example users.csv file data might look like this:

useriddepartmentaccess_levellocationtitle
ADMIN-*ITadministratorHQSystem Administrator
dev-user-*EngineeringdeveloperRemoteSoftware Engineer
TEST_*QAtesterLabQA Engineer
support-*SupportagentOfficeSupport Specialist

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
    id =~ match(file="users.csv", column=userid, mode=glob, ignoreCase=true)

    Uses glob pattern matching to match the userid column of the users.csv lookup table file against the IDs in the events. When an event ID matches a pattern in users.csv, all (non-pattern) columns from that first matching row are added to the event. The column names become new field names.

    Pattern matching examples based on the input data and lookup file are:

    ADMIN-123 matches ADMIN-*

    dev-user-456 matches dev-user-*

    TEST_789 matches TEST_*

    support-001 matches support-*

  3. Event Result set.

Summary and Results

The query is used to match event IDs against patterns in a user list, and then add the matching user details (other columns from the row in the users.csv file) to the events.

Pattern-based matching with field enrichment is, for example, useful in case you want to add user context to authentication logs.

Sample output from the incoming example data:

@timestampidactionsource_ipdepartmentaccess_levellocationtitle
2024-01-15T09:00:00.000ZADMIN-123login10.0.0.1ITadministratorHQSystem Administrator
2024-01-15T09:01:00.000Zdev-user-456code_push10.0.0.2EngineeringdeveloperRemoteSoftware Engineer
2024-01-15T09:02:00.000ZTEST_789test_run10.0.0.3QAtesterLabQA Engineer
2024-01-15T09:03:00.000Zsupport-001ticket_update10.0.0.4SupportagentOfficeSupport Specialist

After matching, the output combines original event fields with matched user details. Only events with matching patterns appear in output.