File tree Expand file tree Collapse file tree 2 files changed +13
-11
lines changed
Expand file tree Collapse file tree 2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change 11from elastalert .enhancements import BaseEnhancement
22from util import convert_array_to_object
3- from util import parse_detections
3+ from util import parse_array
44
5- # For easier access to nested values in an array , this merges all items in array
5+ # For easier access to nested values in an array , this merges all items in array
66# within
77class AlertTextEnhancement (BaseEnhancement ):
88 # The enhancement is run against every match
99 # The match is passed to the process function where it can be modified in any way
1010 # ElastAlert will do this for each enhancement linked to a rule
1111 def process (self , match ):
12- parsed_match = parse_detections (match )
12+ parsed_match = parse_array (match , 'detections' )
13+ match .update (parsed_match )
14+ parsed_match = parse_array (match , 'errors' )
1315 match .update (parsed_match )
Original file line number Diff line number Diff line change @@ -6,24 +6,24 @@ def convert_array_to_object(array):
66 json [str (idx )] = array [idx ]
77 return json
88
9- def parse_detections (match ) :
10- key = 'detections'
9+ def parse_array (match , key ) :
10+ o = match [ key ] if key in match else {}
1111 parsed = {key + '_parsed' : {}}
1212
13- if not isinstance (match [ key ] , list ):
13+ if not isinstance (o , list ):
1414 return parsed
15- if len (match [ key ] ) == 0 :
15+ if len (o ) == 0 :
1616 return parsed
1717
1818 # Converts array terms into objects
19- # parsed[key + '_parsed'] = convert_array_to_object(match[key] )
19+ # parsed[key + '_parsed'] = convert_array_to_object(o )
2020
21- for sk , value in match [ key ] [0 ].iteritems ():
21+ for sk , value in o [0 ].iteritems ():
2222 value_array = []
2323 if isinstance (value , list ):
24- value_array = list (chain .from_iterable (sv for sv in (v [sk ] for v in match [ key ] ) if sv ))
24+ value_array = list (chain .from_iterable (sv for sv in (v [sk ] for v in o ) if sv ))
2525 else :
26- value_array = [v [sk ] for v in match [ key ] ]
26+ value_array = [v [sk ] for v in o ]
2727 unique_values = set (value_array )
2828 parsed [key + '_parsed' ][sk ] = ", " .join (str (va ) for va in unique_values )
2929
You can’t perform that action at this time.
0 commit comments