From 2fdc7b111d31006b568e820ee7aaa8290f5944b9 Mon Sep 17 00:00:00 2001 From: Hemna Date: Wed, 6 Nov 2024 08:43:25 -0500 Subject: [PATCH] Only load EmailStats if email is enabled This patch updates the stats collector to only register the EmailStats when the email plugin is enabled. --- aprsd/plugins/email.py | 6 ++++++ aprsd/stats/__init__.py | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/aprsd/plugins/email.py b/aprsd/plugins/email.py index 12657a1..b7cd526 100644 --- a/aprsd/plugins/email.py +++ b/aprsd/plugins/email.py @@ -12,6 +12,7 @@ import imapclient from oslo_config import cfg from aprsd import packets, plugin, threads, utils +from aprsd.stats import collector from aprsd.threads import tx from aprsd.utils import trace @@ -126,6 +127,11 @@ class EmailPlugin(plugin.APRSDRegexCommandPluginBase): shortcuts = _build_shortcuts_dict() LOG.info(f"Email shortcuts {shortcuts}") + + # Register the EmailStats producer with the stats collector + # We do this here to prevent EmailStats from being registered + # when email is not enabled in the config file. + collector.Collector().register_producer(EmailStats) else: LOG.info("Email services not enabled.") self.enabled = False diff --git a/aprsd/stats/__init__.py b/aprsd/stats/__init__.py index 2059a65..0e68df7 100644 --- a/aprsd/stats/__init__.py +++ b/aprsd/stats/__init__.py @@ -1,7 +1,6 @@ from aprsd import plugin from aprsd.client import stats as client_stats from aprsd.packets import packet_list, seen_list, tracker, watch_list -from aprsd.plugins import email from aprsd.stats import app, collector from aprsd.threads import aprsd @@ -15,6 +14,5 @@ stats_collector.register_producer(watch_list.WatchList) stats_collector.register_producer(tracker.PacketTrack) stats_collector.register_producer(plugin.PluginManager) stats_collector.register_producer(aprsd.APRSDThreadList) -stats_collector.register_producer(email.EmailStats) stats_collector.register_producer(client_stats.APRSClientStats) stats_collector.register_producer(seen_list.SeenList)