barman.output module#

This module control how the output of Barman will be rendered

barman.output.AVAILABLE_WRITERS = {'console': <class 'barman.output.ConsoleOutputWriter'>, 'json': <class 'barman.output.JsonOutputWriter'>}#

This dictionary acts as a registry of available OutputWriters

class barman.output.ConsoleOutputWriter(debug=False, quiet=False)View on GitHub#

Bases: object

SERVER_OUTPUT_PREFIX = 'Server %s:'#
__init__(debug=False, quiet=False)View on GitHub#

Default output writer that output everything on console.

Parameters:
  • debug (bool) – print debug messages on standard error

  • quiet (bool) – don’t print info messages

_err(message, args)View on GitHub#

Print a message on standard error

_out(message, args)View on GitHub#

Print a message on standard output

_print(message, args, stream)View on GitHub#

Print an encoded message on the given output stream

_record_check(server_name, check, status, hint, perfdata)View on GitHub#

Record the check line in result_check_map attribute

This method is for subclass use

Parameters:
  • server_name (str) – the server is being checked

  • check (str) – the check name

  • status (bool) – True if succeeded

  • hint (str,None) – hint to print if not None

  • perfdata (str,None) – additional performance data to print if not None

active#

The server is active

close()View on GitHub#

Close the output channel.

Nothing to do for console.

debug(message, *args)View on GitHub#

Emit debug.

error(message, *args)View on GitHub#

Error messages are sent to standard error

error_occurred()View on GitHub#

Called immediately before any message method when the originating call has is_error=True

exception(message, *args)View on GitHub#

Warning messages are sent to standard error

info(message, *args)View on GitHub#

Normal messages are sent to standard output

init_check(server_name, active, disabled)View on GitHub#

Init the check command

Parameters:
  • server_name (str) – the server we are start listing

  • active (boolean) – The server is active

  • disabled (boolean) – The server is disabled

init_check_wal_archive(server_name)View on GitHub#

Init the check-wal-archive command output method

Parameters:

server_name (str) – the server we are displaying

init_list_backup(server_name, minimal=False)View on GitHub#

Init the list-backups command

Parameters:
  • server_name (str) – the server we are start listing

  • minimal (bool) – if true output only a list of backup id

init_list_server(server_name, minimal=False)View on GitHub#

Init the list-servers command

Parameters:

server_name (str) – the server we are start listing

init_replication_status(server_name, minimal=False)View on GitHub#

Init the ‘standby-status’ command

Parameters:
  • server_name (str) – the server we are start listing

  • minimal (str) – minimal output

init_show_server(server_name, description=None)View on GitHub#

Init the show-servers command output method

Parameters:
  • server_name (str) – the server we are displaying

  • description (str,None) – server description if applicable

init_status(server_name)View on GitHub#

Init the status command

Parameters:

server_name (str) – the server we are start listing

is_debug()View on GitHub#

Access the debug property of the OutputWriter instance

Return bool:

if the writer is in debug mode or not

is_quiet()View on GitHub#

Access the quiet property of the OutputWriter instance

Return bool:

if the writer is quiet or not

minimal#

The minimal flag. If set the command must output a single list of values.

static render_show_backup(backup_info, output_fun)View on GitHub#

Renders the output of a show backup command

Parameters:
  • backup_info (dict) – a dictionary containing the backup metadata

  • output_fun (function) – function which accepts a string and sends it to an output writer

static render_show_backup_base(backup_info, output_fun, header_row, nested_row)View on GitHub#

Renders base backup metadata in plain text form.

Parameters:
  • backup_info (dict) – a dictionary containing the backup metadata

  • output_fun (function) – function which accepts a string and sends it to an output writer

  • header_row (str) – format string which allows for single value header rows to be formatted

  • nested_row (str) – format string which allows for key: value rows to be formatted

static render_show_backup_catalog_info(backup_info, output_fun, header_row, nested_row)View on GitHub#

Renders catalog metadata in plain text form.

