From 24b10f4d389fcc5c23406eceef5d6e9a35551d21 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sat, 4 May 2024 01:38:32 +0200 Subject: extra recipients per service --- readme.md | 9 +++++++-- src/mail.rs | 11 +++++------ src/main.rs | 2 ++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/readme.md b/readme.md index a3755af..c4c000e 100644 --- a/readme.md +++ b/readme.md @@ -21,8 +21,8 @@ bind: 127.0.0.1:8000 interval: 60 # check interval in seconds mail: # the entire mail section is optional - from: status@example.org - to: [admin@example.org] + mail_from: status@example.org + mail_to: [admin@example.org] smtp_auth: !plain # can be !plain, !starttls or !tls smtp_server: 127.0.0.1 smtp_port: 8025 @@ -40,6 +40,11 @@ services: - !http { url: https://meet.metamuffin.org/ } # this checks that status code of a HTTP request for success - title: failing service + mail_to: [bob@example.org] # for this service, bob will be notified too checks: - !shell { title: "Do nothing unsuccessfully", command: "false" } # this runs a command and checks the exit code ``` + +## License + +AGPL-3.0-only; See `COPYING`. diff --git a/src/mail.rs b/src/mail.rs index 841b552..d6a22b1 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -12,8 +12,8 @@ use crate::Config; #[derive(Debug, Deserialize)] pub struct MailConfig { - from: String, - to: Vec, + mail_from: String, + mail_to: Vec, smtp_auth: SmtpAuth, smtp_port: u16, smtp_timeout: Option, @@ -59,11 +59,10 @@ pub async fn send_mail( } let transport = transport.build(); - for recipient in &mconfig.to { - let service = &config.services[service]; - + let service = &config.services[service]; + for recipient in mconfig.mail_to.iter().chain(service.mail_to.iter()) { let message = Message::builder() - .from(Mailbox::from_str(&mconfig.from)?) + .from(Mailbox::from_str(&mconfig.mail_from)?) .to(Mailbox::from_str(&recipient)?) .subject(format!("{} failed.", service.title)) .body(format!( diff --git a/src/main.rs b/src/main.rs index ff6357f..7f55089 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,8 @@ pub struct Service { title: String, url: Option, checks: Vec, + #[serde(default)] + mail_to: Vec, } #[derive(Debug, Clone)] -- cgit v1.2.3-70-g09d2