Skip to content

This guide shows you how to add enrichment contexts to your package. You’ll learn how to define contexts in the manifest, populate them with data, and test context interactions.

Contexts provide stateful enrichment capabilities. Define them in the contexts section of your package.yaml. The node creates these contexts when you install the package.

package.yaml
contexts:
threat-indicators:
type: lookup-table
description: |
A lookup table keyed by indicator values (hashes, IPs, domains)
for threat intelligence enrichment.
args: {}
disabled: false

Tenzir supports several context types:

TypeDescription
lookup-tableKey-value store for enrichment lookups
geoipGeographic IP address lookups
bloom-filterProbabilistic set membership testing

Each context definition supports:

FieldDescription
typeThe context type (required)
descriptionA user-facing description
argsType-specific arguments for context creation
disabledSet to true to disable the context

Use the context::update operator to populate a context. This typically happens in a pipeline that fetches data from an external source:

pipelines/update-lookup-table.tql
---
name: Update Threat Intel
description: >
Fetches threat indicators hourly and updates the lookup table.
disabled: true
---
every 1h {
from_http "https://feeds.example.com/indicators.json"
}
parse_json
context::update "threat-indicators", key=indicator

The key parameter specifies which field to use as the lookup key. The entire event becomes the value associated with that key.

Use the context::enrich operator to look up values and add context data to events:

subscribe "network-events"
context::enrich "threat-indicators", key=dst_ip
where threat-indicators != null
publish "alerts"

When the lookup succeeds, the context name becomes a field containing the matched data.

Contexts are stateful and require a running node. Use test suites to share a node fixture across sequential tests.

Add a test.yaml file to define the suite:

  • Directorytests/context/
    • test.yaml Suite configuration
    • 01-list.tql
    • 02-update.tql
    • 03-inspect.tql
tests/context/test.yaml
suite: context-tests
fixtures: [node]

The suite runs tests in lexicographic order, sharing the node fixture across all tests.

Number test files to control execution order. The first test verifies that the context exists after package installation:

tests/context/01-list.tql
// Verify the context exists after package installation
context::list
where name == "my-context"

The second test loads data into the context using an inline input file:

tests/context/02-update.tql
// Load data into the context
from_file env("TENZIR_INPUT")
context::update "my-context", key=indicator

The input file provides the test data:

tests/context/02-update.input
{"indicator": "hash123", "severity": "high"}
{"indicator": "hash456", "severity": "low"}

The third test verifies the context contains the expected data:

tests/context/03-inspect.tql
// Verify the context contains expected data
context::inspect "my-context"
sort indicator

Each test can depend on state left by previous tests in the suite.

OptionDescription
suiteSuite name (required to enable suite mode)
fixturesList of fixtures to start (for example, [node])
timeoutCommand timeout in seconds (default: 30)

Last updated: