mikrotik api improvements
This commit is contained in:
parent
5ecada7646
commit
8e8ea6426d
2 changed files with 35 additions and 4 deletions
|
|
@ -188,7 +188,14 @@ impl MikrotikClient {
|
||||||
// Build and send the command
|
// Build and send the command
|
||||||
let mut words = vec![command.to_string()];
|
let mut words = vec![command.to_string()];
|
||||||
for (key, value) in args {
|
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?;
|
self.send_sentence(&words).await?;
|
||||||
|
|
|
||||||
|
|
@ -548,6 +548,13 @@ async fn execute_mikrotik_job(
|
||||||
.map(|(k, v)| (k.as_str(), v.as_str()))
|
.map(|(k, v)| (k.as_str(), v.as_str()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
tracing::debug!(
|
||||||
|
"Executing MikroTik command '{}' with {} args: {:?}",
|
||||||
|
cmd.command,
|
||||||
|
args.len(),
|
||||||
|
args
|
||||||
|
);
|
||||||
|
|
||||||
match client.execute(&cmd.command, &args).await {
|
match client.execute(&cmd.command, &args).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
// Check for error in response
|
// Check for error in response
|
||||||
|
|
@ -561,10 +568,27 @@ async fn execute_mikrotik_job(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert sentences to protobuf format
|
tracing::debug!(
|
||||||
for sentence in response.sentences {
|
"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 {
|
all_sentences.push(MikrotikSentence {
|
||||||
attributes: sentence.attributes,
|
attributes: sentence.attributes.clone(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue