mikrotik api improvements

This commit is contained in:
Graham McIntire 2026-02-02 14:02:27 -06:00
parent 5ecada7646
commit 8e8ea6426d
No known key found for this signature in database
2 changed files with 35 additions and 4 deletions

View file

@ -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?;

View file

@ -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(),
});
}
}