Statis 统计概览信息
(report Report)
| 8 | |
| 9 | // Statis 统计概览信息 |
| 10 | func Statis(report Report) (string, string) { |
| 11 | |
| 12 | // 组件风险统计 key:0代表组件总数 |
| 13 | depStatic := map[int]int{ |
| 14 | 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, |
| 15 | } |
| 16 | |
| 17 | // 漏洞风险统计 |
| 18 | vulStatic := map[int]int{ |
| 19 | 0: 0, 1: 0, 2: 0, 3: 0, 4: 0, |
| 20 | } |
| 21 | // 记录统计过的漏洞 |
| 22 | vulSet := map[string]bool{} |
| 23 | |
| 24 | report.DepDetailGraph.ForEach(func(n *detail.DepDetailGraph) bool { |
| 25 | |
| 26 | if n.Name == "" { |
| 27 | return true |
| 28 | } |
| 29 | |
| 30 | // 当前组件风险 |
| 31 | risk := 5 |
| 32 | for _, v := range n.Vulnerabilities { |
| 33 | if !vulSet[v.Id] { |
| 34 | vulSet[v.Id] = true |
| 35 | if v.SecurityLevelId > 0 { |
| 36 | vulStatic[v.SecurityLevelId]++ |
| 37 | } |
| 38 | vulStatic[0]++ |
| 39 | } |
| 40 | if v.SecurityLevelId < risk { |
| 41 | // 组件风险取最高漏洞风险 |
| 42 | risk = v.SecurityLevelId |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | if risk > 0 { |
| 47 | depStatic[risk]++ |
| 48 | } |
| 49 | depStatic[0]++ |
| 50 | |
| 51 | return true |
| 52 | }) |
| 53 | if vulStatic[0] != 0 { |
| 54 | return fmt.Sprintf("Components:%d C:%d H:%d M:%d L:%d", |
| 55 | depStatic[0], depStatic[1], depStatic[2], depStatic[3], depStatic[4]), |
| 56 | fmt.Sprintf("\nVulnerabilities:%d C:%d H:%d M:%d L:%d", |
| 57 | vulStatic[0], vulStatic[1], vulStatic[2], vulStatic[3], vulStatic[4]) |
| 58 | } |
| 59 | return fmt.Sprintf("Components: %d", depStatic[0]), "" |
| 60 | } |