question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question about counting pattern?

See original GitHub issue

i want use connting pattern with time gap,but the result makes me confused.The example i wrote is a brute force login success dection and below is the execution plan:

@Plan:name('TestExecutionPlan')

define stream rawStream ( catBehavior string, catOutcome string, srcAddress string, 
             deviceCat string, srcUsername string, 
             catObject string, destAddress string, appProtocol string ); 
 
@info(name = 'condition1') 
from rawStream[ catBehavior == '/Authentication/Verify' 
         and catOutcome == 'FAIL' and not( srcAddress is null ) ]#window.time(1 min) 
select srcAddress, deviceCat, srcUsername, destAddress, appProtocol 
insert into e1_OutputStream;

@info(name = 'condition2') 
from rawStream[ catBehavior == '/Authentication/Verify' 
         and catOutcome == 'OK' and not( srcAddress is null ) ]#window.time(1 min)  
select srcAddress, deviceCat, srcUsername, destAddress, appProtocol 
insert into e2_OutputStreamOutputStream;

@info(name = 'result') 
from every ( e1 = e1_OutputStream<9:> ) -> e2 = e2_OutputStream[ e1.srcAddress == srcAddress 
                                and e1.deviceCat == deviceCat 
                                and e1.srcUsername == srcUsername 
                                and e1.destAddress == destAddress 
                                and e1.appProtocol == appProtocol ]
within 10 second 
select 'relationEvent' as event, e1.srcAddress, 
e1.deviceCat, e1.srcUsername, e1.destAddress, e1.appProtocol 
insert into resultOutputStream;

and the event stream is below,include 9 FAIL, 1 SUCCESS events

rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,FAIL,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]
delay(2000)
rawStream=[/Authentication/Verify,OK,1.1.1.1,deviceCat,srcUsername,catObject,destAddress,appProtocol]

9 FAIL login and 1 SUC login will trigger the rule,so i wrote e1 = e1_OutputStream<9:>,also i want detect during a time period,so i wrote within 10 second .the event streams i sent should not trigger the rule( the sum of delay time > 10 sec ),but the result is that it do triggered the rule.so i’m wondering the time gap i defined,matches with the first event or the last event? 9 FAIL login and 1 SUC login will trigger the rule,so i wrote e1 = e1_OutputStream<9:>,also i want detect during a time period,so i wrote within 10 second ,the event streams i sent should not trigger the rule,but the result is it do triggered the rule.so i’m wornding

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tishan89commented, Jan 2, 2017

Hi @tttMelody ,

The time gap is the time between first event and the last event. basically we keep that time constraint so that we won’t keep holding events till infinity. Only an event will be held for that time duration within a pattern. That being said I think your requirement is to detect 9 or more subsequent failures followed by a success login. If so you don’t need the #window.time(1 min) also. You can just have a you filter query to filter success and fail events. And your query would look like

@info(name = ‘result’) from every e1 = e1_OutputStream -> e2 = e1_OutputStream<8:> [e1.srcAddress == srcAddress and e1.deviceCat == deviceCat and e1.srcUsername == srcUsername and e1.destAddress == destAddress and e1.appProtocol == appProtocol ] ->e3 = e2_OutputStream[ e1.srcAddress == srcAddress and e1.deviceCat == deviceCat and e1.srcUsername == srcUsername and e1.destAddress == destAddress and e1.appProtocol == appProtocol ] within 10 second select ‘relationEvent’ as event, e1.srcAddress, e1.deviceCat, e1.srcUsername, e1.destAddress, e1.appProtocol insert into resultOutputStream;

I have added an extra layer to the pattern to make sure that first nine events are for the same src address, device cat etc. Pattern you wrote will match for any nine failed events regardless of src address etc.

0reactions
Aaaaaaroncommented, Jan 12, 2017

@tishan89 thanks so so much.your solution is so brilliant.I always confused about how to do operation with grouped data in a pattern and in the same time join another grouped stream. Your solution use e2 instead of group.it is brilliant.but I wander the performance may not be good,if your data is dispersed. In my use case I am only concerned with the Success happen after Fail,I didn’t concern about the order that the 9 Fail events in its own group.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Questions on Patterns | Patterns Worksheets - Math Only Math
Easy ways to solve math questions on patterns number series. We need to find the exact missing ... The counting numbers may be...
Read more >
Number Series and Patterns Questions and Answers
The first pattern begins with 13 and adds 2 to each number to arrive at the next; the alternating pattern begins with 29...
Read more >
Patterns Questions for Tests and Worksheets - Help Teaching
You can create printable tests and worksheets from these Patterns questions! Select one or more questions using the checkboxes above each question.
Read more >
12 Number Patterns
12.1 Simple Number Patterns. A list of numbers which form a pattern is called a sequence. In this section, straightfor- ward sequences are...
Read more >
Number Patterns - Grade 3 | Mathematics Quiz - Quizizz
Play this game to review Mathematics. What are the missing numbers in this pattern? 12, 15, ___, 21, ____, 27.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found