Parameters:
  • backup_info (dict) – a dictionary containing the backup metadata

  • output_fun (function) – function which accepts a string and sends it to an output writer

  • header_row (str) – format string which allows for single value header rows to be formatted

  • nested_row (str) – format string which allows for key: value rows to be formatted

static render_show_backup_general(backup_info, output_fun, row)View on GitHub#

Render general backup metadata in plain text form.

Parameters:
  • backup_info (dict) – a dictionary containing the backup metadata

  • output_fun (function) – function which accepts a string and sends it to an output writer

  • row (str) – format string which allows for key: value rows to be formatted

static render_show_backup_server(backup_info, output_fun, header_row, nested_row)View on GitHub#

Render server metadata in plain text form.

Parameters:
  • backup_info (dict) – a dictionary containing the backup metadata

  • output_fun (function) – function which accepts a string and sends it to an output writer

  • header_row (str) – format string which allows for single value header rows to be formatted

  • nested_row (str) – format string which allows for key: value rows to be formatted

static render_show_backup_snapshots(backup_info, output_fun, header_row, nested_row)View on GitHub#

Render snapshot metadata in plain text form.

Parameters:
  • backup_info (dict) – a dictionary containing the backup metadata

  • output_fun (function) – function which accepts a string and sends it to an output writer

  • header_row (str) – format string which allows for single value header rows to be formatted

  • nested_row (str) – format string which allows for key: value rows to be formatted

static render_show_backup_tablespaces(backup_info, output_fun, header_row, nested_row)View on GitHub#

Render tablespace metadata in plain text form.

Parameters:
  • backup_info (dict) – a dictionary containing the backup metadata

  • output_fun (function) – function which accepts a string and sends it to an output writer

  • header_row (str) – format string which allows for single value header rows to be formatted

  • nested_row (str) – format string which allows for key: value rows to be formatted

static render_show_backup_walinfo(backup_info, output_fun, header_row, nested_row)View on GitHub#

Renders WAL metadata in plain text form.

Parameters:
  • backup_info (dict) – a dictionary containing the backup metadata

  • output_fun (function) – function which accepts a string and sends it to an output writer

  • header_row (str) – format string which allows for single value header rows to be formatted

  • nested_row (str) – format string which allows for key: value rows to be formatted

result_backup(backup_info)View on GitHub#

Render the result of a backup.

Nothing to do for console.

result_check(server_name, check, status, hint=None, perfdata=None)View on GitHub#

Record a server result of a server check and output it as INFO

Parameters:
  • server_name (str) – the server is being checked

  • check (str) – the check name

  • status (bool) – True if succeeded

  • hint (str,None) – hint to print if not None

  • perfdata (str,None) – additional performance data to print if not None

result_check_list#

Used in check command to hold the check results

result_check_wal_archive(server_name)View on GitHub#

Output the results of the check-wal-archive command

Parameters:

server_name (str) – the server we are displaying

result_list_backup(backup_info, backup_size, wal_size, retention_status)View on GitHub#

Output a single backup in the list-backups command

Parameters:
  • backup_info (BackupInfo) – backup we are displaying

  • backup_size – size of base backup (with the required WAL files)

  • wal_size – size of WAL files belonging to this backup (without the required WAL files)

  • retention_status – retention policy status

result_list_server(server_name, description=None)View on GitHub#

Output a result line of a list-servers command

Parameters:
  • server_name (str) – the server is being checked

  • description (str,None) – server description if applicable

result_recovery(results)View on GitHub#

Render the result of a recovery.

result_replication_status(server_name, target, server_lsn, standby_info)View on GitHub#

Record a result line of a server status command

and output it as INFO

Parameters:
  • server_name (str) – the replication server

  • target (str) – all|hot-standby|wal-streamer

  • server_lsn (str) – server’s current lsn

  • standby_info (StatReplication) – status info of a standby

result_show_backup(backup_ext_info)View on GitHub#

Output all available information about a backup in show-backup command

The argument has to be the result of a Server.get_backup_ext_info() call

Parameters:

backup_ext_info (dict) – a dictionary containing the info to display

result_show_server(server_name, server_info)View on GitHub#

Output the results of the show-servers command

