logstash-plugins / logstash-input-snmp

Apache License 2.0
17 stars 22 forks source link

fix: Specifically cast passed in retries and timeout values to ints #104

Open jrgns opened 2 years ago

jrgns commented 2 years ago

Release notes

What does this PR do?

Specifically cast the retries and interval settings in the host array to integers. Since there's no validation on these values, if you set these values through ENV variables, they'll come through as strings.

Why is it important/What is the impact to the user?

Users will like to set these values through ENV variables.

Checklist

How to test this PR locally

input {
    snmp {
        hosts => [
            {host => "udp:127.0.0.1" community => "public" retries => '${RETRIES:2}' timeout => '${TIMEOUT:5000}' }

Related issues

None created

Logs

Pipeline error {:pipeline_id=>"inventory-input", :exception=>#<TypeError: cannot convert instance of class org.jruby.RubyString to int>, :backtrace=>[
    "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-snmp-1.2.7/lib/logstash/inputs/snmp/client.rb:48:in `build_target'",
    "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-snmp-1.2.7/lib/logstash/inputs/snmp/client.rb:25:in `initialize'",
    "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-snmp-1.2.7/lib/logstash/inputs/snmp.rb:157:in `block in register'",
    "org/jruby/RubyArray.java:1809:in `each'",
    "/usr/share/logstash/vendor/bundle/jruby/2.5.0/gems/logstash-input-snmp-1.2.7/lib/logstash/inputs/snmp.rb:123:in `register'",
    "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:228:in `block in register_plugins'",
    "org/jruby/RubyArray.java:1809:in `each'",
    "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:227:in `register_plugins'",
    "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:386:in `start_inputs'",
    "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:311:in `start_workers'",
    "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:185:in `run'",
    "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:137:in `block in start'"
], "pipeline.sources"=>["/usr/share/logstash/pipeline/inventory.conf"], :thread=>"#<Thread:0x567073ec@/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:125 run>"}
jrgns commented 2 years ago

Will provide tests as soon as I have a gap :)