Fix warnings, implement Errors

This commit is contained in:
2026-08-21 15:08:39 +03:00
parent 0642807b06
commit 6395a8e672
5 changed files with 21 additions and 15 deletions

View File

@@ -10,7 +10,6 @@
use std::net::IpAddr; use std::net::IpAddr;
use clap::ArgGroup; use clap::ArgGroup;
use serde::de;
#[derive(Debug, Clone, clap::Parser, Default)] #[derive(Debug, Clone, clap::Parser, Default)]
#[command( #[command(

View File

@@ -12,7 +12,7 @@ use clap::Parser;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tabled::Tabled; use tabled::Tabled;
use crate::config::cli::{CliArgs, CliCommand}; use crate::config::cli::CliArgs;
const DEFAULT_CONFIG: &'static str = include_str!("../../config.default.toml"); const DEFAULT_CONFIG: &'static str = include_str!("../../config.default.toml");

View File

@@ -1,3 +1,4 @@
#![allow(dead_code)]
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use diesel::prelude::*; use diesel::prelude::*;

View File

@@ -13,11 +13,9 @@ use std::{
str::FromStr, str::FromStr,
}; };
use clap::builder; use diesel::{ExpressionMethods, RunQueryDsl, query_dsl::methods::FilterDsl};
use diesel::{ExpressionMethods, RunQueryDsl};
use log::LevelFilter; use log::LevelFilter;
use serde_json::json; use serde_json::json;
use tabled::Table;
use tokio::time::{self, Duration}; use tokio::time::{self, Duration};
use crate::{ use crate::{
@@ -25,7 +23,10 @@ use crate::{
Config, ConfigHost, Config, ConfigHost,
cli::{CliCommand, CliDeviceCommand, OutputFormat}, cli::{CliCommand, CliDeviceCommand, OutputFormat},
}, },
db::models::{NewAntenna, NewClientReading}, db::{
models::{NewAntenna, NewClientReading},
schema::antennas,
},
}; };
mod config; mod config;
@@ -92,7 +93,7 @@ async fn main() -> anyhow::Result<()> {
let v6_cmd = "/interface/wireless/registration-table/print"; let v6_cmd = "/interface/wireless/registration-table/print";
let v7_cmd = "/interface/wifi/registration-table/print"; let v7_cmd = "/interface/wifi/registration-table/print";
let mut interval = time::interval(Duration::from_secs(5)); let mut interval = time::interval(Duration::from_mins(3));
loop { loop {
interval.tick().await; interval.tick().await;
@@ -143,7 +144,7 @@ async fn main() -> anyhow::Result<()> {
if client_db.contains("@") { if client_db.contains("@") {
client_db = client_db.split('@').nth(0).unwrap().to_string(); client_db = client_db.split('@').nth(0).unwrap().to_string();
} }
dbg!(&client_db);
let client_db = let client_db =
parse_int::parse::<i32>(&client_db).expect("Unparseble number"); parse_int::parse::<i32>(&client_db).expect("Unparseble number");
records.push(NewClientReading { records.push(NewClientReading {
@@ -155,11 +156,17 @@ async fn main() -> anyhow::Result<()> {
} }
} }
Ok(_) => unreachable!(), Ok(_) => unreachable!(),
Err(_) => {} Err(e) => {
diesel::update(
antennas::table.filter(antennas::ip.eq(antenna.ip.to_string())),
)
.set(antennas::error.eq(e.to_string()))
.execute(&mut conn)?;
}
} }
} }
log::info!("inserting: {records:?}"); log::debug!("inserting: {records:?}");
diesel::insert_into(crate::db::schema::client_readings::table) diesel::insert_into(crate::db::schema::client_readings::table)
.values(&records) .values(&records)
.execute(&mut conn) .execute(&mut conn)
@@ -309,7 +316,7 @@ fn print_output(
e.to_string(), e.to_string(),
]; ];
for wanted_col in &wanted_cols { for _ in &wanted_cols {
row.push(String::new()); row.push(String::new());
} }
table.push(row); table.push(row);
@@ -374,7 +381,7 @@ fn print_output(
} }
} }
Err(e) => { Err(e) => {
let mut row = vec![ let _ = vec![
host.name.clone(), host.name.clone(),
host.ip.clone().to_string(), host.ip.clone().to_string(),
e.to_string(), e.to_string(),

View File

@@ -10,14 +10,12 @@
use core::panic; use core::panic;
use std::{ use std::{
collections::HashMap, collections::HashMap,
hash::Hash,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
use anyhow::bail; use anyhow::bail;
use futures::future::join_all; use futures::future::join_all;
use mikrotik_rs::{Command, CommandBuilder, Event, MikrotikDevice}; use mikrotik_rs::{CommandBuilder, Event, MikrotikDevice};
use regex::Regex;
use crate::config::{Config, ConfigHost}; use crate::config::{Config, ConfigHost};
@@ -97,6 +95,7 @@ impl MtCommander {
}*/ }*/
} }
#[allow(dead_code)]
impl MtCommanderInternal { impl MtCommanderInternal {
fn new(cfg: Config) -> Self { fn new(cfg: Config) -> Self {
Self { cfg: Some(cfg) } Self { cfg: Some(cfg) }