Parameters:
  • server_name (str) – the server we are displaying

  • server_info (dict) – a dictionary containing the info to display

result_status(server_name, status, description, message)View on GitHub#

Record a result line of a server status command

and output it as INFO

Parameters:
  • server_name (str) – the server is being checked

  • status (str) – the returned status code

  • description (str) – the returned status description

  • message (str,object) – status message. It will be converted to str

warning(message, *args)View on GitHub#

Warning messages are sent to standard error

barman.output.DEFAULT_WRITER = 'console'#

The default OutputWriter

class barman.output.JsonOutputWriter(*args, **kwargs)View on GitHub#

Bases: ConsoleOutputWriter

__init__(*args, **kwargs)View on GitHub#

Output writer that writes on standard output using JSON.

When closed, it dumps all the collected results as a JSON object.

_mangle_key(value)View on GitHub#

Mangle a generic description to be used as dict key

Return type:

str

_out_to_field(field, message, *args)View on GitHub#

Store a message in the required field

close()View on GitHub#

Close the output channel. Print JSON output

debug(message, *args)View on GitHub#

Add debug messages in _DEBUG list

error(message, *args)View on GitHub#

Add error messages in _ERROR list

exception(message, *args)View on GitHub#

Add exception messages in _EXCEPTION list

info(message, *args)View on GitHub#

Add normal messages in _INFO list

init_check(server_name, active, disabled)View on GitHub#

Init the check command

Parameters:
  • server_name (str) – the server we are start listing

  • active (boolean) – The server is active

  • disabled (boolean) – The server is disabled

init_check_wal_archive(server_name)View on GitHub#

Init the check-wal-archive command output method

Parameters:

server_name (str) – the server we are displaying

init_list_backup(server_name, minimal=False)View on GitHub#

Init the list-backups command

Parameters:
  • server_name (str) – the server we are listing

  • minimal (bool) – if true output only a list of backup id

init_list_server(server_name, minimal=False)View on GitHub#

Init the list-servers command

Parameters:

server_name (str) – the server we are listing

init_replication_status(server_name, minimal=False)View on GitHub#

Init the ‘standby-status’ command

Parameters:
  • server_name (str) – the server we are start listing

  • minimal (str) – minimal output

init_show_server(server_name, description=None)View on GitHub#

Init the show-servers command output method

Parameters:
  • server_name (str) – the server we are displaying

  • description (str,None) – server description if applicable

init_status(server_name)View on GitHub#

Init the status command

Parameters:

server_name (str) – the server we are start listing

json_output#

Store JSON data

result_backup(backup_info)View on GitHub#

Save the result of a backup.

result_check(server_name, check, status, hint=None, perfdata=None)View on GitHub#

Record a server result of a server check and output it as INFO

Parameters:
  • server_name (str) – the server is being checked

  • check (str) – the check name

  • status (bool) – True if succeeded

  • hint (str,None) – hint to print if not None

  • perfdata (str,None) – additional performance data to print if not None

result_check_wal_archive(server_name)View on GitHub#

Output the results of the check-wal-archive command

Parameters:

server_name (str) – the server we are displaying

result_list_backup(backup_info, backup_size, wal_size, retention_status)View on GitHub#

Output a single backup in the list-backups command

Parameters:
  • backup_info (BackupInfo) – backup we are displaying

  • backup_size – size of base backup (with the required WAL files)

  • wal_size – size of WAL files belonging to this backup (without the required WAL files)

  • retention_status – retention policy status

result_list_server(server_name, description=None)View on GitHub#

Output a result line of a list-servers command

Parameters:
  • server_name (str) – the server is being checked

  • description (str,None) – server description if applicable

result_recovery(results)View on GitHub#

Render the result of a recovery.

result_replication_status(server_name, target, server_lsn, standby_info)View on GitHub#

Record a result line of a server status command

and output it as INFO

Parameters:
  • server_name (str) – the replication server

  • target (str) – all|hot-standby|wal-streamer

  • server_lsn (str) – server’s current lsn

  • standby_info (StatReplication) – status info of a standby

