Welcome to rsync_watch’s documentation!

class rsync_watch.ChecksCollection(raise_exception: bool = True)[source]

Bases: object

Collect multiple check results.

Params raise_exception

Raise an exception it some checks have failed.

_log_fail(message: str) None[source]
check_file(file_path: str) None[source]

Check if a file exists.

Parameters

file_path – The file to check.

check_ping(dest: str) None[source]

Check if a remote host is reachable by pinging to it.

Parameters

dest – A destination to ping to.

check_ssh_login(ssh_host: str) None[source]

Check if the given host is online by retrieving its hostname.

Parameters

ssh_host – A ssh host string in the form of: user@hostname or hostname or alias (as specified in ~/.ssh/config)

have_passed() bool[source]
Returns

True in fall checks have passed else false.

Return type

boolean

property messages: str
Returns

A concatenated string containing all messages of all failed checks.

exception rsync_watch.StatsNotFoundError(msg, **data)[source]

Bases: CommandWatcherError

Raised when some stats regex couldn’t be found in stdout.

rsync_watch.convert_stat_number_to_int(comma_integer: str) int[source]

Convert a integer containing commas to a integer without commas.

Parameters

comma_integer – a integer containing commas

Returns

A integer without commas

rsync_watch.get_argparser() ArgumentParser[source]
Returns

A ArgumentParse object.

Return type

object

rsync_watch.main() None[source]

Main function. Gets called by entry_points console_scripts.

rsync_watch.parse_stats(stdout: str) Dict[str, Union[int, float]][source]

Parse the standard output of the rsync process.

Parameters

stdout – The standard output of the rsync process

Returns

A dictionary containing all the stats numbers.

rsync_watch.service_name(host_name: str, src: str, dest: str) str[source]

Format a service name to use as a Nagios or Icinga service name.

Parameters
  • host_name – The hostname of the machine the rsync job running on.

  • src – A source string rsync understands

  • dest – A destination string rsync understands

Returns

The service name

A Python script to monitor the execution of a rsync task.

usage: rsync-watch.py [-h] [--host-name HOST_NAME]
                      [--dest-user-group USER_GROUP_NAME]
                      [--rsync-args RSYNC_ARGS]
                      [--action-check-failed {exception,skip}]
                      [--check-file FILE_PATH] [--check-ping DESTINATION]
                      [--check-ssh-login SSH_LOGIN] [-v]
                      src dest

Positional Arguments

src

The source ([[USER@]HOST:]SRC)

dest

The destination ([[USER@]HOST:]DEST)

Named Arguments

--host-name

The hostname to submit over NSCA to the monitoring.

--dest-user-group

Both the user name and the group name of the destination will be set to this name.

--rsync-args

Rsync CLI arguments. Insert some rsync command line arguments.Wrap all arguments in one string, for example: –rsync-args ‘–exclude “this folder”’

-v, --version

show program’s version number and exit

checks

Perform different checks before running the rsync task.

--action-check-failed

Possible choices: exception, skip

Select action what to do when a check failed.

Default: “skip”

--check-file

Check if a file exists on the local machine.

--check-ping

Check if a remote host is reachable by pinging. DESTINATION can a IP address or a host name or a full qualified host name.

--check-ssh-login

Check if a remote host is reachable over the network by SSHing into it. SSH_LOGIN: “root@192.168.1.1” or “root@example.com” or “example.com”.