From 2e6bcc075888bd36e1787665bc9d3700cd4a8fc8 Mon Sep 17 00:00:00 2001 From: Github GPG acces Date: Fri, 15 Mar 2024 13:12:04 +0100 Subject: Add CallbackAPIversion for MQTT export Due to the recent update of paho-mqtt to V2.0.0 which requires API versioning, addition of callback_api_version in paho.Client --- glances/exports/mqtt/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glances/exports/mqtt/__init__.py b/glances/exports/mqtt/__init__.py index 9055fa6f..f29bd1b8 100644 --- a/glances/exports/mqtt/__init__.py +++ b/glances/exports/mqtt/__init__.py @@ -65,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(callback_api_version=2, client_id='glances_' + self.hostname, clean_session=False) client.username_pw_set(username=self.user, password=self.password) if self.tls: client.tls_set(certifi.where()) -- cgit v1.2.3 From 396283c9e96299075824815fb287921aa587b1aa Mon Sep 17 00:00:00 2001 From: Github GPG acces Date: Fri, 15 Mar 2024 21:58:05 +0100 Subject: Make 'callback_api_version' configurable --- docker-compose/glances.conf | 1 + glances/exports/mqtt/__init__.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docker-compose/glances.conf b/docker-compose/glances.conf index f07ff1c0..50066773 100644 --- a/docker-compose/glances.conf +++ b/docker-compose/glances.conf @@ -600,6 +600,7 @@ user=guest password=guest topic=glances topic_structure=per-metric +callback_api_version=2 [couchdb] # Configuration for the --export couchdb option diff --git a/glances/exports/mqtt/__init__.py b/glances/exports/mqtt/__init__.py index f29bd1b8..a9a9f6dd 100644 --- a/glances/exports/mqtt/__init__.py +++ b/glances/exports/mqtt/__init__.py @@ -38,7 +38,7 @@ 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', 'topic', 'tls', 'topic_structure', 'callback_api_version'] ) if not self.export_enable: exit('Missing MQTT config') @@ -61,11 +61,14 @@ class Export(GlancesExport): exit("MQTT client initialization failed") def init(self): + # Get the current callback api version + self.callback_api_version = int(self.callback_api_version) or 2 + """Init the connection to the MQTT server.""" if not self.export_enable: return None try: - client = paho.Client(callback_api_version=2, client_id='glances_' + self.hostname, clean_session=False) + client = paho.Client(self.callback_api_version, client_id='glances_' + self.hostname, clean_session=False) client.username_pw_set(username=self.user, password=self.password) if self.tls: client.tls_set(certifi.where()) -- cgit v1.2.3