我想要写一个复杂的规则,当任何网络ip通过10分钟窗口击中应用程序时,我都需要触发规则。我有一些挑战,其中ip的变化,我不知道如何保持跟踪的每一个ip已经击中应用程序。
rule "IP hit exceeds 10 times"
no-loop
when
"some ip hitting more than 10 times" over window:time(10m);
$cnt: count(1); $cnt >= 10)
then
System.out.println("IP hit exceeds 10 times");
end我需要逻辑的这一部分的代码“一些ip击中”。提前谢谢。
发布于 2020-12-16 14:01:15
如果您引用Drools文档,您可以看到与window一起使用的accumulate函数将完全满足您的需要。
基本上,accumulate通过一个集合收集项目--如果我们没有使用滑动窗口,您可以使用它来获取子列表或计算事件列表的总和。还有一个类似的函数名为collect,但我将在本例中使用accumulate。
总之,假设您有一个类定义如下:
class IpHitEvent {
private String ip;
// getters and setters
}然后,您可以利用accumulate和内置的count方法来获取指定IP的IP命中次数。
rule "Single IP Hits > 10"
when
$ip: String() // Target IP -- set based on your own logic
Integer( this > 10 ) from accumulate(IpHitEvent( ip == $ip ) over window:time(10m), count(1))
then
System.out.println($ip + " has hit more than 10 times!");
// logic for when IP hit count exceeds 10
endhttps://stackoverflow.com/questions/65156982
复制相似问题