Как правильно передать числовую переменную в поле max_age дроссельной заслонки? - PullRequest
0 голосов
/ 18 февраля 2019

Как передать целочисленное поле параметру max_age блока дроссельного фильтра?Я не могу пройти мимо ошибки, показанной ниже.

[ERROR] 2019-02-18 20:19:30.005 [Converge PipelineAction::Create<main>] throttle - Invalid setting for throttle filter plugin:

  filter {
    throttle {
      # This setting must be a number
      # Expected number, got "throttle_max_age" (type throttle_max_age)
      max_age => ["throttle_max_age"]
      ...
    }
  }

Часть фильтра моей конфигурации logstash:

filter {

    mutate { add_field => { "eventkey" => "%{[logger][hostname]}-%{[probe][name]}-%{voltage_category}" } }

    # Specific alert frequencies for different alert categories
    if ["voltage_category] == "normal" {
        # Voltage normal
        # 86400 = one day
        mutate { add_field => { "throttle_period" => 86400 }  }
        # Two days and ten seconds
        mutate { add_field => { "throttle_max_age" => 172810 } }
    } else {
        # Abnormal event. Throttle less, so more notifications are transmitted
        mutate { add_field => { "throttle_period" => 15 } }
        mutate { add_field => { "throttle_max_age" => 180 } }
    } # end of voltage abnormal

    # Added this for S & G - had no effect. 
    mutate { convert => { "throttle_max_age" => "integer" } }

    # For a given ID, emit ONE event no more than every 15 seconds
    # ID: logger.hostname + probe.name
    throttle {
        key => "%{eventkey}"
        period => [throttle_period]
        max_age => [throttle_max_age]
        before_count => -1
        after_count => 1
        add_tag => "throttled"
    }
}

1 Ответ

0 голосов
/ 19 февраля 2019

К сожалению, кажется, что это невозможно сделать в данный момент, поскольку значение проверяется в момент загрузки конфигурации Logstash, и оно ожидает конкретное числовое значение.

Вот исходный код плагина газа, где он проверяет, что значение является числом:
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

В качестве обходного пути, если у вас есть только пара случаев для значения max_age, вы можете изменить условное условие и установить там два дроссельных фильтра.Например:

# 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
} 
...