Add MQTT hostname configuration

added the possibility of configuring the hostname of the MQTT topic
This commit is contained in:
Github GPG acces 2024-03-15 13:18:50 +01:00
parent c591461fde
commit ff5b181d6c
No known key found for this signature in database
GPG Key ID: 384AAACE61391474
2 changed files with 7 additions and 2 deletions

1
docker-compose/glances.conf Normal file → Executable file
View File

@ -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

8
glances/exports/mqtt/__init__.py Normal file → Executable file
View File

@ -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'