0

Need a rule which alerts if a certain number of BootNotifications (here 2) occurs in a certain time frame (here 10s).

I came up with the following rule:

rule "MonitorNumberOfReboots"
dialect "mvel"
when
    $s : BootNotification()
    Number( intValue >= 2 ) from accumulate ( BootNotification() over window:time (10s), count(1)) 
    not (Command(this before [0s, 1h] $s )) 
then
    Command $c = new Command();
    insertLogical( $c );
    end

Further explanation:

  • Kie-Engine is running in "stateful", "stream", "realtime" and "equality" mode

Testing:

  • I tested the rule by adding BootNotification with an interval > 10s => Rule does not fire => check
  • I tested the rule by adding BootNotification with an interval 2s => Rule fires many times => fail

Question/Problem:

I don't want the rule to fire many times. When the rules fires, I insert a Command. In when-clause I added a check if Command exists. I expect the rule to not fire more than once in 1h. It doesn't work. Even after 10s it just keeps inserting Command instances.

I thought the problem could my the "this before [0s, 1h] $s" in the third line of when-clause, so I replaced it with

not (Command() over window:time (1h)) 

but it does fire even more often when add BootNotifications every 2s.

Scholle
  • 1,521
  • 2
  • 23
  • 44
  • you want the session clock to be as per System time or from the time that you are sending in your data? – Prog_G Jun 12 '18 at 12:27
  • i guess system time should be the way to go. however, the order of events represented by the timestamp in each event should be considered too, because its is architecturally not guaranteed that the events are inserted into working memory according to the timestamp. – Scholle Jun 12 '18 at 14:00
  • For CEP in Drools, you should insert data in working memory in sequence. The rules you want to define is based on the occurrence of the dependent events. If you will not insert the event in proper order you will get wrong output. – Prog_G Jun 13 '18 at 09:50
  • During testing I did insert events in sequence, so the timestamp check is actually not relevant here. I updated my question and removed everything not relevant. – Scholle Jun 13 '18 at 19:18
  • As per my understanding, the rule that you have set will fire whenever `BootNotification()` object is inserted into the working memory over a `window of 10s` that means that if `BootNotification()` object comes in the working memory in 2 seconds also then it will fire the rule and it will keep firing if more `BootNotification()` object is inserted into the working memory as you have set the condition of `count value as >= 2`. – Prog_G Jun 14 '18 at 05:03
  • As per my understanding, at least two BootNotifications need to be in the working memory to fire the rule. You are right, when I keep adding BootNotifications every 2 seconds, the rule should keep firing, BUT: When the rule fires for the first time, it inserts Command object into the working memory. Shouldn't this prevent the rule from firing due to the check in line 3 of when clause over a period of 1 hour? Is there a different way to ensure the rule fires only once for a certain period of time? – Scholle Jun 14 '18 at 21:25
  • Try using this `Number( intValue = 2 ) from accumulate ( BootNotification() over window:time (10s), count(1)) ` as your windowing rule and check. – Prog_G Jun 15 '18 at 03:58

0 Answers0