【问题标题】:WSo2 Siddhi: How to count the number of events that fulfill a conditionWSo2 Siddhi:如何计算满足条件的事件数量
【发布时间】:2018-12-08 00:22:09
【问题描述】:

我正在研究一个用例来检测基于一些传入事件的登录暴力攻击。为此,我必须使用 wso2 + siddhi(非可选)。

我构建的代码的结构是:

  1. 为每个被攻击的目标创建一个分区
  2. 创建 5 秒的窗口
  3. 对于属于上一个窗口的每个事件,选择类别为“attempt.login”的所有条目
  4. 将它们插入新表中。

一旦我在新表中有每个条目,我想知道表中存储了多少事件,以便能够检测到暴力(如果事件数大于 20,例如,这意味着正在发生暴力攻击)。

partition with (Target_IP4 of I_Events)
begin
    from I_Events[Category == 'Attempt.Login']#window.time(5 sec)
    select meta_EventTime, correlation__id, Source_IP4, Source_Proto, Source_Hostname, Target_IP4, Target_Proto, Target_Hostnmae, Category, count() as attempts
    insert into #login_attempts;



from #login_attempts[attempts > 20]#window.time(5 sec)
    select ...
    insert into alert;

end;

从上面的代码中可以看出,我尝试使用 count() 函数但它不起作用,它只是在每次添加新元素时将值增加 1,例如,添加的第一个元素将具有 attemps = 1,第二个元素 attemps = 2,等等。

如果不能实现上述想法......至少有人知道如果满足给定条件,如何选择字符串的所有元素?例如,如果流的一个元素的属性设置为 true,则选择该流中的所有元素。

【问题讨论】:

    标签: stream wso2 complex-event-processing wso2cep siddhi


    【解决方案1】:

    您可以使用以下 Siddhi 查询来满足您的要求。

    partition with (Target_IP4 of I_Events)
    begin
    from I_Events[Category == 'Attempt.Login']#window.time(5 sec)
    select meta_EventTime, correlation__id, Source_IP4, Source_Proto, Source_Hostname, Target_IP4, Target_Proto, Target_Hostnmae, Category, count() as attempts
    having attempts > 20
    insert into alert;
    end;
    

    这里前 20 个事件在 5 分钟内出现在同一目标 ip 下不会产生任何警报。之后,在 20 分钟内超过该限制的每个事件都会生成警报。这种实现的一个缺点是,如果您有大量不同的 target_ip,它将导致创建大量分区,从而导致服务器进入 OOM。解决方案是使用group by

    体山

    【讨论】:

      猜你喜欢
      • 2019-04-30
      • 2013-10-14
      • 2019-07-13
      • 2019-03-11
      • 2015-03-21
      • 1970-01-01
      • 2018-07-26
      • 2019-07-15
      • 2020-08-29
      相关资源
      最近更新 更多