result_show_backup(backup_ext_info)View on GitHub#

Output all available information about a backup in show-backup command in json format.

The argument has to be the result of a barman.server.Server.get_backup_ext_info() call

Parameters:

backup_ext_info (dict) – a dictionary containing the info to display

result_show_server(server_name, server_info)View on GitHub#

Output the results of the show-servers command

Parameters:
  • server_name (str) – the server we are displaying

  • server_info (dict) – a dictionary containing the info to display

result_status(server_name, status, description, message)View on GitHub#

Record a result line of a server status command

and output it as INFO

Parameters:
  • server_name (str) – the server is being checked

  • status (str) – the returned status code

  • description (str) – the returned status description

  • message (str,object) – status message. It will be converted to str

warning(message, *args)View on GitHub#

Add warning messages in _WARNING list

class barman.output.NagiosOutputWriter(debug=False, quiet=False)View on GitHub#

Bases: ConsoleOutputWriter

Nagios output writer.

This writer doesn’t output anything to console. On close it writes a nagios-plugin compatible status

_err(message, args)View on GitHub#

Do not print anything on standard error

_out(message, args)View on GitHub#

Do not print anything on standard output

_parse_check_results()View on GitHub#

Parse the check results and return the servers checked and any issues.

Return tuple:

a tuple containing a list of checked servers, a list of all issues found and a list of additional performance detail.

_print_check_failure(servers, issues, perf_detail)View on GitHub#

Prints the output for a failed check.

_print_check_success(servers, issues=None, perf_detail=None)View on GitHub#

Prints the output for a successful check.

_summarise_server_issues(issues)View on GitHub#

Converts the supplied list of issues into a printable summary.

Return tuple:

A tuple where the first element is a string summarising each server with issues and the second element is a string containing the details of all failures for each server.

close()View on GitHub#

Display the result of a check run as expected by Nagios.

Also set the exit code as 2 (CRITICAL) in case of errors

barman.output.close()View on GitHub#

Close the output writer.

barman.output.close_and_exit()View on GitHub#

Close the output writer and terminate the program.

If an error has been emitted the program will report a non zero return value.

barman.output.debug(message, *args, **kwargs)View on GitHub#

Output a message with severity ‘DEBUG’

Key bool log:

whether to log the message

barman.output.error(message, *args, **kwargs)View on GitHub#

Output a message with severity ‘ERROR’. Also records that an error has occurred unless the ignore parameter is True.

Key bool ignore:

avoid setting an error exit status (default False)

Key bool log:

whether to log the message

barman.output.error_occurred = False#

True if error or exception methods have been called

barman.output.exception(message, *args, **kwargs)View on GitHub#

Output a message with severity ‘EXCEPTION’

If raise_exception parameter doesn’t evaluate to false raise and exception:
  • if raise_exception is callable raise the result of raise_exception()

  • if raise_exception is an exception raise it

  • else raise the last exception again

Key bool ignore:

avoid setting an error exit status

Key raise_exception:

raise an exception after the message has been processed

Key bool log:

whether to log the message

barman.output.info(message, *args, **kwargs)View on GitHub#

Output a message with severity ‘INFO’

Key bool log:

whether to log the message

barman.output.result(command, *args, **kwargs)View on GitHub#

Output the result of an operation.

Parameters:
  • command (str) – name of the command are being executed

  • args (tuple) – all remaining positional arguments will be sent to the output processor

  • kwargs (dict) – all keyword arguments will be sent to the output processor

barman.output.set_output_writer(new_writer, *args, **kwargs)View on GitHub#

Replace the current output writer with a new one.

The new_writer parameter can be a symbolic name or an OutputWriter object

Parameters:
  • new_writer – the OutputWriter name or the actual OutputWriter

  • args (tuple) – all remaining positional arguments will be passed to the OutputWriter constructor

  • kwargs (dict) – all remaining keyword arguments will be passed to the OutputWriter constructor

Type:

string or an OutputWriter

barman.output.warning(message, *args, **kwargs)View on GitHub#

Output a message with severity ‘WARNING’

Key bool log:

whether to log the message