mentat.module.precache module

This Mentat module is a script providing pre-caching functions and features. Use case for this module is precaching distinct values of selected database table column values. These can be then used for example for generating value selection widgets for user interface.

This script is implemented using the pyzenkit.zenscript framework and so it provides all of its core features. See the documentation for more in-depth details.

It is further based on mentat.script.fetcher module, which provides database fetching and message post-processing capabilities.

Usage examples

# Display help message and exit.
mentat-precache.py --help

# Run in debug mode (enable output of debugging information to terminal).
mentat-precache.py --debug

# Run with increased logging level.
mentat-precache.py --log-level debug

Available script commands

precache (default)

Perform pre-caching of selected database table column values. These values can be then used for various use cases like generating value selection widgets for user interface etc.

status

Display status of cache files within cache directory.

Custom configuration

Custom command line options

--allow-empty

Allow storing empty item sets as valid result (flag).

Type: boolean, default: False

--cache-dir dir-name

Filesystem path to cache directory.

Type: string, default: /var/mentat/cache

Custom config file options

itemsets

List of requested itemsets to be precached. It must be in a form of list constaining list of two strings, index 0 is a name of the itemset, index 1 is a name of event table column.

Example configuration:

"itemsets": [
    ["itemset-stat-categories",       "category"],
    ["itemset-stat-sourcetypes",      "source_type"],
    ["itemset-stat-targettypes",      "target_type"],
    ["itemset-stat-detectors",        "node_name"],
    ["itemset-stat-detectortypes",    "node_type"],
    ["itemset-stat-protocols",        "protocol"],
    ["itemset-stat-groups",           "resolvedabuses"],
    ["itemset-stat-classes",          "eventclass"],
    ["itemset-stat-severities",       "eventseverity"],
    ["itemset-stat-inspectionerrors", "inspectionerrors"]
],

Type: list of list of strings, default: []

class mentat.module.precache.MentatPrecacheScript[source]

Bases: FetcherScript

Implementation of Mentat module (script) providing pre-caching functions and features.

CONFIG_ALLOW_EMPTY = 'allow_empty'
CONFIG_CACHE_DIR = 'cache_dir'
CONFIG_ITEMSETS = 'itemsets'
cbk_command_precache()[source]

Implementation of the precache command (default).

Perform pre-caching of selected database table column values. These values can be then used for various use cases like generating value selection widgets for user interface etc.

cbk_command_status()[source]

Implementation of the status command.

Display status of cache files within cache directory.

get_default_command()[source]

Return the name of the default script command. This command will be executed in case it is not explicitly selected either by command line option, or by configuration file directive.

Returns

Name of the default command.

Return type

str