diff options
-rwxr-xr-x | docker-compose/glances.conf | 1 | ||||
-rwxr-xr-x | glances/exports/mqtt/__init__.py | 14 |
2 files changed, 5 insertions, 10 deletions
diff --git a/docker-compose/glances.conf b/docker-compose/glances.conf index 1aa17314..f07ff1c0 100755 --- a/docker-compose/glances.conf +++ b/docker-compose/glances.conf @@ -595,7 +595,6 @@ 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 54d0a8f2..8563ccdd 100755 --- a/glances/exports/mqtt/__init__.py +++ b/glances/exports/mqtt/__init__.py @@ -38,17 +38,13 @@ class Export(GlancesExport): # Load the MQTT configuration file self.export_enable = self.load_conf( - 'mqtt', mandatories=['host', 'password'], options=['port', 'user', 'hostname', 'topic', 'tls', 'topic_structure'] + 'mqtt', mandatories=['host', 'password'], options=['port', 'user', 'devicename', 'topic', 'tls', 'topic_structure'] ) if not self.export_enable: exit('Missing MQTT config') # Get the current hostname - self.hostname = (self.hostname or socket.gethostname()) - if self.hostname in ['NONE']: - self.hostname = socket.gethostname() - else: - self.hostname = self.hostname + self.devicename = self.devicename or socket.gethostname() self.port = int(self.port) or 8883 self.topic = self.topic or 'glances' self.user = self.user or 'glances' @@ -69,7 +65,7 @@ class Export(GlancesExport): if not self.export_enable: return None try: - client = paho.Client(client_id='glances_' + self.hostname, clean_session=False) + client = paho.Client(client_id='glances_' + self.devicename, clean_session=False) client.username_pw_set(username=self.user, password=self.password) if self.tls: client.tls_set(certifi.where()) @@ -93,7 +89,7 @@ class Export(GlancesExport): for sensor, value in zip(columns, points): try: sensor = [whitelisted(name) for name in sensor.split('.')] - to_export = [self.topic, self.hostname, name] + to_export = [self.topic, self.devicename, name] to_export.extend(sensor) topic = '/'.join(to_export) @@ -102,7 +98,7 @@ class Export(GlancesExport): logger.error("Can not export stats to MQTT server (%s)" % e) elif self.topic_structure == 'per-plugin': try: - topic = '/'.join([self.topic, self.hostname, name]) + topic = '/'.join([self.topic, self.devicename, name]) sensor_values = dict(zip(columns, points)) # Build the value to output |