23
23
from lingzhi_engine .settings import MEDIA_ROOT
24
24
from django .utils .translation import gettext as _
25
25
from django .utils .translation import activate
26
+ from dongtai .models .strategy import IastStrategyModel
26
27
27
28
import os
28
29
@@ -46,19 +47,39 @@ def delete_old_files(path, save_seconds=3600):
46
47
47
48
48
49
def get_vul_count_by_agent (agent_ids , vid , user ):
49
- typeInfo = IastVulnerabilityModel .objects .filter (
50
- agent_id__in = agent_ids ).values ().order_by ("level" )
50
+ queryset = IastVulnerabilityModel .objects .filter (
51
+ agent_id__in = agent_ids )
52
+ typeInfo = queryset .values ().order_by ("level" )
51
53
if vid :
52
54
typeInfo = typeInfo .filter (id = vid )
53
55
type_summary = []
54
56
levelCount = {}
55
57
vulDetail = {}
58
+ strategy_ids = queryset .values_list ('strategy_id' ,
59
+ flat = True ).distinct ()
60
+ strategys = {
61
+ strategy ['id' ]: strategy
62
+ for strategy in IastStrategyModel .objects .filter (
63
+ pk__in = strategy_ids ).values ('id' , 'vul_name' ).all ()
64
+ }
65
+ hook_type_ids = queryset .values_list ('hook_type_id' ,
66
+ flat = True ).distinct ()
67
+ hooktypes = {
68
+ hooktype ['id' ]: hooktype
69
+ for hooktype in HookType .objects .filter (
70
+ pk__in = hook_type_ids ).values ('id' , 'name' ).all ()
71
+ }
56
72
if typeInfo :
57
73
typeArr = {}
58
74
typeLevel = {}
59
75
for one in typeInfo :
60
- hook_type = HookType .objects .filter (pk = one ['hook_type_id' ]).first ()
61
- one ['type' ] = hook_type .name if hook_type else ''
76
+ hook_type = hooktypes .get ('hook_type_id' , None )
77
+ hook_type_name = hook_type ['name' ] if hook_type else None
78
+ strategy = strategys .get ('strategy_id' , None )
79
+ strategy_name = strategy ['vul_name' ] if strategy else None
80
+ type_ = list (
81
+ filter (lambda x : x is not None , [strategy_name , hook_type_name ]))
82
+ one ['type' ]= type_ [0 ] if type_ else ''
62
83
typeArr [one ['type' ]] = typeArr .get (one ['type' ], 0 ) + 1
63
84
typeLevel [one ['type' ]] = one ['level_id' ]
64
85
levelCount [one ['level_id' ]] = levelCount .get (one ['level_id' ], 0 ) + 1
0 commit comments