Skip to content

Pipelines

Pipelines run library components together in the same order as the service.

Main pipeline [Code]

The main pipeline functions like a standard inference pipeline. To initialize the entire system, the user only needs to provide either a configuration dictionary or the configuration classes themselves. Since the pipeline inherits from CoreComponent, all CoreComponent methods are also available in the pipeline class.

If do_parsing=False, the pipeline will take already-parsed logs as input, and the parsing step will be skipped. Likewise, if do_aggregation=False, the pipeline will output the detectors’ alerts directly, and the alert aggregation step will be skipped.

Configure each pipeline component with a configuration object or a dictionary. The detector list can contain both forms.

Example 1

Run a pipeline with only one log source.

One source example
from detectmatelibrary.alert_aggregation.logid_count import LogIDCountAggegationConfig

from detectmatelibrary.parsers.tree_matcher import TemplateCppTreeMatcherConfig

from detectmatelibrary.detectors.charset_detector import CharsetDetectorConfig

from detectmatelibrary.pipeline import PipelineConfig, Pipeline
import detectmatelibrary.schemas as schemas

config = PipelineConfig(
        do_parsing=True,  # Use the parser
        do_aggregation=True,  # Use the aggregator
        parsers=[TemplateCppTreeMatcherConfig(
            path_templates="docs/examples/data/tutorial_templates.txt",
            log_format="type=<Type> msg=audit(<Time>): <Content>"
        )],
        n_workers=1,  # You can add parallelization for the detectors
        detectors=[
            {
                "detectors": {
                    "ECVCDetector": {
                        "method_type": "ecvc_detector",
                        "data_use_configure": 100,
                        "window_size": 10,
                        "seed": 0,
                        "validation_per": 0.,
                        "threshold_method": "mean"
                    }
                }
            },
            CharsetDetectorConfig(
                data_use_configure=100,
                data_use_training=1,
                auto_config=True,
            )
        ],
        aggregator=LogIDCountAggegationConfig(max_count=1)
    )

pipeline = Pipeline(config=config)
pipeline.process(schemas.LogSchema({
    "logID": "0",
    "log": "pid=9699 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:accounting acct=\"root\"'",
}))

Example 2

Run a pipeline with multiple log sources.

Multiple source example
from detectmatelibrary.parsers.tree_matcher import TemplateCppTreeMatcherConfig
from detectmatelibrary.parsers.autoparser import AutoParserConfig

from detectmatelibrary.detectors.charset_detector import CharsetDetectorConfig

from detectmatelibrary.alert_aggregation.logid_count import LogIDCountAggegationConfig

from detectmatelibrary.pipeline import PipelineConfig, Pipeline
import detectmatelibrary.schemas as schemas


config = PipelineConfig(
    do_parsing=True,
    do_aggregation=True,
    n_workers=1,
    parsers=[
        TemplateCppTreeMatcherConfig(
            path_templates="docs/examples/data/tutorial_templates.txt",
            log_format="type=<Type> msg=audit(<Time>): <Content>",
            log_source="Audit_logs",
        ),
        AutoParserConfig(
            fix_type="Apache",
            log_source="Apache_logs",
            data_use_training=1,
        ),
    ],
    detectors=[
        CharsetDetectorConfig(
            data_use_configure=1000,
            data_use_training=1,
            auto_config=True,
            parser="TreeMatcher_from_Audit_logs"
        ),
        CharsetDetectorConfig(
            data_use_configure=10,
            data_use_training=1,
            auto_config=True,
            parser="AutoParser_from_Apache_logs",
        )
    ],
    aggregator=LogIDCountAggegationConfig(max_count=1)
)
pipeline = Pipeline(config=config)

pipeline.process(schemas.LogSchema({
    "logID": "0",
    "log": "pid=9699 uid=0 auid=4294967295 ses=4294967295 msg='op=PAM:accounting acct=\"root\"'",
    "logSource": "Audit_logs"
}))