Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output json format in json timeline for standard output #1252

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-Japanese.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**改善:**

- `update-rules`コマンドを実行したときに、検知ルールが変更された場合にルール名を出力するようにした。以前は`modified:`フィールドを更新したルールだけが表示されていた。(#1243) (@hitenkoku)
- `json-timeline`コマンドの標準出力でJSONフォーマットを出力するように修正した。 (#1197) (@hitenkoku)
- JSON入力でデータが配列内にある場合に解析できるようにした。 (#1248) (@hitenkoku)

**バグ修正:**
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**Enhancements:**

- Any time there is a change in a detection rule, it will be displayed when running the `update-rules` command. Previously, only rules that updated their `modified:` field would be displayed. (#1243) (@hitenkoku)
- The `json-timeline` command now outputs in JSON format when outputting to the terminal. (#1197) (@hitenkoku)
- Added support for parsing JSON input when the data is inside an array. (#1248) (@hitenkoku)

**Bug Fixes:**
Expand Down
19 changes: 14 additions & 5 deletions src/afterfact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
time, detect_info.eventid
)));
}
if displayflag {
if displayflag && !(json_output_flag || jsonl_output_flag) {
// 標準出力の場合
if plus_header {
// ヘッダーのみを出力
Expand Down Expand Up @@ -431,10 +431,13 @@
);
prev_message = result.1;
prev_details_convert_map = detect_info.details_convert_map.clone();
wtr.write_field(format!("{{ {} }}", &result.0))?;
if displayflag {
write_color_buffer(&disp_wtr, None, &format!("{{ {} }}", &result.0), true).ok();
} else {

Check warning on line 436 in src/afterfact.rs

View check run for this annotation

Codecov / codecov/patch

src/afterfact.rs#L435-L436

Added lines #L435 - L436 were not covered by tests
wtr.write_field(format!("{{ {} }}", &result.0))?;
}
} else if json_output_flag {
// JSON output
wtr.write_field("{")?;
let result = output_json_str(
&detect_info.ext_field,
prev_message,
Expand All @@ -446,8 +449,14 @@
);
prev_message = result.1;
prev_details_convert_map = detect_info.details_convert_map.clone();
wtr.write_field(&result.0)?;
wtr.write_field("}")?;
if displayflag {
write_color_buffer(&disp_wtr, None, &format!("{{\n{}\n}}", &result.0), true)
.ok();
} else {

Check warning on line 455 in src/afterfact.rs

View check run for this annotation

Codecov / codecov/patch

src/afterfact.rs#L453-L455

Added lines #L453 - L455 were not covered by tests
wtr.write_field("{")?;
wtr.write_field(&result.0)?;
wtr.write_field("}")?;
}
} else {
// csv output format
if plus_header {
Expand Down