From 6b996ac1e17be2143f652850b942d235d99d1cca Mon Sep 17 00:00:00 2001 From: Petr Krasnoshchekov Date: Tue, 20 Sep 2022 17:21:08 +0500 Subject: [PATCH 1/5] Support connection to Mosquitto through unix socket --- Jenkinsfile | 2 +- debian/changelog | 6 ++++++ debian/control | 2 +- wb-diag-collect.conf | 2 +- wb/diag/rpc_server.py | 20 +++++++++++++++----- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9732e2d..879aec3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1 +1 @@ -buildDebArchAll() +buildDebSbuild defaultTargets: 'bullseye-host' diff --git a/debian/changelog b/debian/changelog index ecf9ebc..4980beb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +wb-diag-collect (1.4.0) stable; urgency=medium + + * Support connection to Mosquitto through unix socket + + -- Petr Krasnoshchekov Tue, 20 Sep 2022 15:05:48 +0500 + wb-diag-collect (1.3.0) stable; urgency=medium * Add enum with "OK","OPERATION_ERROR","USER_INPUT_ERROR" result codes diff --git a/debian/control b/debian/control index 83b1c67..afc9573 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ X-Python3-Version: >= 3.2 Package: python3-wb-diag-collect Section: python Architecture: all -Depends: ${python3:Depends}, ${misc:Depends}, python3-yaml, python3-mqttrpc, python3-paho-mqtt, python3-wb-mcu-fw-updater, emmcparm (>= 5.0.0) +Depends: ${python3:Depends}, ${misc:Depends}, python3-yaml, python3-mqttrpc, python3-paho-mqtt, python3-paho-socket, python3-wb-mcu-fw-updater, emmcparm (>= 5.0.0), python3-urllib3 Description: python3 library for one-click diagnostic data collector for Wiren Board diff --git a/wb-diag-collect.conf b/wb-diag-collect.conf index ad1ea99..53d23d5 100644 --- a/wb-diag-collect.conf +++ b/wb-diag-collect.conf @@ -1,5 +1,5 @@ mqtt: - broker: '127.0.0.1' + broker: 'unix:///var/run/mosquitto/mosquitto.sock' port: 1883 journald_logs: diff --git a/wb/diag/rpc_server.py b/wb/diag/rpc_server.py index 491ba97..44fd8ed 100644 --- a/wb/diag/rpc_server.py +++ b/wb/diag/rpc_server.py @@ -3,9 +3,11 @@ import signal import subprocess from contextlib import contextmanager +import urllib from mqttrpc import MQTTRPCResponseManager, dispatcher from paho.mqtt import client as mqttclient +import paho_socket from wb.diag import collector @@ -20,11 +22,19 @@ def __init__(self, options, dispatcher, logger): self.dispatcher.add_method(self.diag) self.dispatcher.add_method(self.status) - self.client = mqttclient.Client("wb-diag-collect") - self.client.on_message = self.on_message - - logger.debug("Connecting to broker %s:%s", options["broker"], options["port"]) - self.client.connect(options["broker"], options["port"]) + broker = options["broker"] + url = urllib.parse.urlparse(broker) + if url.scheme == 'unix': + logger.debug("Connecting to broker %s", broker) + self.client = paho_socket.Client("wb-diag-collect") + self.client.on_message = self.on_message + self.client.sock_connect(url.netloc + url.path) + else: + port = options["port"] + logger.debug("Connecting to broker %s:%s", broker, port) + self.client = mqttclient.Client("wb-diag-collect") + self.client.on_message = self.on_message + self.client.connect(broker, port) self.run = True From 9b15f01a6e73fe1c3d41f4d66ef497b880d99f26 Mon Sep 17 00:00:00 2001 From: Petr Krasnoshchekov Date: Tue, 20 Sep 2022 17:25:11 +0500 Subject: [PATCH 2/5] Refactoring --- wb/diag/rpc_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wb/diag/rpc_server.py b/wb/diag/rpc_server.py index 44fd8ed..95d3554 100644 --- a/wb/diag/rpc_server.py +++ b/wb/diag/rpc_server.py @@ -28,7 +28,7 @@ def __init__(self, options, dispatcher, logger): logger.debug("Connecting to broker %s", broker) self.client = paho_socket.Client("wb-diag-collect") self.client.on_message = self.on_message - self.client.sock_connect(url.netloc + url.path) + self.client.sock_connect(url.path) else: port = options["port"] logger.debug("Connecting to broker %s:%s", broker, port) From f9600fc03de761f8ee3985b19f07dea0e804e60d Mon Sep 17 00:00:00 2001 From: Petr Krasnoshchekov Date: Tue, 20 Sep 2022 17:56:45 +0500 Subject: [PATCH 3/5] Fixes --- debian/control | 2 +- wb/diag/rpc_server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/control b/debian/control index afc9573..a06152e 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ X-Python3-Version: >= 3.2 Package: python3-wb-diag-collect Section: python Architecture: all -Depends: ${python3:Depends}, ${misc:Depends}, python3-yaml, python3-mqttrpc, python3-paho-mqtt, python3-paho-socket, python3-wb-mcu-fw-updater, emmcparm (>= 5.0.0), python3-urllib3 +Depends: ${python3:Depends}, ${misc:Depends}, python3-yaml, python3-mqttrpc, python3-paho-mqtt, python3-paho-socket, python3-wb-mcu-fw-updater, emmcparm (>= 5.0.0) Description: python3 library for one-click diagnostic data collector for Wiren Board diff --git a/wb/diag/rpc_server.py b/wb/diag/rpc_server.py index 95d3554..a4b9329 100644 --- a/wb/diag/rpc_server.py +++ b/wb/diag/rpc_server.py @@ -3,7 +3,7 @@ import signal import subprocess from contextlib import contextmanager -import urllib +import urllib.parse from mqttrpc import MQTTRPCResponseManager, dispatcher from paho.mqtt import client as mqttclient From f0ed86ca1658b39d4ef8057e3bb0535b2e79d2af Mon Sep 17 00:00:00 2001 From: Petr Krasnoshchekov Date: Tue, 20 Sep 2022 18:09:44 +0500 Subject: [PATCH 4/5] Remove port from config --- wb-diag-collect.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/wb-diag-collect.conf b/wb-diag-collect.conf index 53d23d5..5429a3b 100644 --- a/wb-diag-collect.conf +++ b/wb-diag-collect.conf @@ -1,6 +1,5 @@ mqtt: broker: 'unix:///var/run/mosquitto/mosquitto.sock' - port: 1883 journald_logs: lines_number: 1000 From ed0a48c2a316994ded886a6176a431e8653a02c2 Mon Sep 17 00:00:00 2001 From: Petr Krasnoshchekov Date: Wed, 21 Sep 2022 11:41:07 +0500 Subject: [PATCH 5/5] Version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e43d235..3e90ea0 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup(name='wb-diag-collect', - version='1.0', + version='1.4.0', description='Diagnostic collector', author='Sokolov Semen', author_email='s.sokolov@wirenboard.ru',