Limit size of emails
This commit is contained in:
1 parent
f6a2589741
commit
9addf61e8e
3 files changed
+29
-2
No files matched your search
@@ -22,3 +22,14 @@ scheduler.
|
|||||||
* Can create a size-limited rotated logfile.
|
* Can create a size-limited rotated logfile.
|
||||||
* Can send notification emails after each run or only for failures.
|
* Can send notification emails after each run or only for failures.
|
||||||
* Can run `scrub` after `sync`
|
* Can run `scrub` after `sync`
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
###v0.3 (20 Jul 2017)
|
||||||
|
* Limit size of sent emails
|
||||||
|
|
||||||
|
###v0.2 (27 Apr 2015)
|
||||||
|
* Fix compatibility with Snapraid 8.0
|
||||||
|
* Allow disabling of scrub from command line
|
||||||
|
|
||||||
|
###v0.1 (16 Feb 2014)
|
||||||
|
* Initial release
|
||||||
@@ -20,6 +20,8 @@ short = true
|
|||||||
subject = [SnapRAID] Status Report:
|
subject = [SnapRAID] Status Report:
|
||||||
from =
|
from =
|
||||||
to =
|
to =
|
||||||
|
; maximum email size in KiB
|
||||||
|
maxsize = 500
|
||||||
|
|
||||||
[smtp]
|
[smtp]
|
||||||
host =
|
host =
|
||||||
|
|||||||
+16
-2
@@ -1,4 +1,6 @@
|
|||||||
# -*- coding: utf8 -*-
|
# -*- coding: utf8 -*-
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import logging
|
import logging
|
||||||
@@ -79,7 +81,19 @@ def send_email(success):
|
|||||||
body = "SnapRAID job completed successfully:\n\n\n"
|
body = "SnapRAID job completed successfully:\n\n\n"
|
||||||
else:
|
else:
|
||||||
body = "Error during SnapRAID job:\n\n\n"
|
body = "Error during SnapRAID job:\n\n\n"
|
||||||
body += email_log.getvalue()
|
|
||||||
|
log = email_log.getvalue()
|
||||||
|
maxsize = config['email'].get('maxsize', 500) * 1024
|
||||||
|
if maxsize and len(log) > maxsize:
|
||||||
|
cut_lines = log.count("\n", maxsize//2, -maxsize//2)
|
||||||
|
log = (
|
||||||
|
"NOTE: Log was too big for email and was shortened\n\n" +
|
||||||
|
log[:maxsize//2] +
|
||||||
|
"[...]\n\n\n --- LOG WAS TOO BIG - {} LINES REMOVED --\n\n\n[...]".format(
|
||||||
|
cut_lines) +
|
||||||
|
log[-maxsize//2:])
|
||||||
|
body += log
|
||||||
|
|
||||||
msg = MIMEText(body, "plain", "utf-8")
|
msg = MIMEText(body, "plain", "utf-8")
|
||||||
msg["Subject"] = config["email"]["subject"] + \
|
msg["Subject"] = config["email"]["subject"] + \
|
||||||
(" SUCCESS" if success else " ERROR")
|
(" SUCCESS" if success else " ERROR")
|
||||||
@@ -126,7 +140,7 @@ def load_config(args):
|
|||||||
|
|
||||||
int_options = [
|
int_options = [
|
||||||
("snapraid", "deletethreshold"), ("logging", "maxsize"),
|
("snapraid", "deletethreshold"), ("logging", "maxsize"),
|
||||||
("scrub", "percentage"), ("scrub", "older-than")
|
("scrub", "percentage"), ("scrub", "older-than"), ("email", "maxsize"),
|
||||||
]
|
]
|
||||||
for section, option in int_options:
|
for section, option in int_options:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in new issue
Block a user