mentat.module.ideagen module

This Mentat module is a script providing functions for generating IDEA messages, mainly for testing or development purposes.

The messsages are generated using prepared templates filled with randomized values of certain keys.

Currently this script is work in progress and many features are hardcoded, like the lists of values for message randomization process.

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.

Message templates

Message templates are based on jinja2 templates. The location of template directory can be adjusted with command line option --template-dir or configuration file directive template_dir and by default is set to /etc/mentat/templates/idea.

Usage examples

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

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

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

# Generate given number of messages.
mentat-ideagen.py --count 10

# Generate random number of messages up to given max count.
mentat-ideagen.py --random-count 10

# Generate messages into given queue directory.
mentat-ideagen.py --queue-dir /var/mentat/spool/mentat-inspector.py/incoming

Available script commands

generate-random (default)

Generate configured number of random test messages into target queue directory.

Custom configuration

Custom command line options

--count

Number of messages to be generated in one batch. This option is mutually exclusive with random-count and always comes as a second.

Type: integer, default: 1

--random-count

Number of messages to be generated in one batch. This option is mutually exclusive with count and always takes precedence.

Type: integer, default: None

--steady

Generate messages continuously with given time backoff (flag).

Type: boolean, default: False

--back-off

Back-off time between message batches in seconds, used when steady is True.

Type: integer, default: 60

--queue-dir

Name of the target queue directory.

Type: string, default: /var/tmp

--temp-dir

Name of the temporary file directory.

Type: string, default: /var/tmp

--template

Name of template file for generating messages.

Type: string, default: msg.01.idea.j2

--template-dir

Name of the directory containing message templates.

Type: string, default: /etc/mentat/templates/idea

class mentat.module.ideagen.MentatIdeagenScript[source]

Bases: MentatBaseScript

Implementation of Mentat module (script) providing functions for generating IDEA messages, mainly for testing or development purposes.

CONFIG_BACK_OFF = 'back_off'
CONFIG_COUNT = 'count'
CONFIG_LIST_CATEGORIES = 'list_categories'
CONFIG_LIST_CLASSES = 'list_classes'
CONFIG_LIST_NODE_NAMES = 'list_node_names'
CONFIG_LIST_NODE_SWS = 'list_node_sws'
CONFIG_LIST_NODE_TAGS = 'list_node_tags'
CONFIG_LIST_PROTOCOLS = 'list_protocols'
CONFIG_LIST_SEVERITIES = 'list_severities'
CONFIG_LIST_SOURCE_EMAILS = 'list_source_emails'
CONFIG_LIST_SOURCE_HOSTNAMES = 'list_source_hostnames'
CONFIG_LIST_SOURCE_IP4S = 'list_source_ip4s'
CONFIG_LIST_SOURCE_IP6S = 'list_source_ip6s'
CONFIG_LIST_SOURCE_MACS = 'list_source_macs'
CONFIG_LIST_SOURCE_URLS = 'list_source_urls'
CONFIG_LIST_SRCTGT_TAGS = 'list_srctgt_tags'
CONFIG_LIST_TARGET_EMAILS = 'list_target_emails'
CONFIG_LIST_TARGET_HOSTNAMES = 'list_target_hostnames'
CONFIG_LIST_TARGET_IP4S = 'list_target_ip4s'
CONFIG_LIST_TARGET_IP6S = 'list_target_ip6s'
CONFIG_LIST_TARGET_MACS = 'list_target_macs'
CONFIG_LIST_TARGET_URLS = 'list_target_urls'
CONFIG_QUEUE_DIR = 'queue_dir'
CONFIG_RANDOM_COUNT = 'random_count'
CONFIG_STEADY = 'steady'
CONFIG_TEMPLATE = 'template'
CONFIG_TEMPLATE_DIR = 'template_dir'
CONFIG_TEMP_DIR = 'temp_dir'
cbk_command_generate_random()[source]

Implementation of generate-random command (default).

Generate configured number of random test messages into target queue 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