From b8210b0fbe7ac2b5c6f7ae32529f74aa6771e2f4 Mon Sep 17 00:00:00 2001 From: agessaman Date: Tue, 14 Apr 2026 11:44:17 -0700 Subject: [PATCH] feat: enhance radio and admin configuration settings Added new configuration options for radio health monitoring and alerting in config.ini.example, including radio_offline_threshold, radio_offline_alert_enabled, and radio_offline_alert_email. Introduced an [Admin] section with settings for a local admin API, including enabled, port, and token fields. Updated related files to reflect these changes, improving the organization and functionality of the configuration structure. --- config.ini.example | 18 +++++++++++++++++- config.ini.minimal-example | 15 +++++++++++++++ config.ini.quickstart | 12 ++++++++++++ modules/core.py | 6 +++++- modules/scheduler.py | 12 ++++++++++-- 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/config.ini.example b/config.ini.example index e109265..f0c145c 100644 --- a/config.ini.example +++ b/config.ini.example @@ -50,6 +50,15 @@ radio_zombie_alert_enabled = false # Optional zombie alert recipients (comma-separated; empty = nightly recipients) radio_zombie_alert_email = +# Consecutive send timeouts before entering radio-offline state +radio_offline_threshold = 3 + +# Send immediate radio-offline alert email (uses Notifications SMTP settings) +radio_offline_alert_enabled = false + +# Optional radio-offline alert recipients (comma-separated; empty = nightly recipients) +radio_offline_alert_email = + [Bot] # Bot name for identification and logging bot_name = MeshCoreBot @@ -185,6 +194,13 @@ service_restart_backoff_seconds = 300 # Max seconds to wait for a channel message send before timing out (default: 30) send_timeout_seconds = 30 +[Admin] +# Local admin API (binds to 127.0.0.1) +enabled = false +port = 5001 +# Required when enabled +token = + [Channels] # Channels to monitor (comma-separated) # Bot will only respond to messages on these channels @@ -1718,7 +1734,7 @@ enabled = false # Channels to post alerts to (comma-separated). # Prefer this option if you want multiple channels. -channels = #general +channels = #mybotchannel # Fallback single channel option (used only when channels= is not set). # channel = #general diff --git a/config.ini.minimal-example b/config.ini.minimal-example index 1fb2f28..d44d315 100644 --- a/config.ini.minimal-example +++ b/config.ini.minimal-example @@ -48,6 +48,15 @@ serial_port = /dev/ttyUSB0 # Connection timeout in seconds timeout = 30 +# Radio health / alert defaults +radio_probe_interval_seconds = 300 +radio_probe_fail_threshold = 3 +radio_zombie_alert_enabled = false +radio_zombie_alert_email = +radio_offline_threshold = 3 +radio_offline_alert_enabled = false +radio_offline_alert_email = + [Bot] # Bot name for identification and logging bot_name = MeshCoreBot @@ -157,6 +166,12 @@ db_path = meshcore_bot.db # Local plugins directory (optional). Default: local. See config.ini.example. #local_dir_path = local +[Admin] +# Local admin API (127.0.0.1 only) +enabled = false +port = 5001 +token = + [Localization] # Language code for bot responses (en, es, es-MX, es-ES, fr, de, ja, etc.) # Default: en (English) diff --git a/config.ini.quickstart b/config.ini.quickstart index 2dc1e0a..fb0dba8 100644 --- a/config.ini.quickstart +++ b/config.ini.quickstart @@ -7,6 +7,13 @@ connection_type = serial serial_port = /dev/ttyUSB0 timeout = 30 +radio_probe_interval_seconds = 300 +radio_probe_fail_threshold = 3 +radio_zombie_alert_enabled = false +radio_zombie_alert_email = +radio_offline_threshold = 3 +radio_offline_alert_enabled = false +radio_offline_alert_email = [Bot] bot_name = MeshCoreBot @@ -19,6 +26,11 @@ bot_tx_rate_limit_seconds = 1.0 per_user_rate_limit_seconds = 30 per_user_rate_limit_enabled = true +[Admin] +enabled = false +port = 5001 +token = + [Channels] monitor_channels = general,test,emergency respond_to_dms = true diff --git a/modules/core.py b/modules/core.py index a242d3b..fffea1a 100644 --- a/modules/core.py +++ b/modules/core.py @@ -390,7 +390,11 @@ class MeshCoreBot: self._send_consecutive_failures: int = ( getattr(self, '_send_consecutive_failures', 0) + 1 ) - threshold = self.config.getint('Bot', 'radio_offline_threshold', fallback=3) + threshold = self.config.getint( + 'Connection', + 'radio_offline_threshold', + fallback=self.config.getint('Bot', 'radio_offline_threshold', fallback=3), + ) if self._send_consecutive_failures >= threshold and not self.is_radio_offline: self._radio_offline = True since = _dt.datetime.utcnow().isoformat() diff --git a/modules/scheduler.py b/modules/scheduler.py index 5b6eb4e..9ddbcca 100644 --- a/modules/scheduler.py +++ b/modules/scheduler.py @@ -1144,7 +1144,11 @@ class MessageScheduler: import ssl as _ssl from email.message import EmailMessage - alert_enabled = self.bot.config.getboolean('Bot', 'radio_offline_alert_enabled', fallback=True) + alert_enabled = self.bot.config.getboolean( + 'Connection', + 'radio_offline_alert_enabled', + fallback=self.bot.config.getboolean('Bot', 'radio_offline_alert_enabled', fallback=False), + ) if not alert_enabled: return @@ -1155,7 +1159,11 @@ class MessageScheduler: from_name = self._get_notif('from_name') or 'MeshCore Bot' from_email = self._get_notif('from_email') - alert_email_cfg = self.bot.config.get('Bot', 'radio_offline_alert_email', fallback='').strip() + alert_email_cfg = self.bot.config.get( + 'Connection', + 'radio_offline_alert_email', + fallback=self.bot.config.get('Bot', 'radio_offline_alert_email', fallback=''), + ).strip() if alert_email_cfg: recipients = [r.strip() for r in alert_email_cfg.split(',') if r.strip()] else: