From 8e8ea6426d531f99cf347ae6ec2ddc45fc077372 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 2 Feb 2026 14:02:27 -0600 Subject: [PATCH] mikrotik api improvements --- src/mikrotik/client.rs | 9 ++++++++- src/websocket_client.rs | 30 +++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/mikrotik/client.rs b/src/mikrotik/client.rs index 266396e..14ca515 100644 --- a/src/mikrotik/client.rs +++ b/src/mikrotik/client.rs @@ -188,7 +188,14 @@ impl MikrotikClient { // Build and send the command let mut words = vec![command.to_string()]; for (key, value) in args { - words.push(format!("={}={}", key, value)); + // Query parameters use ? prefix, attributes use = prefix + if key.starts_with('?') || key.starts_with('.') { + // Query or special attribute - use as-is with = separator + words.push(format!("{}={}", key, value)); + } else { + // Regular attribute - prepend with = + words.push(format!("={}={}", key, value)); + } } self.send_sentence(&words).await?; diff --git a/src/websocket_client.rs b/src/websocket_client.rs index 4c43c13..67ffb7f 100644 --- a/src/websocket_client.rs +++ b/src/websocket_client.rs @@ -548,6 +548,13 @@ async fn execute_mikrotik_job( .map(|(k, v)| (k.as_str(), v.as_str())) .collect(); + tracing::debug!( + "Executing MikroTik command '{}' with {} args: {:?}", + cmd.command, + args.len(), + args + ); + match client.execute(&cmd.command, &args).await { Ok(response) => { // Check for error in response @@ -561,10 +568,27 @@ async fn execute_mikrotik_job( break; } - // Convert sentences to protobuf format - for sentence in response.sentences { + tracing::debug!( + "Command '{}' returned {} sentences", + cmd.command, + response.sentences.len() + ); + + // Convert sentences to protobuf format and log attribute keys + for (idx, sentence) in response.sentences.iter().enumerate() { + let attr_keys: Vec<&String> = sentence.attributes.keys().collect(); + let total_size: usize = sentence.attributes.values().map(|v| v.len()).sum(); + + tracing::debug!( + "Sentence {}: {} attributes ({} bytes total): {:?}", + idx, + sentence.attributes.len(), + total_size, + attr_keys + ); + all_sentences.push(MikrotikSentence { - attributes: sentence.attributes, + attributes: sentence.attributes.clone(), }); } }