Skip to content

Commit

Permalink
suricatasc: implement datajson commands
Browse files Browse the repository at this point in the history
  • Loading branch information
regit committed Mar 2, 2025
1 parent f8335bb commit 1e62200
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions rust/suricatasc/src/unix/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ impl<'a> CommandParser<'a> {
}

pub fn parse(&self, input: &str) -> Result<serde_json::Value, CommandParseError> {
let parts: Vec<&str> = input.split(' ').map(|s| s.trim()).collect();
let mut parts: Vec<&str> = input.split(' ').map(|s| s.trim()).collect();
if parts.is_empty() {
return Err(CommandParseError::Other("No command provided".to_string()));
}
let command = parts[0];
let args = &parts[1..];

let spec = self
.commands
Expand All @@ -91,6 +90,13 @@ impl<'a> CommandParser<'a> {

// Calculate the number of required arguments for better error reporting.
let required = spec.iter().filter(|e| e.required).count();
let optional = spec.iter().filter(|e| !e.required).count();
// Handle the case where the command has only required arguments and allow
// last one to contain spaces.
if optional == 0 {
parts = input.splitn(required + 1, ' ').map(|s| s).collect();
}
let args = &parts[1..];

let mut json_args = HashMap::new();

Expand Down Expand Up @@ -386,6 +392,45 @@ fn command_defs() -> Result<HashMap<String, Vec<Argument>>, serde_json::Error> {
"type": "string",
},
],
"datajson-add": [
{
"name": "setname",
"required": true,
"type": "string",
},
{
"name": "settype",
"required": true,
"type": "string",
},
{
"name": "datavalue",
"required": true,
"type": "string",
},
{
"name": "datajson",
"required": true,
"type": "string",
},
],
"datajson-remove": [
{
"name": "setname",
"required": true,
"type": "string",
},
{
"name": "settype",
"required": true,
"type": "string",
},
{
"name": "datavalue",
"required": true,
"type": "string",
},
],
"get-flow-stats-by-id": [
{
"name": "flow_id",
Expand Down

0 comments on commit 1e62200

Please sign in to comment.