Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Sep 14, 2024
1 parent f051e92 commit f21eabf
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 139 deletions.
82 changes: 7 additions & 75 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,9 @@ Features

::

usage: rsync-watch.py [-h] [--host-name HOST_NAME]
[--dest-user-group USER_GROUP_NAME] [--exclude EXCLUDE]
[--rsync-args RSYNC_ARGS]
[--action-check-failed {exception,skip}]
[--check-file FILE_PATH] [--check-ping DESTINATION]
[--check-ssh-login SSH_LOGIN] [-v]
[--email-from-addr EMAIL_FROM_ADDR]
[--email-to-addr EMAIL_TO_ADDR]
[--email-to-addr-critical EMAIL_TO_ADDR_CRITICAL]
[--email-smtp-login EMAIL_SMTP_LOGIN]
[--email-smtp-password EMAIL_SMTP_PASSWORD]
[--email-smtp-server EMAIL_SMTP_SERVER]
[--nsca-remote-host NSCA_REMOTE_HOST]
[--nsca-password NSCA_PASSWORD]
[--nsca-encryption-method NSCA_ENCRYPTION_METHOD]
[--nsca-port NSCA_PORT] [--icinga-url ICINGA_URL]
[--icinga-user ICINGA_USER]
[--icinga-password ICINGA_PASSWORD]
[--beep-activated BEEP_ACTIVATED]
usage: rsync-watch.py [-h] [--host-name HOST_NAME] [--dest-user-group USER_GROUP_NAME] [--exclude EXCLUDE]
[--rsync-args RSYNC_ARGS] [--action-check-failed {exception,skip}] [--check-file FILE_PATH]
[--check-ping DESTINATION] [--check-ssh-login SSH_LOGIN] [-v]
src dest

A Python script to monitor the execution of a rsync task.
Expand All @@ -59,12 +43,10 @@ Features
--host-name HOST_NAME
The hostname to submit over NSCA to the monitoring.
--dest-user-group USER_GROUP_NAME
Both the user name and the group name of the
destination will be set to this name.
Both the user name and the group name of the destination will be set to this name.
--exclude EXCLUDE See the documention of --exclude in the rsync manual.
--rsync-args RSYNC_ARGS
Rsync CLI arguments. Insert some rsync command line
arguments. Wrap all arguments in one string, for
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

Expand All @@ -76,59 +58,9 @@ Features
--check-file FILE_PATH
Check if a file exists on the local machine.
--check-ping DESTINATION
Check if a remote host is reachable by pinging.
DESTINATION can a IP address or a host name or a full
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 SSH_LOGIN
Check if a remote host is reachable over the network
by SSHing into it. SSH_LOGIN: “[email protected]” or
Check if a remote host is reachable over the network by SSHing into it. SSH_LOGIN: “[email protected]” or
[email protected]” or “example.com”.

email:
Generated by the config_reader.

--email-from-addr EMAIL_FROM_ADDR
The email address of the sender.
--email-to-addr EMAIL_TO_ADDR
The email address of the recipient.
--email-to-addr-critical EMAIL_TO_ADDR_CRITICAL
The email address of the recipient to send critical
messages to.
--email-smtp-login EMAIL_SMTP_LOGIN
The SMTP login name.
--email-smtp-password EMAIL_SMTP_PASSWORD
The SMTP password.
--email-smtp-server EMAIL_SMTP_SERVER
The URL of the SMTP server, for example:
`smtp.example.com:587`.

nsca:
Generated by the config_reader.

--nsca-remote-host NSCA_REMOTE_HOST
The IP address of the NSCA remote host.
--nsca-password NSCA_PASSWORD
The NSCA password.
--nsca-encryption-method NSCA_ENCRYPTION_METHOD
The NSCA encryption method. The supported encryption
methods are: 0 1 2 3 4 8 11 14 15 16
--nsca-port NSCA_PORT
The NSCA port.

icinga:
Generated by the config_reader.

