fix PR comments

This commit is contained in:
Pim Kunis 2023-10-01 17:00:20 +02:00 committed by pizzapim
parent a587e207f9
commit eaa22be3db
4 changed files with 40 additions and 35 deletions

View File

@ -1321,27 +1321,29 @@ properties:
properties:
url:
type: string
example: "mastodon://accesskey/host/?visibility=direct"
example: "gotify://hostname/token"
label:
type: string
example: mastodon
description: |
A list of Apprise services to publish to with URLs and labels.
The labels are used for logging.
A full list of services and their configuration can be found at
https://github.com/caronc/apprise/wiki.
A list of Apprise services to publish to with URLs
and labels. The labels are used for logging.
A full list of services and their configuration can be found
at https://github.com/caronc/apprise/wiki.
example:
- url: "slack://xoxb-1234-1234-4ddbaae6f3523ada2d/#backups"
label: slackbackups
- url: "matrixs://nuxref:abc123@matrix.example.com/#general/#backups"
label: matrix
- url: "kodi://user@hostname"
label: kodi
- url: "line://Token@User"
label: line
start:
type: object
required: ['body']
properties:
title:
type: string
description: |
Specify the message title.
Specify the message title. If left unspecified, no
title is sent.
example: Ping!
body:
type: string
@ -1350,11 +1352,13 @@ properties:
example: Starting backup process.
finish:
type: object
required: ['body']
properties:
title:
type: string
description: |
Specify the message title.
Specify the message title. If left unspecified, no
title is sent.
example: Ping!
body:
type: string
@ -1363,11 +1367,13 @@ properties:
example: Backups successfully made.
fail:
type: object
required: ['body']
properties:
title:
type: string
description: |
Specify the message title.
Specify the message title. If left unspecified, no
title is sent.
example: Ping!
body:
type: string
@ -1386,7 +1392,9 @@ properties:
description: |
List of one or more monitoring states to ping for: "start",
"finish", and/or "fail". Defaults to pinging for failure
only.
only. For each selected state, corresponding configuration
for the message title and body should be given. If any is
left unspecified, a generic message is emitted instead.
example:
- start
- finish

View File

@ -1,4 +1,5 @@
import logging
import operator
logger = logging.getLogger(__name__)
@ -19,7 +20,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
'''
try:
import apprise
from apprise import NotifyType, NotifyFormat
from apprise import NotifyFormat, NotifyType
except ImportError:
logger.warning('Unable to import Apprise in monitoring hook')
return
@ -28,7 +29,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
'start': NotifyType.INFO,
'finish': NotifyType.SUCCESS,
'fail': NotifyType.FAILURE,
'log': NotifyType.INFO
'log': NotifyType.INFO,
}
run_states = hook_config.get('states', ['fail'])
@ -40,7 +41,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
state.name.lower(),
{
'title': f'A borgmatic {state.name} event happened',
'body': f'A borgmatic {state.name} event happened'
'body': f'A borgmatic {state.name} event happened',
},
)
@ -49,27 +50,24 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
return
dry_run_string = ' (dry run; not actually pinging)' if dry_run else ''
labels_string = ', '.join(map(lambda service: service['label'], hook_config.get('services')))
labels_string = ', '.join(map(operator.itemgetter('label'), hook_config.get('services')))
logger.info(f'{config_filename}: Pinging Apprise services: {labels_string}{dry_run_string}')
title = state_config.get('title', '')
body = state_config.get('body')
notify_type = state_to_notify_type[state.name.lower()]
apprise_object = apprise.Apprise()
apprise_object.add(list(map(lambda service: service['url'], hook_config.get('services'))))
apprise_object.add(list(map(operator.itemgetter('url'), hook_config.get('services'))))
if dry_run:
return
result = apprise_object.notify(
title=title,
body=body,
title=state_config.get('title', ''),
body=state_config.get('body'),
body_format=NotifyFormat.TEXT,
notify_type=notify_type)
notify_type=state_to_notify_type[state.name.lower()],
)
if result is False:
logger.warning(f'{config_filename}: error sending some apprise notifications')
logger.warning(f'{config_filename}: Error sending some Apprise notifications')
def destroy_monitor(

View File

@ -34,11 +34,9 @@ setup(
'packaging',
'requests',
'ruamel.yaml>0.15.0,<0.18.0',
'setuptools'
'setuptools',
),
extras_require={
"Apprise": ["apprise"]
},
extras_require={"Apprise": ["apprise"]},
include_package_data=True,
python_requires='>=3.7',
)

View File

@ -1,6 +1,8 @@
appdirs==1.4.4; python_version >= '3.8'
apprise==1.3.0
attrs==22.2.0; python_version >= '3.8'
black==23.3.0; python_version >= '3.8'
certifi==2022.9.24
chardet==5.1.0
click==8.1.3; python_version >= '3.8'
codespell==2.2.4
@ -14,16 +16,18 @@ flexmock==0.11.3
idna==3.4
importlib_metadata==6.3.0; python_version < '3.8'
isort==5.12.0
jsonschema==4.17.3
Markdown==3.4.1
mccabe==0.7.0
packaging==23.1
pluggy==1.0.0
pathspec==0.11.1; python_version >= '3.8'
pluggy==1.0.0
py==1.11.0
pycodestyle==2.10.0
pyflakes==3.0.1
jsonschema==4.17.3
pytest==7.3.0
pytest-cov==4.0.0
PyYAML==6.0
regex; python_version >= '3.8'
requests==2.31.0
ruamel.yaml>0.15.0,<0.18.0
@ -31,6 +35,3 @@ toml==0.10.2; python_version >= '3.8'
typed-ast; python_version >= '3.8'
typing-extensions==4.5.0; python_version < '3.8'
zipp==3.15.0; python_version < '3.8'
certifi==2022.9.24
PyYAML==6.0
Markdown==3.4.1