Skip to content

Commit ca12d2b

Browse files
committed
suricatasc: implement datajson commands
1 parent 3b0cb38 commit ca12d2b

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

rust/suricatasc/src/unix/commands.rs

+47-2
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ impl<'a> CommandParser<'a> {
7171
}
7272

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

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

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

95101
let mut json_args = HashMap::new();
96102

@@ -386,6 +392,45 @@ fn command_defs() -> Result<HashMap<String, Vec<Argument>>, serde_json::Error> {
386392
"type": "string",
387393
},
388394
],
395+
"datajson-add": [
396+
{
397+
"name": "setname",
398+
"required": true,
399+
"type": "string",
400+
},
401+
{
402+
"name": "settype",
403+
"required": true,
404+
"type": "string",
405+
},
406+
{
407+
"name": "datavalue",
408+
"required": true,
409+
"type": "string",
410+
},
411+
{
412+
"name": "datajson",
413+
"required": true,
414+
"type": "string",
415+
},
416+
],
417+
"datajson-remove": [
418+
{
419+
"name": "setname",
420+
"required": true,
421+
"type": "string",
422+
},
423+
{
424+
"name": "settype",
425+
"required": true,
426+
"type": "string",
427+
},
428+
{
429+
"name": "datavalue",
430+
"required": true,
431+
"type": "string",
432+
},
433+
],
389434
"get-flow-stats-by-id": [
390435
{
391436
"name": "flow_id",

0 commit comments

Comments
 (0)