mirror of
https://github.com/netinvent/npbackup.git
synced 2025-10-25 04:46:58 +08:00
email: Only send the first x bytes of detail in email
This commit is contained in:
parent
bdf2e56cce
commit
fe15bcf0c5
2 changed files with 15 additions and 1 deletions
|
|
@ -51,3 +51,6 @@ ALLOWED_UPGRADE_SERVER_IDS = ("npbackup.upgrader", "npbackup.deployment_server")
|
|||
|
||||
# Replacement string for sensitive data
|
||||
HIDDEN_BY_NPBACKUP = "_[o_O]_hidden_by_npbackup"
|
||||
|
||||
# Maximum number of characters for details content in emails
|
||||
MAX_EMAIL_DETAIL_LENGTH = 1000
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ from npbackup.restic_metrics import (
|
|||
from npbackup.__version__ import __intname__ as NAME, version_dict
|
||||
from npbackup.__debug__ import fmt_json
|
||||
from resources.customization import OEM_STRING
|
||||
from npbackup.__env__ import MAX_EMAIL_DETAIL_LENGTH
|
||||
|
||||
logger = getLogger()
|
||||
|
||||
|
|
@ -325,7 +326,17 @@ def send_metrics_mail(
|
|||
body += f"\nDate: {date}"
|
||||
|
||||
if isinstance(restic_result, dict):
|
||||
body += f"\n\nDetail: {fmt_json(restic_result)}"
|
||||
try:
|
||||
restic_result = fmt_json(restic_result)
|
||||
except TypeError:
|
||||
# TypeError may happen on ls command which contains a json of LSNodes when HAVE_MSGSPEC is True
|
||||
pass
|
||||
# Convert the dict to a string so we can analyze its length
|
||||
restic_result = str(restic_result)
|
||||
if len(restic_result) > MAX_EMAIL_DETAIL_LENGTH:
|
||||
body += f"\n\nDetail:\n{restic_result[0:MAX_EMAIL_DETAIL_LENGTH]} [... truncated]"
|
||||
else:
|
||||
body += f"\n\nDetail:\n{restic_result}"
|
||||
|
||||
body += f"\n\nGenerated by {OEM_STRING} {version_dict['version']}\n"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue