Added notifications for devices that came back online after a

configurable time period
This commit is contained in:
rzuasti
2026-01-23 15:08:58 -05:00
parent ca1674243e
commit 92c1cd5553
4 changed files with 26 additions and 0 deletions
+1
View File
@@ -11,6 +11,7 @@ arp_scan_duration="60s"
[notifications] [notifications]
method="pushover" # For now just pushover method="pushover" # For now just pushover
notify_when_not_seen_for="30m" # Send a notification if a device comes back online after not being seen for this timeframe
[notifications.pushover] [notifications.pushover]
token="acxa8ouwj5iraswe8pupnpp12kmsm7" # Your pushover token goes here, just copy&paste from their website after creating the app token="acxa8ouwj5iraswe8pupnpp12kmsm7" # Your pushover token goes here, just copy&paste from their website after creating the app
+1
View File
@@ -11,6 +11,7 @@ arp_scan_duration="30s" # How long to wait for response packets on each scan (5m
[notifications] [notifications]
method="pushover" # For now just pushover, you can set this to "none" to avoid sending notifications (it will just log) method="pushover" # For now just pushover, you can set this to "none" to avoid sending notifications (it will just log)
notify_when_not_seen_for="1w" # Send a notification if a device comes back online after not being seen for this timeframe
[notifications.pushover] [notifications.pushover]
token="" # Your pushover token goes here, just copy&paste from their website after creating the app token="" # Your pushover token goes here, just copy&paste from their website after creating the app
+23
View File
@@ -1,6 +1,10 @@
mod pushover; mod pushover;
use std::time::Duration;
use crate::{device_finders::Device, settings::CONFIG}; use crate::{device_finders::Device, settings::CONFIG};
use chrono::Local;
use duration_string::DurationString;
use log::{debug, info, warn}; use log::{debug, info, warn};
// Private helper function to deliver messages // Private helper function to deliver messages
@@ -26,6 +30,25 @@ pub fn trigger_new_device(device: Device) -> Result<(), String> {
} }
pub fn trigger_existing_device(existing_device: Device, new_device: Device) -> Result<(), String> { pub fn trigger_existing_device(existing_device: Device, new_device: Device) -> Result<(), String> {
// Notify if the device comes back online after not being seen for the configured period
let elapsed_since_last_seen: Duration = (Local::now().naive_local()
- existing_device.last_seen)
.to_std()
.unwrap_or(Duration::from_secs(0));
if elapsed_since_last_seen >= Duration::from(CONFIG.notifications.notify_when_not_seen_for) {
send_message(format!(
"Device MAC {} - IP {} - Vendor {} came back online after {}.",
new_device.mac_address,
new_device.ipv4_address,
new_device.vendor,
String::from(DurationString::from(Duration::from_secs(
elapsed_since_last_seen.as_secs()
)))
))?;
}
// Notify if the devices vendor and/or IP changed
if (existing_device.ipv4_address != new_device.ipv4_address) if (existing_device.ipv4_address != new_device.ipv4_address)
&& (existing_device.vendor != new_device.vendor) && (existing_device.vendor != new_device.vendor)
{ {
+1
View File
@@ -34,6 +34,7 @@ pub struct Pushover {
pub struct Notifications { pub struct Notifications {
pub method: String, pub method: String,
pub pushover: Pushover, pub pushover: Pushover,
pub notify_when_not_seen_for: DurationString,
} }
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]