--icinga-url ICINGA_URL
The HTTP URL. /v1/actions/process-check-result is
appended.
--icinga-user ICINGA_USER
The user for the HTTP authentification.
--icinga-password ICINGA_PASSWORD
The password for the HTTP authentification.

beep:
Generated by the config_reader.

--beep-activated BEEP_ACTIVATED
Activate the beep channel to report auditive messages.

81 changes: 46 additions & 35 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ repository = "https://github.com/Josef-Friedrich/rsync-watch"

[tool.poetry.dependencies]
python = "^3.10"
command-watcher = "^0"
conf2levels = "^0"
command-watcher = { git = "https://github.com/Josef-Friedrich/command-watcher.git" }

[tool.poetry.group.dev.dependencies]
mypy = "^1"
Expand Down
35 changes: 8 additions & 27 deletions rsync_watch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
#! /usr/bin/env python


import os
import re
import shlex
import socket
import typing
from argparse import Namespace

from command_watcher import CONFIG_READER_SPEC, CommandWatcherError, Watch
from conf2levels import ConfigReader
from command_watcher import CommandWatcherError, Watch

from .check import ChecksCollection
from .cli import ArgumentsDefault, __version__, get_argparser # noqa: F401
from rsync_watch.check import ChecksCollection
from rsync_watch.cli import ArgumentsDefault, __version__, get_argparser # noqa: F401

watch: Watch

Expand Down Expand Up @@ -152,8 +149,8 @@ def format_service_name(host_name: str, src: str, dest: str) -> str:
return result


def build_rsync_command(args: ArgumentsDefault) -> typing.List[str]:
rsync_command: typing.List[str] = ["rsync", "-av", "--delete", "--stats"]
def build_rsync_command(args: ArgumentsDefault) -> list[str]:
rsync_command: list[str] = ["rsync", "-av", "--delete", "--stats"]

if args.dest_user_group:
# https://stackoverflow.com/a/62982981
Expand Down Expand Up @@ -182,11 +179,8 @@ def main() -> None:
# We need `args` for the configs.
# We get the service name from the args.
# A typical chicken-egg-situation.
config_reader: ConfigReader = ConfigReader(spec=CONFIG_READER_SPEC)
parser = get_argparser()
config_reader.spec_to_argparse(parser)
args = typing.cast(ArgumentsDefault, parser.parse_args())
del config_reader

host_name: str
if not args.host_name:
Expand All @@ -196,20 +190,7 @@ def main() -> None:

service = format_service_name(host_name, args.src, args.dest)

ini_file = os.path.join("/", "etc", "command-watcher.ini")
if os.path.exists(ini_file):
config_reader = ConfigReader(
spec=CONFIG_READER_SPEC,
argparse=typing.cast(Namespace, args),
ini=ini_file,
)
else:
config_reader = ConfigReader(
spec=CONFIG_READER_SPEC,
argparse=(typing.cast(Namespace, args), {}),
)
global watch
watch = Watch(service_name=service, config_reader=config_reader)
watch = Watch(service_name=service)

watch.log.info("Service name: {}".format(service))

Expand All @@ -228,7 +209,7 @@ def main() -> None:
watch.report(status=1, custom_message=checks.messages)
watch.log.info(checks.messages)
else:
rsync_command: typing.List[str] = build_rsync_command(args)
rsync_command: list[str] = build_rsync_command(args)

watch.log.info("Source: {}".format(args.src))
watch.log.info("Destination: {}".format(args.dest))
Expand All @@ -238,7 +219,7 @@ def main() -> None:
# define RERR_VANISHED 24 /* file(s) vanished on sender side */
# Vanished files occure if you for example open thunderbird and
# rsync-watch.py synchronizes your maildir folder.
watch.run(rsync_command, ignore_exceptions=[24])
watch.run(rsync_command, ignore_exceptions=[24]) # type: ignore
stats: typing.Dict[str, int | float] = parse_stats(watch.stdout)
watch.report(status=0, performance_data=stats)
watch.log.debug(stats)
Expand Down

0 comments on commit f21eabf

Please sign in to comment.