mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Added events module
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
use crate::device_finders::Device;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
pub fn trigger_new_device(device: Device) {
|
||||||
|
info!("Trigger - New device found: {}.", device);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn trigger_existing_device(existing_device: Device, new_device: Device) {
|
||||||
|
if existing_device.ipv4_address != new_device.ipv4_address {
|
||||||
|
info!(
|
||||||
|
"Trigger - Device with MAC {} changed IPv4 address from {} to {}.",
|
||||||
|
existing_device.mac_address, existing_device.ipv4_address, new_device.ipv4_address
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if existing_device.vendor != new_device.vendor {
|
||||||
|
info!(
|
||||||
|
"Trigger - Device with MAC {} changed vendor from {} to {}.",
|
||||||
|
existing_device.mac_address, existing_device.vendor, new_device.vendor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-5
@@ -4,6 +4,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
mod config;
|
mod config;
|
||||||
mod db;
|
mod db;
|
||||||
mod device_finders;
|
mod device_finders;
|
||||||
|
mod events;
|
||||||
mod mac_vendor_finder;
|
mod mac_vendor_finder;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -35,21 +36,22 @@ async fn main() -> Result<(), String> {
|
|||||||
match recorded_device_result {
|
match recorded_device_result {
|
||||||
Some(recorded_device) => {
|
Some(recorded_device) => {
|
||||||
// If it exists update its last seen date
|
// If it exists update its last seen date
|
||||||
info!(
|
debug!(
|
||||||
"Device found in database {}. Updating to {}.",
|
"Device found in database {}. Updating to {}.",
|
||||||
recorded_device, device
|
recorded_device, device
|
||||||
);
|
);
|
||||||
// TODO: If IPv4 or vendor changed do something
|
db::devices::update(db_conn_clone.lock().unwrap(), device.clone())?;
|
||||||
db::devices::update(db_conn_clone.lock().unwrap(), device.clone());
|
events::trigger_existing_device(recorded_device, device.clone());
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// If it doesn't exist insert it
|
// If it doesn't exist insert it
|
||||||
info!(
|
debug!(
|
||||||
"Device with MAC address {} not found in database. Inserting it.",
|
"Device with MAC address {} not found in database. Inserting it.",
|
||||||
device.mac_address
|
device.mac_address
|
||||||
);
|
);
|
||||||
|
|
||||||
db::devices::insert(db_conn_clone.lock().unwrap(), device.clone());
|
db::devices::insert(db_conn_clone.lock().unwrap(), device.clone())?;
|
||||||
|
events::trigger_new_device(device.clone());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user