fix PR comments
This commit is contained in:
parent
a587e207f9
commit
eaa22be3db
4 changed files with 40 additions and 35 deletions
|
@ -1321,27 +1321,29 @@ properties:
|
||||||
properties:
|
properties:
|
||||||
url:
|
url:
|
||||||
type: string
|
type: string
|
||||||
example: "mastodon://accesskey/host/?visibility=direct"
|
example: "gotify://hostname/token"
|
||||||
label:
|
label:
|
||||||
type: string
|
type: string
|
||||||
example: mastodon
|
example: mastodon
|
||||||
description: |
|
description: |
|
||||||
A list of Apprise services to publish to with URLs and labels.
|
A list of Apprise services to publish to with URLs
|
||||||
The labels are used for logging.
|
and labels. The labels are used for logging.
|
||||||
A full list of services and their configuration can be found at
|
A full list of services and their configuration can be found
|
||||||
https://github.com/caronc/apprise/wiki.
|
at https://github.com/caronc/apprise/wiki.
|
||||||
example:
|
example:
|
||||||
- url: "slack://xoxb-1234-1234-4ddbaae6f3523ada2d/#backups"
|
- url: "kodi://user@hostname"
|
||||||
label: slackbackups
|
label: kodi
|
||||||
- url: "matrixs://nuxref:abc123@matrix.example.com/#general/#backups"
|
- url: "line://Token@User"
|
||||||
label: matrix
|
label: line
|
||||||
start:
|
start:
|
||||||
type: object
|
type: object
|
||||||
|
required: ['body']
|
||||||
properties:
|
properties:
|
||||||
title:
|
title:
|
||||||
type: string
|
type: string
|
||||||
description: |
|
description: |
|
||||||
Specify the message title.
|
Specify the message title. If left unspecified, no
|
||||||
|
title is sent.
|
||||||
example: Ping!
|
example: Ping!
|
||||||
body:
|
body:
|
||||||
type: string
|
type: string
|
||||||
|
@ -1350,11 +1352,13 @@ properties:
|
||||||
example: Starting backup process.
|
example: Starting backup process.
|
||||||
finish:
|
finish:
|
||||||
type: object
|
type: object
|
||||||
|
required: ['body']
|
||||||
properties:
|
properties:
|
||||||
title:
|
title:
|
||||||
type: string
|
type: string
|
||||||
description: |
|
description: |
|
||||||
Specify the message title.
|
Specify the message title. If left unspecified, no
|
||||||
|
title is sent.
|
||||||
example: Ping!
|
example: Ping!
|
||||||
body:
|
body:
|
||||||
type: string
|
type: string
|
||||||
|
@ -1363,11 +1367,13 @@ properties:
|
||||||
example: Backups successfully made.
|
example: Backups successfully made.
|
||||||
fail:
|
fail:
|
||||||
type: object
|
type: object
|
||||||
|
required: ['body']
|
||||||
properties:
|
properties:
|
||||||
title:
|
title:
|
||||||
type: string
|
type: string
|
||||||
description: |
|
description: |
|
||||||
Specify the message title.
|
Specify the message title. If left unspecified, no
|
||||||
|
title is sent.
|
||||||
example: Ping!
|
example: Ping!
|
||||||
body:
|
body:
|
||||||
type: string
|
type: string
|
||||||
|
@ -1386,7 +1392,9 @@ properties:
|
||||||
description: |
|
description: |
|
||||||
List of one or more monitoring states to ping for: "start",
|
List of one or more monitoring states to ping for: "start",
|
||||||
"finish", and/or "fail". Defaults to pinging for failure
|
"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:
|
example:
|
||||||
- start
|
- start
|
||||||
- finish
|
- finish
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
import operator
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
import apprise
|
import apprise
|
||||||
from apprise import NotifyType, NotifyFormat
|
from apprise import NotifyFormat, NotifyType
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.warning('Unable to import Apprise in monitoring hook')
|
logger.warning('Unable to import Apprise in monitoring hook')
|
||||||
return
|
return
|
||||||
|
@ -28,7 +29,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
|
||||||
'start': NotifyType.INFO,
|
'start': NotifyType.INFO,
|
||||||
'finish': NotifyType.SUCCESS,
|
'finish': NotifyType.SUCCESS,
|
||||||
'fail': NotifyType.FAILURE,
|
'fail': NotifyType.FAILURE,
|
||||||
'log': NotifyType.INFO
|
'log': NotifyType.INFO,
|
||||||
}
|
}
|
||||||
|
|
||||||
run_states = hook_config.get('states', ['fail'])
|
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(),
|
state.name.lower(),
|
||||||
{
|
{
|
||||||
'title': f'A borgmatic {state.name} event happened',
|
'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
|
return
|
||||||
|
|
||||||
dry_run_string = ' (dry run; not actually pinging)' if dry_run else ''
|
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}')
|
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 = 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:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
result = apprise_object.notify(
|
result = apprise_object.notify(
|
||||||
title=title,
|
title=state_config.get('title', ''),
|
||||||
body=body,
|
body=state_config.get('body'),
|
||||||
body_format=NotifyFormat.TEXT,
|
body_format=NotifyFormat.TEXT,
|
||||||
notify_type=notify_type)
|
notify_type=state_to_notify_type[state.name.lower()],
|
||||||
|
)
|
||||||
|
|
||||||
if result is False:
|
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(
|
def destroy_monitor(
|
||||||
|
|
6
setup.py
6
setup.py
|
@ -34,11 +34,9 @@ setup(
|
||||||
'packaging',
|
'packaging',
|
||||||
'requests',
|
'requests',
|
||||||
'ruamel.yaml>0.15.0,<0.18.0',
|
'ruamel.yaml>0.15.0,<0.18.0',
|
||||||
'setuptools'
|
'setuptools',
|
||||||
),
|
),
|
||||||
extras_require={
|
extras_require={"Apprise": ["apprise"]},
|
||||||
"Apprise": ["apprise"]
|
|
||||||
},
|
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
python_requires='>=3.7',
|
python_requires='>=3.7',
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
appdirs==1.4.4; python_version >= '3.8'
|
appdirs==1.4.4; python_version >= '3.8'
|
||||||
|
apprise==1.3.0
|
||||||
attrs==22.2.0; python_version >= '3.8'
|
attrs==22.2.0; python_version >= '3.8'
|
||||||
black==23.3.0; python_version >= '3.8'
|
black==23.3.0; python_version >= '3.8'
|
||||||
|
certifi==2022.9.24
|
||||||
chardet==5.1.0
|
chardet==5.1.0
|
||||||
click==8.1.3; python_version >= '3.8'
|
click==8.1.3; python_version >= '3.8'
|
||||||
codespell==2.2.4
|
codespell==2.2.4
|
||||||
|
@ -14,16 +16,18 @@ flexmock==0.11.3
|
||||||
idna==3.4
|
idna==3.4
|
||||||
importlib_metadata==6.3.0; python_version < '3.8'
|
importlib_metadata==6.3.0; python_version < '3.8'
|
||||||
isort==5.12.0
|
isort==5.12.0
|
||||||
|
jsonschema==4.17.3
|
||||||
|
Markdown==3.4.1
|
||||||
mccabe==0.7.0
|
mccabe==0.7.0
|
||||||
packaging==23.1
|
packaging==23.1
|
||||||
pluggy==1.0.0
|
|
||||||
pathspec==0.11.1; python_version >= '3.8'
|
pathspec==0.11.1; python_version >= '3.8'
|
||||||
|
pluggy==1.0.0
|
||||||
py==1.11.0
|
py==1.11.0
|
||||||
pycodestyle==2.10.0
|
pycodestyle==2.10.0
|
||||||
pyflakes==3.0.1
|
pyflakes==3.0.1
|
||||||
jsonschema==4.17.3
|
|
||||||
pytest==7.3.0
|
pytest==7.3.0
|
||||||
pytest-cov==4.0.0
|
pytest-cov==4.0.0
|
||||||
|
PyYAML==6.0
|
||||||
regex; python_version >= '3.8'
|
regex; python_version >= '3.8'
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
ruamel.yaml>0.15.0,<0.18.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'
|
typed-ast; python_version >= '3.8'
|
||||||
typing-extensions==4.5.0; python_version < '3.8'
|
typing-extensions==4.5.0; python_version < '3.8'
|
||||||
zipp==3.15.0; python_version < '3.8'
|
zipp==3.15.0; python_version < '3.8'
|
||||||
certifi==2022.9.24
|
|
||||||
PyYAML==6.0
|
|
||||||
Markdown==3.4.1
|
|
||||||
|
|
Loading…
Reference in a new issue