Merge pull request #659 from Yamato-Security/658-output-percentage-of-detections-in-results-summary

Added output percentage of detections in results summary
This commit is contained in:
DustInDark
2022-08-12 02:22:19 +09:00
committed by GitHub
3 changed files with 12 additions and 6 deletions

View File

@@ -12,6 +12,7 @@
- ルールのアップデート機能のルールパスの出力から./を削除した。 (#642) (@hitenkoku)
- MITRE ATT&CK関連のタグとその他タグを出力するための出力用のエイリアスを追加した。 (#637) (@hitenkoku)
- 結果概要の数値をカンマをつけて見やすくした。 (#649) (@hitenkoku)
- 結果概要内の検知数にパーセント表示を追加した。 (#658) (@hitenkoku)
**バグ修正:**

View File

@@ -12,6 +12,7 @@
- Removed ./ from rule path when updating. (#642) (@hitenkoku)
- Added new output alias for MITRE ATT&CK tags and other tags. (#637) (@hitenkoku)
- Added commas to summary numbers to make them easier to read. (#649) (@hitenkoku)
- Added output percentage of detections in Result Summary. (#658) (@hitenkoku)
**Bug Fixes:**

View File

@@ -437,6 +437,7 @@ fn _print_unique_results(
// the order in which are registered and the order of levels to be displayed are reversed
counts_by_level.reverse();
let total_count = counts_by_level.iter().sum::<u128>();
// output total results
write_color_buffer(
&BufferWriter::stdout(ColorChoice::Always),
@@ -445,10 +446,7 @@ fn _print_unique_results(
"{} {}: {}",
head_word,
tail_word,
counts_by_level
.iter()
.sum::<u128>()
.to_formatted_string(&Locale::en),
total_count.to_formatted_string(&Locale::en),
),
true,
)
@@ -458,12 +456,18 @@ fn _print_unique_results(
if "undefined" == *level_name {
continue;
}
let percent = if total_count == 0 {
0 as f64
} else {
(counts_by_level[i] as f64) / (total_count as f64) * 100.0
};
let output_raw_str = format!(
"{} {} {}: {}",
"{} {} {}: {} ({:.2}%)",
head_word,
level_name,
tail_word,
counts_by_level[i].to_formatted_string(&Locale::en)
counts_by_level[i].to_formatted_string(&Locale::en),
percent
);
write_color_buffer(
&BufferWriter::stdout(ColorChoice::Always),