2021-07-14 20:50:41 -04:00
|
|
|
import logging
|
|
|
|
|
2022-12-16 14:04:08 -05:00
|
|
|
from aprsd import packets, plugin
|
2021-07-14 20:50:41 -04:00
|
|
|
|
2021-08-23 12:14:19 -04:00
|
|
|
|
2021-07-14 20:50:41 -04:00
|
|
|
LOG = logging.getLogger("APRSD")
|
|
|
|
|
|
|
|
|
2021-08-19 11:39:29 -04:00
|
|
|
class NotifySeenPlugin(plugin.APRSDWatchListPluginBase):
|
2021-07-17 14:30:29 -04:00
|
|
|
"""Notification plugin to send seen message for callsign.
|
|
|
|
|
|
|
|
|
|
|
|
This plugin will track callsigns in the watch list and report
|
|
|
|
when a callsign has been seen when the last time they were
|
|
|
|
seen was older than the configured age limit.
|
|
|
|
"""
|
2021-07-14 20:50:41 -04:00
|
|
|
|
2021-11-12 11:36:22 -05:00
|
|
|
short_description = "Notify me when a CALLSIGN is recently seen on APRS-IS"
|
2021-07-14 20:50:41 -04:00
|
|
|
|
2022-12-14 22:03:21 -05:00
|
|
|
def process(self, packet: packets.MessagePacket):
|
2021-10-06 12:08:29 -04:00
|
|
|
LOG.info("NotifySeenPlugin")
|
2021-07-14 20:50:41 -04:00
|
|
|
|
|
|
|
notify_callsign = self.config["aprsd"]["watch_list"]["alert_callsign"]
|
2022-12-14 22:03:21 -05:00
|
|
|
fromcall = packet.from_call
|
2021-07-14 20:50:41 -04:00
|
|
|
|
2021-07-17 14:30:29 -04:00
|
|
|
wl = packets.WatchList()
|
|
|
|
age = wl.age(fromcall)
|
|
|
|
|
2022-12-14 22:03:21 -05:00
|
|
|
if wl.is_old(fromcall):
|
2021-07-17 14:30:29 -04:00
|
|
|
LOG.info(
|
|
|
|
"NOTIFY {} last seen {} max age={}".format(
|
|
|
|
fromcall,
|
|
|
|
age,
|
|
|
|
wl.max_delta(),
|
|
|
|
),
|
|
|
|
)
|
2022-12-16 14:04:08 -05:00
|
|
|
packet_type = packet.__class__.__name__
|
2021-07-17 14:30:29 -04:00
|
|
|
# we shouldn't notify the alert user that they are online.
|
|
|
|
if fromcall != notify_callsign:
|
2022-12-16 14:04:08 -05:00
|
|
|
pkt = packets.MessagePacket(
|
|
|
|
from_call=self.config["aprsd"]["callsign"],
|
|
|
|
to_call=notify_callsign,
|
|
|
|
message_text=(
|
|
|
|
f"{fromcall} was just seen by type:'{packet_type}'"
|
|
|
|
),
|
2022-12-17 18:00:26 -05:00
|
|
|
allow_delay=False,
|
2021-12-06 14:11:34 -05:00
|
|
|
)
|
2022-12-17 18:00:26 -05:00
|
|
|
# pkt.allow_delay = False
|
2022-12-16 14:04:08 -05:00
|
|
|
return pkt
|
2021-12-07 11:25:14 -05:00
|
|
|
else:
|
2021-12-10 14:20:57 -05:00
|
|
|
LOG.debug("fromcall and notify_callsign are the same, not notifying")
|
2022-12-16 14:04:08 -05:00
|
|
|
return packets.NULL_MESSAGE
|
2021-07-17 14:30:29 -04:00
|
|
|
else:
|
|
|
|
LOG.debug(
|
2021-12-10 14:20:57 -05:00
|
|
|
"Not old enough to notify on callsign '{}' : {} < {}".format(
|
2021-07-17 14:30:29 -04:00
|
|
|
fromcall,
|
|
|
|
age,
|
|
|
|
wl.max_delta(),
|
|
|
|
),
|
|
|
|
)
|
2022-12-16 14:04:08 -05:00
|
|
|
return packets.NULL_MESSAGE
|