mirror of
https://github.com/craigerl/aprsd.git
synced 2025-08-01 13:12:26 -04:00
Compare commits
5 Commits
6e62ac14b8
...
98a62102b7
Author | SHA1 | Date | |
---|---|---|---|
98a62102b7 | |||
7d1e739502 | |||
bd0bcc1924 | |||
adcf94d8c7 | |||
9f3c8f889f |
@ -126,7 +126,10 @@ class APRSISClient(base.APRSClient):
|
|||||||
return aprs_client
|
return aprs_client
|
||||||
|
|
||||||
def consumer(self, callback, blocking=False, immortal=False, raw=False):
|
def consumer(self, callback, blocking=False, immortal=False, raw=False):
|
||||||
self._client.consumer(
|
try:
|
||||||
callback, blocking=blocking,
|
self._client.consumer(
|
||||||
immortal=immortal, raw=raw,
|
callback, blocking=blocking,
|
||||||
)
|
immortal=immortal, raw=raw,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
LOG.error(f"Exception in consumer: {e}")
|
||||||
|
@ -193,14 +193,14 @@ class Aprsdis(aprslib.IS):
|
|||||||
except ParseError as exp:
|
except ParseError as exp:
|
||||||
self.logger.log(
|
self.logger.log(
|
||||||
11,
|
11,
|
||||||
"%s\n Packet: %s",
|
"%s Packet: '%s'",
|
||||||
exp,
|
exp,
|
||||||
exp.packet,
|
exp.packet,
|
||||||
)
|
)
|
||||||
except UnknownFormat as exp:
|
except UnknownFormat as exp:
|
||||||
self.logger.log(
|
self.logger.log(
|
||||||
9,
|
9,
|
||||||
"%s\n Packet: %s",
|
"%s Packet: '%s'",
|
||||||
exp,
|
exp,
|
||||||
exp.packet,
|
exp.packet,
|
||||||
)
|
)
|
||||||
|
@ -50,12 +50,16 @@ def signal_handler(sig, frame):
|
|||||||
|
|
||||||
|
|
||||||
class APRSDListenThread(rx.APRSDRXThread):
|
class APRSDListenThread(rx.APRSDRXThread):
|
||||||
def __init__(self, packet_queue, packet_filter=None, plugin_manager=None):
|
def __init__(
|
||||||
|
self, packet_queue, packet_filter=None, plugin_manager=None,
|
||||||
|
enabled_plugins=[], log_packets=False,
|
||||||
|
):
|
||||||
super().__init__(packet_queue)
|
super().__init__(packet_queue)
|
||||||
self.packet_filter = packet_filter
|
self.packet_filter = packet_filter
|
||||||
self.plugin_manager = plugin_manager
|
self.plugin_manager = plugin_manager
|
||||||
if self.plugin_manager:
|
if self.plugin_manager:
|
||||||
LOG.info(f"Plugins {self.plugin_manager.get_message_plugins()}")
|
LOG.info(f"Plugins {self.plugin_manager.get_message_plugins()}")
|
||||||
|
self.log_packets = log_packets
|
||||||
|
|
||||||
def process_packet(self, *args, **kwargs):
|
def process_packet(self, *args, **kwargs):
|
||||||
packet = self._client.decode_packet(*args, **kwargs)
|
packet = self._client.decode_packet(*args, **kwargs)
|
||||||
@ -76,13 +80,16 @@ class APRSDListenThread(rx.APRSDRXThread):
|
|||||||
if self.packet_filter:
|
if self.packet_filter:
|
||||||
filter_class = filters[self.packet_filter]
|
filter_class = filters[self.packet_filter]
|
||||||
if isinstance(packet, filter_class):
|
if isinstance(packet, filter_class):
|
||||||
packet_log.log(packet)
|
if self.log_packets:
|
||||||
|
packet_log.log(packet)
|
||||||
if self.plugin_manager:
|
if self.plugin_manager:
|
||||||
# Don't do anything with the reply
|
# Don't do anything with the reply
|
||||||
# This is the listen only command.
|
# This is the listen only command.
|
||||||
self.plugin_manager.run(packet)
|
self.plugin_manager.run(packet)
|
||||||
else:
|
else:
|
||||||
packet_log.log(packet)
|
if self.log_packets:
|
||||||
|
LOG.error("PISS")
|
||||||
|
packet_log.log(packet)
|
||||||
if self.plugin_manager:
|
if self.plugin_manager:
|
||||||
# Don't do anything with the reply.
|
# Don't do anything with the reply.
|
||||||
# This is the listen only command.
|
# This is the listen only command.
|
||||||
@ -95,7 +102,7 @@ class ListenStatsThread(APRSDThread):
|
|||||||
"""Log the stats from the PacketList."""
|
"""Log the stats from the PacketList."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__("SimpleStatsLog")
|
super().__init__("PacketStatsLog")
|
||||||
self._last_total_rx = 0
|
self._last_total_rx = 0
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
@ -161,6 +168,11 @@ class ListenStatsThread(APRSDThread):
|
|||||||
),
|
),
|
||||||
help="Filter by packet type",
|
help="Filter by packet type",
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--enable-plugin",
|
||||||
|
multiple=True,
|
||||||
|
help="Enable a plugin. This is the name of the file in the plugins directory.",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
"--load-plugins",
|
"--load-plugins",
|
||||||
default=False,
|
default=False,
|
||||||
@ -172,6 +184,18 @@ class ListenStatsThread(APRSDThread):
|
|||||||
nargs=-1,
|
nargs=-1,
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--log-packets",
|
||||||
|
default=False,
|
||||||
|
is_flag=True,
|
||||||
|
help="Log incoming packets.",
|
||||||
|
)
|
||||||
|
@click.option(
|
||||||
|
"--enable-packet-stats",
|
||||||
|
default=False,
|
||||||
|
is_flag=True,
|
||||||
|
help="Enable packet stats periodic logging.",
|
||||||
|
)
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@cli_helper.process_standard_options
|
@cli_helper.process_standard_options
|
||||||
def listen(
|
def listen(
|
||||||
@ -179,8 +203,11 @@ def listen(
|
|||||||
aprs_login,
|
aprs_login,
|
||||||
aprs_password,
|
aprs_password,
|
||||||
packet_filter,
|
packet_filter,
|
||||||
|
enable_plugin,
|
||||||
load_plugins,
|
load_plugins,
|
||||||
filter,
|
filter,
|
||||||
|
log_packets,
|
||||||
|
enable_packet_stats,
|
||||||
):
|
):
|
||||||
"""Listen to packets on the APRS-IS Network based on FILTER.
|
"""Listen to packets on the APRS-IS Network based on FILTER.
|
||||||
|
|
||||||
@ -240,15 +267,26 @@ def listen(
|
|||||||
packet_collector.PacketCollector().unregister(seen_list.SeenList)
|
packet_collector.PacketCollector().unregister(seen_list.SeenList)
|
||||||
|
|
||||||
pm = None
|
pm = None
|
||||||
pm = plugin.PluginManager()
|
|
||||||
if load_plugins:
|
if load_plugins:
|
||||||
|
pm = plugin.PluginManager()
|
||||||
LOG.info("Loading plugins")
|
LOG.info("Loading plugins")
|
||||||
pm.setup_plugins(load_help_plugin=False)
|
pm.setup_plugins(load_help_plugin=False)
|
||||||
|
elif enable_plugin:
|
||||||
|
pm = plugin.PluginManager()
|
||||||
|
pm.setup_plugins(
|
||||||
|
load_help_plugin=False,
|
||||||
|
plugin_list=enable_plugin,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
LOG.warning(
|
LOG.warning(
|
||||||
"Not Loading any plugins use --load-plugins to load what's "
|
"Not Loading any plugins use --load-plugins to load what's "
|
||||||
"defined in the config file.",
|
"defined in the config file.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if pm:
|
||||||
|
for p in pm.get_plugins():
|
||||||
|
LOG.info("Loaded plugin %s", p.__class__.__name__)
|
||||||
|
|
||||||
stats = stats_thread.APRSDStatsStoreThread()
|
stats = stats_thread.APRSDStatsStoreThread()
|
||||||
stats.start()
|
stats.start()
|
||||||
|
|
||||||
@ -257,11 +295,14 @@ def listen(
|
|||||||
packet_queue=threads.packet_queue,
|
packet_queue=threads.packet_queue,
|
||||||
packet_filter=packet_filter,
|
packet_filter=packet_filter,
|
||||||
plugin_manager=pm,
|
plugin_manager=pm,
|
||||||
|
enabled_plugins=enable_plugin,
|
||||||
|
log_packets=log_packets,
|
||||||
)
|
)
|
||||||
LOG.debug("Start APRSDListenThread")
|
LOG.debug("Start APRSDListenThread")
|
||||||
listen_thread.start()
|
listen_thread.start()
|
||||||
listen_stats = ListenStatsThread()
|
if enable_packet_stats:
|
||||||
listen_stats.start()
|
listen_stats = ListenStatsThread()
|
||||||
|
listen_stats.start()
|
||||||
|
|
||||||
keepalive.start()
|
keepalive.start()
|
||||||
LOG.debug("keepalive Join")
|
LOG.debug("keepalive Join")
|
||||||
|
@ -472,7 +472,10 @@ class PluginManager:
|
|||||||
del self._pluggy_pm
|
del self._pluggy_pm
|
||||||
self.setup_plugins()
|
self.setup_plugins()
|
||||||
|
|
||||||
def setup_plugins(self, load_help_plugin=True):
|
def setup_plugins(
|
||||||
|
self, load_help_plugin=True,
|
||||||
|
plugin_list=[],
|
||||||
|
):
|
||||||
"""Create the plugin manager and register plugins."""
|
"""Create the plugin manager and register plugins."""
|
||||||
|
|
||||||
LOG.info("Loading APRSD Plugins")
|
LOG.info("Loading APRSD Plugins")
|
||||||
@ -481,9 +484,13 @@ class PluginManager:
|
|||||||
_help = HelpPlugin()
|
_help = HelpPlugin()
|
||||||
self._pluggy_pm.register(_help)
|
self._pluggy_pm.register(_help)
|
||||||
|
|
||||||
enabled_plugins = CONF.enabled_plugins
|
# if plugins_list is passed in, only load
|
||||||
if enabled_plugins:
|
# those plugins.
|
||||||
for p_name in enabled_plugins:
|
if plugin_list:
|
||||||
|
for plugin_name in plugin_list:
|
||||||
|
self._load_plugin(plugin_name)
|
||||||
|
elif CONF.enabled_plugins:
|
||||||
|
for p_name in CONF.enabled_plugins:
|
||||||
self._load_plugin(p_name)
|
self._load_plugin(p_name)
|
||||||
else:
|
else:
|
||||||
# Enabled plugins isn't set, so we default to loading all of
|
# Enabled plugins isn't set, so we default to loading all of
|
||||||
|
@ -10,7 +10,7 @@ LOG = logging.getLogger("APRSD")
|
|||||||
@runtime_checkable
|
@runtime_checkable
|
||||||
class StatsProducer(Protocol):
|
class StatsProducer(Protocol):
|
||||||
"""The StatsProducer protocol is used to define the interface for collecting stats."""
|
"""The StatsProducer protocol is used to define the interface for collecting stats."""
|
||||||
def stats(self, serializeable=False) -> dict:
|
def stats(self, serializable=False) -> dict:
|
||||||
"""provide stats in a dictionary format."""
|
"""provide stats in a dictionary format."""
|
||||||
...
|
...
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user