use std::{
+ fmt,
net::UdpSocket,
thread,
time::{self, Duration},
// Send e-mail.
println!("Sending email...");
match send_email(
- "Watchdog Watchdog ERROR",
- &format!("Error: {:?}", error),
+ "Watchdog Watchdog: Check alive error",
+ &format!("Error: {}", error),
+ &config.smtp_relay_address,
&config.smtp_login,
&config.smtp_password,
) {
WrongMessageReceived(String),
}
+impl fmt::Display for PingError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ PingError::SocketReceiveError(error) => {
+ write!(f, "Didn't receive any response from watchdog: {}", error)
+ }
+ PingError::SocketSendError(error) => {
+ write!(f, "Unable to send the message: {}", error)
+ }
+ PingError::WrongMessageReceived(message) => {
+ write!(f, "Watchdog replay with a wrong message: {}", message)
+ }
+ }
+ }
+}
+
fn ping(socket: &UdpSocket, rng: &mut ThreadRng) -> std::result::Result<Duration, PingError> {
loop {
let number: u64 = rng.gen();
}
}
-fn send_email(title: &str, body: &str, login: &str, pass: &str) -> Result<()> {
+fn send_email(
+ title: &str,
+ body: &str,
+ smtp_relay_address: &str,
+ login: &str,
+ pass: &str,
+) -> Result<()> {
let email = Message::builder()
.message_id(None)
.from("Staking Watchdog Watchdog <redmine@d-lan.net>".parse()?)
let creds = Credentials::new(login.to_string(), pass.to_string());
- // Open a remote connection to gmail
- let mailer = SmtpTransport::relay("mail.gandi.net")?
+ let mailer = SmtpTransport::relay(smtp_relay_address)?
.credentials(creds)
.build();
- // Send the email
let response = mailer.send(&email)?;
println!("{:?}", response);