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_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();
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("mail.infomaniak.com")?
.credentials(creds)
.build();