不幸的是,现在似乎不可能做到这一点,因为值在加载Logstash配置时被验证,并且它期望一个具体的数字值。
下面是throttle插件的源代码,它在其中检查值是否为数字:
https://github.com/logstash-plugins/logstash-filter-throttle/blob/master/lib/logstash/filters/throttle.rb#L191
与允许字段替换的周期值比较:
https://github.com/logstash-plugins/logstash-filter-throttle/blob/5c8d3543ba0eed9ba8a93ae4ffbef7fb15d881ea/lib/logstash/filters/throttle.rb#L197
作为一种解决办法,如果您只有几个案例的最大年龄值,您可以修改条件,并在那里放置两个节流过滤器。例如:
# Specific alert frequencies for different alert categories
if ["voltage_category] == "normal" {
# Voltage normal
throttle {
key => "%{eventkey}"
# 86400 = one day
period => 86400
# Two days and ten seconds
max_age => 172810
before_count => -1
after_count => 1
add_tag => "throttled"
}
} else {
# Abnormal event. Throttle less, so more notifications are transmitted
throttle {
key => "%{eventkey}"
period => 15
max_age => 180
before_count => -1
after_count => 1
add_tag => "throttled"
}
# end of voltage abnormal
}