wuttjamaican.problems

Problem Checks + Handler

class wuttjamaican.problems.ProblemCheck(config)[source]

Base class for problem checks.

Each subclass must define logic for discovery of problems, according to its purpose; see find_problems().

If the check does find problems, and an email is to be sent, the check instance is also able to affect that email somewhat, e.g. by adding an attachment. See get_email_context() and make_email_attachments().

Parameters:

config – App config object.

find_problems()[source]

Find all problems relevant to this check.

This should always return a list, although no constraint is made on what type of elements it contains.

Returns:

List of problems found.

get_email_context(problems, **kwargs)[source]

This can be used to add extra context for a specific check’s report email template.

Parameters:

problems – List of problems found.

Returns:

Context dict for email template.

make_email_attachments(context)[source]

Optionally generate some attachment(s) for the report email.

Parameters:

context – Context dict for the report email. In particular see context['problems'] for main data.

Returns:

List of attachments, if applicable.

property problem_key

Key identifying this problem check.

This key must be unique within the context of the “system” it pertains to.

See also system_key and title.

property system_key

Key identifying which “system” the check pertains to.

Many apps may only have one “system” which corresponds to the app itself. However some apps may integrate with other systems and have ability/need to check for problems on those systems as well.

See also problem_key and title.

property title

Display title for the problem check.

See also system_key and problem_key.

class wuttjamaican.problems.ProblemHandler(config)[source]

Base class and default implementation for the problem handler.

There is normally no need to instantiate this yourself; instead call get_problem_handler() on the app handler.

The problem handler can be used to discover and run problem checks. In particular see:

filter_problem_checks(systems=None, problems=None)[source]

Return a list of all problem checks which match the given criteria.

This first calls get_all_problem_checks() and then filters the result according to params.

Parameters:
  • systems – Optional list of “system keys” which a problem check must match, in order to be included in return value.

  • problems – Optional list of “problem keys” which a problem check must match, in order to be included in return value.

Returns:

List of ProblemCheck classes; may be an empty list.

find_problems(check)[source]

Execute the given check to find relevant problems.

This mostly calls ProblemCheck.find_problems() although subclass may override if needed.

This should always return a list, although no constraint is made on what type of elements it contains.

Parameters:

checkProblemCheck instance.

Returns:

List of problems found.

get_all_problem_checks()[source]

Return a list of all problem checks which are “available” according to config.

See also filter_problem_checks().

Returns:

List of ProblemCheck classes.

get_check_email_context(check, problems, **kwargs)[source]

This can be used to add extra context for a specific check’s report email template.

Note that this calls ProblemCheck.get_email_context() and in many cases that is where customizations should live.

Parameters:
  • checkProblemCheck instance.

  • problems – List of problems found.

Returns:

Context dict for email template.

get_email_key(check)[source]

Return the “email key” to be used when sending report email resulting from the given problem check.

This follows a convention using the check’s system_key and problem_key.

This is called by send_problem_report().

Parameters:

checkProblemCheck class or instance.

Returns:

Config key for problem report email message.

get_global_email_context(**kwargs)[source]

This can be used to add extra context for all email report templates, regardless of which problem check is involved.

Returns:

Context dict for all email templates.

get_supported_systems(checks=None)[source]

Returns list of keys for all systems which are supported by any of the problem checks.

Parameters:

checks – Optional list of ProblemCheck classes. If not specified, calls get_all_problem_checks().

Returns:

List of system keys.

get_system_title(system_key)[source]

Returns the display title for a given system.

The default logic returns the system_key as-is; subclass may override as needed.

Parameters:

system_key – Key identifying a checked system.

Returns:

Display title for the system.

is_enabled(check)[source]

Returns boolean indicating if the given problem check is enabled, per config.

Parameters:

checkProblemCheck class or instance.

Returns:

True if enabled; False if not.

organize_problem_checks(checks)[source]

Organize the problem checks by grouping them according to their system_key.

Parameters:

checks – List of ProblemCheck classes.

Returns:

Dict with “system” keys; each value is a list of problem checks pertaining to that system.

run_problem_check(check, force=False)[source]

Run the given problem check, if it is enabled and configured to run for the current weekday.

Running a check involves calling find_problems() and possibly send_problem_report().

See also run_problem_checks().

Parameters:
  • checkProblemCheck class.

  • force – If true, run the check regardless of whether it is configured to run.

run_problem_checks(checks, force=False)[source]

Run the given problem checks.

This calls run_problem_check() for each, so config is consulted to determine if each check should actually run - unless force=True.

Parameters:
  • checks – List of ProblemCheck classes.

  • force – If true, run the checks regardless of whether each is configured to run.

send_problem_report(check, problems)[source]

Send an email with details of the given problem check report.

This calls get_email_key() to determine which key to use for sending email.

It also calls get_global_email_context() and get_check_email_context() to build the email template context.

And it calls ProblemCheck.make_email_attachments() to allow the check to provide message attachments.

Parameters:
  • checkProblemCheck instance.

  • problems – List of problems found.

should_run_for_weekday(check, weekday)[source]

Returns boolean indicating if the given problem check is configured to run for the given weekday.

Parameters:
  • checkProblemCheck class or instance.

  • weekday – Integer corresponding to a particular weekday. Uses the same conventions as Python itself, i.e. Monday is represented as 0 and Sunday as 6.

Returns:

True if check should run; False if not.