mirror of
https://github.com/tcivie/meshtastic-metrics-exporter.git
synced 2025-03-05 20:52:02 -08:00
Bugfix (Fixed issue with unknown json data configuration)
This commit is contained in:
parent
0b8bd8e025
commit
e155aeaeae
|
@ -86,6 +86,8 @@ CREATE TABLE IF NOT EXISTS node_configurations
|
||||||
-- Configuration (MQTT)
|
-- Configuration (MQTT)
|
||||||
mqtt_encryption_enabled BOOLEAN DEFAULT FALSE,
|
mqtt_encryption_enabled BOOLEAN DEFAULT FALSE,
|
||||||
mqtt_json_enabled BOOLEAN DEFAULT FALSE,
|
mqtt_json_enabled BOOLEAN DEFAULT FALSE,
|
||||||
|
mqtt_json_message_timestamp TIMESTAMP DEFAULT NOW(),
|
||||||
|
|
||||||
mqtt_configured_root_topic TEXT DEFAULT '',
|
mqtt_configured_root_topic TEXT DEFAULT '',
|
||||||
mqtt_info_last_timestamp TIMESTAMP DEFAULT NOW(),
|
mqtt_info_last_timestamp TIMESTAMP DEFAULT NOW(),
|
||||||
|
|
||||||
|
|
|
@ -187,11 +187,28 @@ class NodeConfigurationMetrics(metaclass=Singleton):
|
||||||
self.db.execute_db_operation(db_operation)
|
self.db.execute_db_operation(db_operation)
|
||||||
|
|
||||||
def process_mqtt_update(self, node_id: str, mqtt_encryption_enabled=None, mqtt_json_enabled=None,
|
def process_mqtt_update(self, node_id: str, mqtt_encryption_enabled=None, mqtt_json_enabled=None,
|
||||||
mqtt_configured_root_topic=None):
|
mqtt_configured_root_topic=None, is_json_message=False):
|
||||||
if not self.report:
|
if not self.report:
|
||||||
return
|
return
|
||||||
|
|
||||||
def db_operation(cur, conn):
|
def db_operation(cur, conn):
|
||||||
|
# Update the last MQTT message timestamp for every message
|
||||||
|
cur.execute("""
|
||||||
|
UPDATE node_configurations
|
||||||
|
SET mqtt_info_last_timestamp = NOW()
|
||||||
|
WHERE node_id = %s
|
||||||
|
""", (node_id,))
|
||||||
|
|
||||||
|
# If it's a JSON message, update the JSON message timestamp
|
||||||
|
if is_json_message:
|
||||||
|
cur.execute("""
|
||||||
|
UPDATE node_configurations
|
||||||
|
SET mqtt_json_message_timestamp = NOW(),
|
||||||
|
mqtt_json_enabled = TRUE
|
||||||
|
WHERE node_id = %s
|
||||||
|
""", (node_id,))
|
||||||
|
|
||||||
|
# Perform the main update
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
INSERT INTO node_configurations (
|
INSERT INTO node_configurations (
|
||||||
node_id,
|
node_id,
|
||||||
|
@ -203,9 +220,14 @@ class NodeConfigurationMetrics(metaclass=Singleton):
|
||||||
ON CONFLICT(node_id)
|
ON CONFLICT(node_id)
|
||||||
DO UPDATE SET
|
DO UPDATE SET
|
||||||
mqtt_encryption_enabled = COALESCE(EXCLUDED.mqtt_encryption_enabled, node_configurations.mqtt_encryption_enabled),
|
mqtt_encryption_enabled = COALESCE(EXCLUDED.mqtt_encryption_enabled, node_configurations.mqtt_encryption_enabled),
|
||||||
mqtt_json_enabled = COALESCE(EXCLUDED.mqtt_json_enabled, node_configurations.mqtt_json_enabled),
|
mqtt_json_enabled = CASE
|
||||||
|
WHEN (node_configurations.mqtt_info_last_timestamp - node_configurations.mqtt_json_message_timestamp) > INTERVAL '1 hour'
|
||||||
|
THEN FALSE
|
||||||
|
ELSE COALESCE(EXCLUDED.mqtt_json_enabled, node_configurations.mqtt_json_enabled)
|
||||||
|
END,
|
||||||
mqtt_configured_root_topic = COALESCE(EXCLUDED.mqtt_configured_root_topic, node_configurations.mqtt_configured_root_topic),
|
mqtt_configured_root_topic = COALESCE(EXCLUDED.mqtt_configured_root_topic, node_configurations.mqtt_configured_root_topic),
|
||||||
mqtt_info_last_timestamp = NOW()
|
mqtt_info_last_timestamp = NOW()
|
||||||
|
RETURNING mqtt_json_enabled
|
||||||
""", (node_id, mqtt_encryption_enabled, mqtt_json_enabled, mqtt_configured_root_topic))
|
""", (node_id, mqtt_encryption_enabled, mqtt_json_enabled, mqtt_configured_root_topic))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,7 @@ class MessageProcessor:
|
||||||
gateway_node_id = str(int(json_packet['sender'][1:], 16))
|
gateway_node_id = str(int(json_packet['sender'][1:], 16))
|
||||||
NodeConfigurationMetrics().process_mqtt_update(
|
NodeConfigurationMetrics().process_mqtt_update(
|
||||||
node_id=gateway_node_id,
|
node_id=gateway_node_id,
|
||||||
|
mqtt_json_enabled=True,
|
||||||
mqtt_encryption_enabled=json_packet.get('encrypted', False),
|
mqtt_encryption_enabled=json_packet.get('encrypted', False),
|
||||||
mqtt_configured_root_topic=topic
|
mqtt_configured_root_topic=topic
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue