*/
use std::{
+ fmt,
net::UdpSocket,
sync::{Arc, Mutex},
thread,
// Send e-mail.
println!("Sending email...");
match send_email(
- "Staking ERROR",
- &format!("Error: {:?}", error),
+ "Watchdog: Staking error",
+ &format!("Error: {}", error),
+ &config.smtp_relay_address,
&config.smtp_login,
&config.smtp_password,
) {
CheckAlive,
}
+impl fmt::Display for CheckError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ CheckError::HttpError(text) => {
+ write!(
+ f,
+ "Beacon node health check can't be reached (HTTP error): {}",
+ text
+ )
+ }
+ CheckError::NotSync => {
+ write!(
+ f,
+ "Beacon node health check is syncing (currently not sync)"
+ )
+ }
+ CheckError::InvalidSyncStatus => {
+ write!(f, "Beacon node health check returns an invalid status code")
+ }
+ CheckError::NodeHavingIssues => {
+ write!(
+ f,
+ "Beacon node health check is not initilized or having issue"
+ )
+ }
+ CheckError::UnknownCodeFromHealthCheck(code) => {
+ write!(
+ f,
+ "Beacon node health check returns an unknown code: {}",
+ code
+ )
+ }
+ CheckError::ReqwestError(error) => {
+ write!(f, "Error from reqwest: {}", error)
+ }
+ CheckError::ValidatorError { pub_key, message } => {
+ write!(f, "Validator '{}' returns an error: {}", pub_key, message)
+ }
+ CheckError::ValidatorStatusError { pub_key, message } => {
+ write!(
+ f,
+ "Validator '{}' returns a status error: {}",
+ pub_key, message
+ )
+ }
+ CheckError::CheckAlive => {
+ write!(f, "Check alive ping hasn't been received")
+ }
+ }
+ }
+}
+
impl From<reqwest::Error> for CheckError {
fn from(value: reqwest::Error) -> Self {
CheckError::ReqwestError(value)
Ok(())
}
-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 <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);