mentat.module.dbmngr module

This Mentat module is a script providing database management functions and features.

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-dbmngr.py --help

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

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

# Perform initial database schema creation (both IDEA event and metadata dbs).
mentat-dbmngr.py --command init

# Reinitialize metadata database (drop and create, data destructive!).
mentat-dbmngr.py --command reinit-main

# Rebuild all IDEA event database indices.
mentat-dbmngr.py --command reindex-event

# Insert/remove demonstration data (accounts, groups, filters and networks).
mentat-dbmngr.py --command fixtures-add
mentat-dbmngr.py --command fixtures-remove

# Check IDEA event database for recently stored objects, send email warning
# in case no new objects were stored in configured time interval.
mentat-dbmngr.py --command watchdog-events
mentat-dbmngr.py --command watchdog-events --watchdog-delta 3600

# Same as above, only execute and produce output in Nagios plugin compatible
# mode.
mentat-dbmngr.py --command watchdog-events --nagios-plugin --log-level warning

# Add new user account to the database. Usefull for creating initial account
# after fresh installation. Note the use of double quotes to pass values
# containing spaces (name, organization) and the use of commas to pass multiple
# roles:
mentat-dbmngr.py --command user-add login=admin "fullname=Clark Kent" email=kent@dailyplanet.com "organization=Daily Planet, inc." roles=user,admin

Available script commands

init (default)

Perform necessary database initializations including creating all required indices.

fixtures-add

Populate database with demonstration objects - fixtures (user accounts and groups).

fixtures-remove

Remove demonstration objects from database - fixtures (user accounts and groups).

reinit-main

Reinitialize main database (drop whole database and recreate).

reindex-event

Rebuild event database indices (drop all indices and recreate).

user-add

Add new user account into the database.

watchdog-events

Check IDEA event database table for last message storage time and send out warning email in a case the last message stored is way too old. This simple watchdog should be able to detect issues in message processing chain. Optionally when used with --nagios-plugin option the direct warning mailing feature is suppressed and output and return code is in compliance with Nagios plugin development guidelines.

Custom configuration

Custom command line options

--watchdog-delta value

Time interval delta in hours for watchdog checks.

Type: integer, default: 2

--mail-subject value

Subject for the database watchdog emails.

Type: string, default: Mentat database watchdog alert

--mail-from value

Source email address for the database watchdog emails.

Type: string, default: root

--mail-to value

Target email address for the database watchdog emails.

Type: string, default: root

--nagios-plugin

Execute as Nagios plugin (flag).

Type: bool, default: False

class mentat.module.dbmngr.MentatDbmngrScript[source]

Bases: FetcherScript

Implementation of Mentat module (script) providing database management functions and features.

CONFIG_ADDITIONAL_ARGS = 'additional_args'
CONFIG_MAIL_FROM = 'mail_from'
CONFIG_MAIL_SUBJECT = 'mail_subject'
CONFIG_MAIL_TO = 'mail_to'
CONFIG_NAGIOS_PLUGIN = 'nagios_plugin'
CONFIG_WATCHDOG_DELTA = 'watchdog_delta'
cbk_command_fixtures_add()[source]

Implementation of the fixtures-add command.

Populate database with demonstration objects - fixtures (user accounts and groups).

cbk_command_fixtures_remove()[source]

Implementation of the fixtures-remove command.

Remove demonstration objects from database - fixtures (user accounts and groups).

cbk_command_init()[source]

Implementation of the init command.

Perform necessary database initializations including creating all required indices.

cbk_command_reindex_event()[source]

Implementation of the reindex-event command.

Drop existing indices in event database and recreate them according to current configuration.

cbk_command_reinit_main()[source]

Implementation of the reinit-main command.

Reinitialize main database (drop and create).

cbk_command_user_add()[source]

Implementation of the user-add command.

Add new user account into the database.

cbk_command_watchdog_events()[source]

Implementation of the watchdog-events command.

Check appropriate database collections for last updates and send warning email in case the last message stored is way too old. This simple watchdog should be able to detect issues in message processing chain.

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