@@ -83,7 +83,7 @@ def test_create_and_alert_rule_with_pipeline_condition_should_not_trigger_event_
8383 self ._api .create_alert_rule_count ('A' , _PERIOD , stream = stream )
8484
8585 # Send a log with user=toto and source=sourceABC. It will be placed in the Stream because the pipeline function found the user in the list. So the rule will trigger but it is wrong because "source" is not equal to "source123"
86- # Send a log with user=xxx and source=source123. It will be placed in the Stream beauce the only Stream rule is field "source" match exactly "source123". So the rule will trigger but it is wrong because "user" is not present in the list
86+ # Send a log with user=xxx and source=source123. It will be placed in the Stream because the only Stream rule is field "source" match exactly "source123". So the rule will trigger but it is wrong because "user" is not present in the list
8787 with self ._graylog .access_gelf_input (self ._gelf_input_identifier ) as inputs :
8888 inputs .send ({'host' : 'source123' })
8989 aggregation_events_count = self ._graylog .get_events_count ('aggregation-v1' )
@@ -170,3 +170,121 @@ def test_create_alert_rule_with_list_should_not_generate_event_on_substrings_of_
170170 for i in range (events ['total_events' ]):
171171 print (events ['events' ][i ])
172172 self .assertEqual (starting_events_count , self ._graylog .get_events_count ('aggregation-v1' ))
173+
174+ def test_notification_should_generate_identifier_for_aggregation_id__issue170 (self ):
175+ stream = {
176+ 'field_rule' : [{
177+ 'field' : 'x' ,
178+ 'type' : 1 ,
179+ 'value' : 'test_value'
180+ }],
181+ 'matching_type' : 'AND'
182+ }
183+ self ._api .create_alert_rule_count ('A' , _PERIOD , stream = stream )
184+
185+ # Send a log with _x=test_value
186+ with self ._graylog .access_gelf_input (self ._gelf_input_identifier ) as inputs :
187+ inputs .send ({'_x' : 'test_value' })
188+
189+ for i in range (60 * _PERIOD + 20 ):
190+ events_count = self ._graylog .get_events_count ('aggregation-v1' )
191+ print (f'events count: { events_count } ' )
192+ if events_count > 0 :
193+ break
194+ time .sleep (1 )
195+
196+ events = self ._graylog .get_events ()
197+
198+ aggregation_id = events ['events' ][0 ]['event' ]['fields' ]['aggregation_id' ]
199+ self .assertIsNotNone (aggregation_id )
200+
201+ def test_notification_should_generate_new_identifier_for_aggregation_id__issue170 (self ):
202+ # Prepare config
203+ self ._graylog .update_alert_wizard_plugin_configuration (aggregation_time = 0 )
204+ stream = {
205+ 'field_rule' : [{
206+ 'field' : 'x' ,
207+ 'type' : 1 ,
208+ 'value' : 'test_value'
209+ }],
210+ 'matching_type' : 'AND'
211+ }
212+ self ._api .create_alert_rule_count ('A' , _PERIOD , stream = stream )
213+
214+ with self ._graylog .access_gelf_input (self ._gelf_input_identifier ) as inputs :
215+ # Send a message with _x=test_value
216+ inputs .send ({'_x' : 'test_value' })
217+
218+ for i in range (60 * _PERIOD + 20 ):
219+ events_count = self ._graylog .get_events_count ('aggregation-v1' )
220+ print (f'events count: { events_count } ' )
221+ if events_count > 0 :
222+ break
223+ time .sleep (1 )
224+
225+ # Send a second message with _x=test_value
226+ inputs .send ({'_x' : 'test_value' })
227+
228+ for i in range (60 * _PERIOD + 20 ):
229+ events_count = self ._graylog .get_events_count ('aggregation-v1' )
230+ print (f'events count: { events_count } ' )
231+ if events_count > 1 :
232+ break
233+ time .sleep (1 )
234+
235+ events = self ._graylog .get_events ()
236+
237+ # Check if all aggregation_id are the same
238+ aggregation_id_1 = events ['events' ][0 ]['event' ]['fields' ]['aggregation_id' ]
239+ aggregation_id_2 = events ['events' ][1 ]['event' ]['fields' ]['aggregation_id' ]
240+
241+ self .assertNotEquals (aggregation_id_1 , aggregation_id_2 )
242+
243+ def test_notification_should_reuse_identifier_for_aggregation_id__issue170 (self ):
244+ # Prepare config
245+ self ._graylog .update_alert_wizard_plugin_configuration (aggregation_time = 10 )
246+ stream = {
247+ 'field_rule' : [{
248+ 'field' : 'x' ,
249+ 'type' : 1 ,
250+ 'value' : 'test_value'
251+ }],
252+ 'matching_type' : 'AND'
253+ }
254+ self ._api .create_alert_rule_count ('A' , _PERIOD , stream = stream )
255+
256+ with self ._graylog .access_gelf_input (self ._gelf_input_identifier ) as inputs :
257+ # Send a message with _x=test_value
258+ inputs .send ({'_x' : 'test_value' })
259+
260+ for i in range (60 * _PERIOD + 20 ):
261+ events_count = self ._graylog .get_events_count ('aggregation-v1' )
262+ print (f'events count: { events_count } ' )
263+ if events_count > 0 :
264+ break
265+ time .sleep (1 )
266+
267+ events = self ._graylog .get_events ()
268+
269+ # Store aggregation_id
270+ aggregation_id = events ['events' ][0 ]['event' ]['fields' ]['aggregation_id' ]
271+
272+ # Send a second message with _x=test_value
273+ inputs .send ({'_x' : 'test_value' })
274+
275+ for i in range (60 * _PERIOD + 20 ):
276+ events_count = self ._graylog .get_events_count ('aggregation-v1' )
277+ print (f'events count: { events_count } ' )
278+ if events_count > 1 :
279+ break
280+ time .sleep (1 )
281+
282+ events = self ._graylog .get_events ()
283+
284+ # Check if all aggregation_id are the same
285+ aggregation_id_1 = events ['events' ][0 ]['event' ]['fields' ]['aggregation_id' ]
286+ aggregation_id_2 = events ['events' ][1 ]['event' ]['fields' ]['aggregation_id' ]
287+
288+ self .assertEqual (aggregation_id , aggregation_id_1 )
289+ self .assertEqual (aggregation_id , aggregation_id_2 )
290+
0 commit comments