File tree Expand file tree Collapse file tree 2 files changed +31
-7
lines changed
Expand file tree Collapse file tree 2 files changed +31
-7
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
34
4-
5+ # For easier access to nested values in an array , this merges all items in array
6+ # within
57class AlertTextEnhancement (BaseEnhancement ):
68 # The enhancement is run against every match
79 # The match is passed to the process function where it can be modified in any way
810 # ElastAlert will do this for each enhancement linked to a rule
911 def process (self , match ):
10- match ['detections_string' ] = ''
11- if 'detections' in match :
12- match ['detections_parsed' ] = convert_array_to_object (match ['detections' ])
12+ parsed_match = parse_detections (match )
13+ match .update (parsed_match )
Original file line number Diff line number Diff line change 1-
1+ from itertools import chain
22
33def convert_array_to_object (array ):
44 json = {}
55 for idx in range (len (array )):
6- json [idx ] = array [idx ]
7- return json
6+ json [str (idx )] = array [idx ]
7+ return json
8+
9+ def parse_detections (match ):
10+ key = 'detections'
11+ parsed = {key + '_parsed' : {}}
12+
13+ if not isinstance (match [key ], list ):
14+ return parsed
15+ if len (match [key ]) == 0 :
16+ return parsed
17+
18+ # Converts array terms into objects
19+ # parsed[key + '_parsed'] = convert_array_to_object(match[key])
20+
21+ for sk , value in match [key ][0 ].iteritems ():
22+ value_array = []
23+ if isinstance (value , list ):
24+ value_array = list (chain .from_iterable (sv for sv in (v [sk ] for v in match [key ]) if sv ))
25+ else :
26+ value_array = [v [sk ] for v in match [key ]]
27+ unique_values = set (value_array )
28+ parsed [key + '_parsed' ][sk ] = ", " .join (str (va ) for va in unique_values )
29+
30+ return parsed
You can’t perform that action at this time.
0 commit comments