From 4d91a3f6cea9337f1571e486c7aca0aff7399889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 6 Aug 2020 17:48:06 +0200 Subject: [PATCH] more logging --- src/app.py | 4 ++++ src/mqtt_helper.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/app.py b/src/app.py index 579373f..843b15c 100644 --- a/src/app.py +++ b/src/app.py @@ -35,6 +35,7 @@ if config.SENTRY_DSN: def setup_rabbit() -> None: + logging.info("Connecting to RabbitMQ") credentials = pika.PlainCredentials(config.RABBIT_USERNAME, config.RABBIT_PASSWORD) connection = pika.BlockingConnection(pika.ConnectionParameters(host=config.RABBIT_HOSTNAME, credentials=credentials, @@ -49,6 +50,7 @@ def setup_rabbit() -> None: exclusive=True).method.queue channel.queue_bind(exchange=config.RABBIT_EXCHANGE, queue=queue) channel.basic_consume(queue=queue, on_message_callback=on_message, auto_ack=True) + logging.debug("Starting consumption") channel.start_consuming() @@ -61,11 +63,13 @@ def on_message(channel, method_frame, header_frame, body): r.raise_for_status() if 'device_id' not in r.json(): logging.error("Input-service response invalid") + logging.info(f"Sending alert command to device {r.json()['device_id']}") mqtt.publish(subtopic=r.json()['device_id'], message=json.dumps({"command": "doAlert"})) if __name__ == "__main__": + logging.info("Guard service starting") mqtt = MQTT() mqtt.topic = config.MQTT_TOPIC mqtt.connect() diff --git a/src/mqtt_helper.py b/src/mqtt_helper.py index 9b1ed93..33f6930 100644 --- a/src/mqtt_helper.py +++ b/src/mqtt_helper.py @@ -58,6 +58,7 @@ class MQTT: Setup client and connect to broker :return: """ + logging.info("Connecting to MQTT") self.client = mqtt.Client(client_id=self.client_id, clean_session=True, userdata=None, protocol=mqtt.MQTTv311, transport="tcp") self.port = int(self.port) @@ -70,6 +71,7 @@ class MQTT: :param subtopic: :return: """ + logging.debug(f"MQTT Topic: {self.topic}/{subtopic} Message: {message} QOS: {self.qos} Retain: {self.retain}") if subtopic: self.client.publish(f"{self.topic}/{subtopic}", message, qos=self.qos, retain=self.retain) else: