Add hostname-aware MQTT topics
- Topics now default to systant/{hostname}/stats and systant/{hostname}/commands
- Runtime config automatically includes system hostname in topics
- NixOS module defaults use config.networking.hostName
- Supports multiple hosts without topic conflicts
- Environment variables can still override if needed
Example: systant/orion/stats, systant/server2/stats, etc.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+3
-3
@@ -6,10 +6,10 @@ config :systant, Systant.MqttClient,
|
||||
client_id: "systant",
|
||||
username: "mqtt",
|
||||
password: "pleasework",
|
||||
stats_topic: "system/stats",
|
||||
command_topic: "system/commands",
|
||||
stats_topic_base: "systant", # Will become systant/{hostname}/stats
|
||||
command_topic_base: "systant", # Will become systant/{hostname}/commands
|
||||
publish_interval: 30_000
|
||||
|
||||
config :logger, :console,
|
||||
format: "$time $metadata[$level] $message\n",
|
||||
metadata: [:request_id]
|
||||
metadata: [:request_id]
|
||||
|
||||
+8
-2
@@ -1,5 +1,11 @@
|
||||
import Config
|
||||
|
||||
# Get hostname for topic construction
|
||||
hostname = case :inet.gethostname() do
|
||||
{:ok, hostname} -> List.to_string(hostname)
|
||||
_ -> "unknown"
|
||||
end
|
||||
|
||||
# Runtime configuration that can use environment variables
|
||||
config :systant, Systant.MqttClient,
|
||||
host: System.get_env("SYSTANT_MQTT_HOST", "localhost"),
|
||||
@@ -7,6 +13,6 @@ config :systant, Systant.MqttClient,
|
||||
client_id: System.get_env("SYSTANT_CLIENT_ID", "systant"),
|
||||
username: System.get_env("SYSTANT_MQTT_USERNAME"),
|
||||
password: System.get_env("SYSTANT_MQTT_PASSWORD"),
|
||||
stats_topic: System.get_env("SYSTANT_STATS_TOPIC", "system/stats"),
|
||||
command_topic: System.get_env("SYSTANT_COMMAND_TOPIC", "system/commands"),
|
||||
stats_topic: System.get_env("SYSTANT_STATS_TOPIC", "systant/#{hostname}/stats"),
|
||||
command_topic: System.get_env("SYSTANT_COMMAND_TOPIC", "systant/#{hostname}/commands"),
|
||||
publish_interval: String.to_integer(System.get_env("SYSTANT_PUBLISH_INTERVAL", "30000"))
|
||||
Reference in New Issue
Block a user