improved logging

This commit is contained in:
Chris Caron 2024-01-13 23:40:58 -05:00
parent 6459053ae4
commit 426c1080bd
3 changed files with 69 additions and 19 deletions

View File

@ -147,16 +147,33 @@ curl -X POST \
-F attach2=@/my/path/to/Apprise.doc \
http://localhost:8000/notify
# This example shows how you can place the body among other parameters
# in the GET parameter and not the payload as another option.
curl -X POST -d 'urls=mailto://user:pass@gmail.com&body=test message' \
-F @/path/to/your/attachment \
http://localhost:8000/notify
# The body is not required if an attachment is provided:
curl -X POST -d 'urls=mailto://user:pass@gmail.com' \
-F @/path/to/your/attachment \
http://localhost:8000/notify
# Send your notifications directly using JSON
curl -X POST -d '{"urls": "mailto://user:pass@gmail.com", "body":"test message"}' \
-H "Content-Type: application/json" \
http://localhost:8000/notify
```
You can also send notifications that are URLs. Apprise will download the item so that it can send it along to all end points that should be notified about it.
```bash
# Use the 'attachment' parameter and send along a web request
curl -X POST \
-F 'urls=mailto://user:pass@gmail.com' \
-F attachment=https://i.redd.it/my2t4d2fx0u31.jpg \
http://localhost:8000/notify
```
### Persistent Storage Solution
You can pre-save all of your Apprise configuration and/or set of Apprise URLs and associate them with a `{KEY}` of your choosing. Once set, the configuration persists for retrieval by the `apprise` [CLI tool](https://github.com/caronc/apprise/wiki/CLI_Usage) or any other custom integration you've set up. The built in website with comes with a user interface that you can use to leverage these API calls as well. Those who wish to build their own application around this can use the following API end points:

View File

@ -153,7 +153,7 @@ class HTTPAttachment(A_MGR['http']):
Web Attachments
"""
def __init__(self, filename, path=None, delete=True, **kwargs):
def __init__(self, filename, delete=True, **kwargs):
"""
Initialize our attachment
"""
@ -168,21 +168,19 @@ class HTTPAttachment(A_MGR['http']):
raise ValueError('Could not create directory {}'.format(
settings.APPRISE_ATTACH_DIR))
if not path:
try:
d, path = tempfile.mkstemp(dir=settings.APPRISE_ATTACH_DIR)
# Close our file descriptor
os.close(d)
try:
d, self._path = tempfile.mkstemp(dir=settings.APPRISE_ATTACH_DIR)
# Close our file descriptor
os.close(d)
except FileNotFoundError:
raise ValueError(
'Could not prepare {} attachment in {}'.format(
filename, settings.APPRISE_ATTACH_DIR))
except FileNotFoundError:
raise ValueError(
'Could not prepare {} attachment in {}'.format(
filename, settings.APPRISE_ATTACH_DIR))
self._path = path
# Prepare our item
super().__init__(path=self._path, name=filename, **kwargs)
super().__init__(name=filename, **kwargs)
# Update our file size based on the settings value
self.max_file_size = settings.APPRISE_ATTACH_SIZE

View File

@ -610,6 +610,10 @@ class NotifyView(View):
# Handle Attachments
attach = None
if not content.get('attachment') and 'attachment' in request.POST:
# Acquire attachments to work with them
content['attachment'] = request.POST['attachment']
if 'attachment' in content or request.FILES:
try:
attach = parse_attachments(
@ -974,8 +978,9 @@ class NotifyView(View):
)
logger.info(
'NOTIFY - %s - Proccessed%s KEY: %s', request.META['REMOTE_ADDR'],
'' if not tag else f' (Tags: {tag}),', key)
'NOTIFY - %s - Delivered Notification(s) - %sKEY: %s',
request.META['REMOTE_ADDR'],
'' if not tag else f'Tags: {tag}, ', key)
# Return our retrieved content
return HttpResponse(
@ -1011,14 +1016,22 @@ class StatelessNotifyView(View):
except (AttributeError, ValueError):
# could not parse JSON response...
logger.warning(
'SNOTIFY - %s - Invalid JSON Payload provided',
request.META['REMOTE_ADDR'])
return HttpResponse(
_('Invalid JSON specified.'),
status=ResponseCode.bad_request)
if not content:
# We could not handle the Content-Type
logger.warning(
'SNOTIFY - %s - Invalid FORM Payload provided',
request.META['REMOTE_ADDR'])
return HttpResponse(
_('The message format is not supported.'),
_('Bad FORM Payload provided.'),
status=ResponseCode.bad_request)
if not content.get('urls') and settings.APPRISE_STATELESS_URLS:
@ -1031,15 +1044,22 @@ class StatelessNotifyView(View):
content.get('type', apprise.NotifyType.INFO) \
not in apprise.NOTIFY_TYPES:
logger.warning(
'SNOTIFY - %s - Payload lacks minimum requirements',
request.META['REMOTE_ADDR'])
return HttpResponse(
_('An invalid payload was specified.'),
_('Payload lacks minimum requirements.'),
status=ResponseCode.bad_request)
# Acquire our body format (if identified)
body_format = content.get('format', apprise.NotifyFormat.TEXT)
if body_format and body_format not in apprise.NOTIFY_FORMATS:
logger.warning(
'SNOTIFY - %s - Format parameter contains an unsupported '
'value (%s)', request.META['REMOTE_ADDR'], str(body_format))
return HttpResponse(
_('An invalid (body) format was specified.'),
_('An invalid body input format was specified.'),
status=ResponseCode.bad_request)
# Prepare our keyword arguments (to be passed into an AppriseAsset
@ -1053,15 +1073,19 @@ class StatelessNotifyView(View):
kwargs['body_format'] = body_format
# Acquire our recursion count (if defined)
recursion = request.headers.get('X-Apprise-Recursion-Count', 0)
try:
recursion = \
int(request.headers.get('X-Apprise-Recursion-Count', 0))
recursion = int(recursion)
if recursion < 0:
# We do not accept negative numbers
raise TypeError("Invalid Recursion Value")
if recursion > settings.APPRISE_RECURSION_MAX:
logger.warning(
'SNOTIFY - %s - Recursion limit reached (%d > %d)',
request.META['REMOTE_ADDR'], recursion,
settings.APPRISE_RECURSION_MAX)
return HttpResponse(
_('The recursion limit has been reached.'),
status=ResponseCode.method_not_accepted)
@ -1070,6 +1094,9 @@ class StatelessNotifyView(View):
kwargs['_recursion'] = recursion
except (TypeError, ValueError):
logger.warning(
'SNOTIFY - %s - Invalid recursion value (%s) provided',
request.META['REMOTE_ADDR'], str(recursion))
return HttpResponse(
_('An invalid recursion value was specified.'),
status=ResponseCode.bad_request)
@ -1100,6 +1127,10 @@ class StatelessNotifyView(View):
# Handle Attachments
attach = None
if not content.get('attachment') and 'attachment' in request.POST:
# Acquire attachments to work with them
content['attachment'] = request.POST['attachment']
if 'attachment' in content or request.FILES:
try:
attach = parse_attachments(
@ -1178,6 +1209,10 @@ class StatelessNotifyView(View):
_('One or more notification could not be sent.'),
status=ResponseCode.failed_dependency)
logger.info(
'SNOTIFY - %s - Delivered Stateless Notification(s)',
request.META['REMOTE_ADDR'])
# Return our retrieved content
return HttpResponse(
_('Notification(s) sent.'),