summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGithub GPG acces <erdnaxela02@hotmail.fr>2024-03-15 13:18:50 +0100
committerGithub GPG acces <erdnaxela02@hotmail.fr>2024-03-15 13:18:50 +0100
commitff5b181d6c31d963efb981aa980bb49f90b0bf09 (patch)
treefdabef7f17a9102b75cd56634446057c681a4903
parentc591461fdefd87a58fdb4c220d8d3ca4c193081f (diff)
Add MQTT hostname configuration
added the possibility of configuring the hostname of the MQTT topic
-rwxr-xr-x[-rw-r--r--]docker-compose/glances.conf1
-rwxr-xr-x[-rw-r--r--]glances/exports/mqtt/__init__.py8
2 files changed, 7 insertions, 2 deletions
diff --git a/docker-compose/glances.conf b/docker-compose/glances.conf
index f07ff1c0..1aa17314 100644..100755
--- a/docker-compose/glances.conf
+++ b/docker-compose/glances.conf
@@ -595,6 +595,7 @@ queue=glances_queue
# Configuration for the --export mqtt option
host=localhost
port=8883
+hostname=NONE
tls=false
user=guest
password=guest
diff --git a/glances/exports/mqtt/__init__.py b/glances/exports/mqtt/__init__.py
index 9055fa6f..54d0a8f2 100644..100755
--- a/glances/exports/mqtt/__init__.py
+++ b/glances/exports/mqtt/__init__.py
@@ -38,13 +38,17 @@ class Export(GlancesExport):
# Load the MQTT configuration file
self.export_enable = self.load_conf(
- 'mqtt', mandatories=['host', 'password'], options=['port', 'user', 'topic', 'tls', 'topic_structure']
+ 'mqtt', mandatories=['host', 'password'], options=['port', 'user', 'hostname', 'topic', 'tls', 'topic_structure']
)
if not self.export_enable:
exit('Missing MQTT config')
# Get the current hostname
- self.hostname = socket.gethostname()
+ self.hostname = (self.hostname or socket.gethostname())
+ if self.hostname in ['NONE']:
+ self.hostname = socket.gethostname()
+ else:
+ self.hostname = self.hostname
self.port = int(self.port) or 8883
self.topic = self.topic or 'glances'
self.user = self.user or 'glances'