Add email delivery for generated reports
This commit is contained in:
@@ -28,6 +28,7 @@ PVE_TASK_HISTORY_LIMIT=500
|
||||
PBS_HOSTNAMES=backup.example.invalid=display-name
|
||||
LOG_LEVEL=INFO
|
||||
REPORT_FILENAME_PREFIX=rapport-sauvegardes-pve
|
||||
REPORT_EMAIL_ENABLED=false
|
||||
```
|
||||
|
||||
## Variable Description
|
||||
@@ -56,6 +57,46 @@ REPORT_FILENAME_PREFIX=rapport-sauvegardes-pve
|
||||
| `PBS<number>_TIMEOUT_SECONDS` | No | HTTP timeout for this PBS server. Default: `PVE_TIMEOUT_SECONDS` or `30`. |
|
||||
| `LOG_LEVEL` | No | Log level. Default: `INFO`. |
|
||||
| `REPORT_FILENAME_PREFIX` | No | PDF filename prefix. |
|
||||
| `REPORT_EMAIL_ENABLED` | No | Enables sending the generated PDF by email. Default: `false`. |
|
||||
| `REPORT_EMAIL_SMTP_HOST` | If email enabled | SMTP server. |
|
||||
| `REPORT_EMAIL_SMTP_PORT` | No | SMTP port. Default: `587`. |
|
||||
| `REPORT_EMAIL_SMTP_STARTTLS` | No | Enables STARTTLS. Default: `true`. Incompatible with `REPORT_EMAIL_SMTP_SSL=true`. |
|
||||
| `REPORT_EMAIL_SMTP_SSL` | No | Uses implicit TLS SMTP, often port `465`. Default: `false`. |
|
||||
| `REPORT_EMAIL_SMTP_USERNAME` | No | SMTP username. If set, `REPORT_EMAIL_SMTP_PASSWORD` is required. |
|
||||
| `REPORT_EMAIL_SMTP_PASSWORD` | No | SMTP password, read only from the environment and never displayed. |
|
||||
| `REPORT_EMAIL_FROM` | If email enabled | Message sender address. |
|
||||
| `REPORT_EMAIL_TO` | If email enabled | Comma-separated recipients. |
|
||||
| `REPORT_EMAIL_SUBJECT` | No | Message subject. Default: `Rapport sauvegardes PVE`. |
|
||||
| `REPORT_EMAIL_SMTP_TIMEOUT_SECONDS` | No | SMTP timeout. Default: `30`. |
|
||||
|
||||
## Email Delivery
|
||||
|
||||
Email delivery is optional and disabled by default. When `REPORT_EMAIL_ENABLED=true`, the `--generate-pdf` command first writes the timestamped PDF to `REPORT_OUTPUT_DIR`, then sends it as an attachment. If sending fails, the PDF remains on disk and the command returns an error so cron or monitoring can report it.
|
||||
|
||||
Example with STARTTLS:
|
||||
|
||||
```env
|
||||
REPORT_EMAIL_ENABLED=true
|
||||
REPORT_EMAIL_SMTP_HOST=smtp.example.invalid
|
||||
REPORT_EMAIL_SMTP_PORT=587
|
||||
REPORT_EMAIL_SMTP_STARTTLS=true
|
||||
REPORT_EMAIL_SMTP_SSL=false
|
||||
REPORT_EMAIL_SMTP_USERNAME=backup-report@example.invalid
|
||||
REPORT_EMAIL_SMTP_PASSWORD=
|
||||
REPORT_EMAIL_FROM=backup-report@example.invalid
|
||||
REPORT_EMAIL_TO=admin@example.invalid,audit@example.invalid
|
||||
REPORT_EMAIL_SUBJECT=PVE backup report
|
||||
```
|
||||
|
||||
Example with implicit TLS:
|
||||
|
||||
```env
|
||||
REPORT_EMAIL_SMTP_PORT=465
|
||||
REPORT_EMAIL_SMTP_STARTTLS=false
|
||||
REPORT_EMAIL_SMTP_SSL=true
|
||||
```
|
||||
|
||||
Do not put SMTP passwords in the Docker image, logs or committed documentation. Use `.env`, a runtime environment variable or a Docker secret mounted at startup.
|
||||
|
||||
## Docker Compose Example
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ docker compose run --rm pve-backup-report --generate-pdf
|
||||
```
|
||||
|
||||
The report is created in `REPORT_OUTPUT_DIR`. The filename contains a timestamp and never overwrites previous reports.
|
||||
If `REPORT_EMAIL_ENABLED=true`, the generated PDF is then sent to the `REPORT_EMAIL_TO` recipients.
|
||||
|
||||
Example file generated on the host:
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ PVE_TASK_HISTORY_LIMIT=500
|
||||
PBS_HOSTNAMES=backup.example.invalid=nom-affiche
|
||||
LOG_LEVEL=INFO
|
||||
REPORT_FILENAME_PREFIX=rapport-sauvegardes-pve
|
||||
REPORT_EMAIL_ENABLED=false
|
||||
```
|
||||
|
||||
## Description des variables
|
||||
@@ -56,6 +57,46 @@ REPORT_FILENAME_PREFIX=rapport-sauvegardes-pve
|
||||
| `PBS<number>_TIMEOUT_SECONDS` | Non | Timeout HTTP pour ce serveur PBS. Defaut : valeur de `PVE_TIMEOUT_SECONDS` ou `30`. |
|
||||
| `LOG_LEVEL` | Non | Niveau de log. Defaut : `INFO`. |
|
||||
| `REPORT_FILENAME_PREFIX` | Non | Prefixe du fichier PDF. |
|
||||
| `REPORT_EMAIL_ENABLED` | Non | Active l'envoi du PDF par email apres generation. Defaut : `false`. |
|
||||
| `REPORT_EMAIL_SMTP_HOST` | Si email actif | Serveur SMTP. |
|
||||
| `REPORT_EMAIL_SMTP_PORT` | Non | Port SMTP. Defaut : `587`. |
|
||||
| `REPORT_EMAIL_SMTP_STARTTLS` | Non | Active STARTTLS. Defaut : `true`. Incompatible avec `REPORT_EMAIL_SMTP_SSL=true`. |
|
||||
| `REPORT_EMAIL_SMTP_SSL` | Non | Utilise SMTP sur TLS implicite, souvent port `465`. Defaut : `false`. |
|
||||
| `REPORT_EMAIL_SMTP_USERNAME` | Non | Identifiant SMTP. Si renseigne, `REPORT_EMAIL_SMTP_PASSWORD` est obligatoire. |
|
||||
| `REPORT_EMAIL_SMTP_PASSWORD` | Non | Mot de passe SMTP, lu uniquement depuis l'environnement et jamais affiche. |
|
||||
| `REPORT_EMAIL_FROM` | Si email actif | Adresse expediteur du message. |
|
||||
| `REPORT_EMAIL_TO` | Si email actif | Destinataires separes par des virgules. |
|
||||
| `REPORT_EMAIL_SUBJECT` | Non | Sujet du message. Defaut : `Rapport sauvegardes PVE`. |
|
||||
| `REPORT_EMAIL_SMTP_TIMEOUT_SECONDS` | Non | Timeout SMTP. Defaut : `30`. |
|
||||
|
||||
## Envoi du rapport par email
|
||||
|
||||
L'envoi email est optionnel et desactive par defaut. Quand `REPORT_EMAIL_ENABLED=true`, la commande `--generate-pdf` genere d'abord le PDF horodate dans `REPORT_OUTPUT_DIR`, puis l'envoie en piece jointe. Si l'envoi echoue, le PDF reste conserve et la commande retourne une erreur pour que cron ou la supervision puisse l'indiquer.
|
||||
|
||||
Exemple avec STARTTLS :
|
||||
|
||||
```env
|
||||
REPORT_EMAIL_ENABLED=true
|
||||
REPORT_EMAIL_SMTP_HOST=smtp.example.invalid
|
||||
REPORT_EMAIL_SMTP_PORT=587
|
||||
REPORT_EMAIL_SMTP_STARTTLS=true
|
||||
REPORT_EMAIL_SMTP_SSL=false
|
||||
REPORT_EMAIL_SMTP_USERNAME=backup-report@example.invalid
|
||||
REPORT_EMAIL_SMTP_PASSWORD=
|
||||
REPORT_EMAIL_FROM=backup-report@example.invalid
|
||||
REPORT_EMAIL_TO=admin@example.invalid,audit@example.invalid
|
||||
REPORT_EMAIL_SUBJECT=Rapport sauvegardes PVE
|
||||
```
|
||||
|
||||
Exemple avec TLS implicite :
|
||||
|
||||
```env
|
||||
REPORT_EMAIL_SMTP_PORT=465
|
||||
REPORT_EMAIL_SMTP_STARTTLS=false
|
||||
REPORT_EMAIL_SMTP_SSL=true
|
||||
```
|
||||
|
||||
Ne pas renseigner de mot de passe SMTP dans l'image Docker, les logs ou la documentation commitee. Utiliser le fichier `.env`, une variable d'environnement runtime ou un secret Docker monte au lancement.
|
||||
|
||||
## Exemple Docker Compose
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ docker compose run --rm pve-backup-report --generate-pdf
|
||||
```
|
||||
|
||||
Le rapport est cree dans `REPORT_OUTPUT_DIR`. Le nom contient un horodatage et n'ecrase pas les rapports precedents.
|
||||
Si `REPORT_EMAIL_ENABLED=true`, le PDF genere est ensuite envoye aux destinataires `REPORT_EMAIL_TO`.
|
||||
|
||||
Exemple de fichier genere sur l'hote :
|
||||
|
||||
|
||||
Reference in New Issue
Block a user