Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update http_poller.rb #109

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/logstash/inputs/http_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
require "manticore"
require "rufus/scheduler"

class LogStash::Inputs::HTTP_Poller < LogStash::Inputs::Base
class LogStash::Inputs::HTTP_Poller2 < LogStash::Inputs::Base
include LogStash::PluginMixins::HttpClient

config_name "http_poller"
config_name "http_poller2"

default :codec, "json"

Expand Down Expand Up @@ -40,7 +40,7 @@ class LogStash::Inputs::HTTP_Poller < LogStash::Inputs::Base
def register
@host = Socket.gethostname.force_encoding(Encoding::UTF_8)

@logger.info("Registering http_poller Input", :type => @type, :schedule => @schedule, :timeout => @timeout)
@logger.info("Registering http_poller2 Input", :type => @type, :schedule => @schedule, :timeout => @timeout)

setup_requests!
end
Expand All @@ -59,6 +59,11 @@ def setup_requests!
def normalize_request(url_or_spec)
if url_or_spec.is_a?(String)
res = [:get, url_or_spec]
#substitute date variables if passed as part of the URL string
now_datetime = DateTime.now
res.gsub!(/{{%y}}/, now_datetime.year)
res.gsub!(/{{%m}}/, now_datetime.month)

elsif url_or_spec.is_a?(Hash)
# The client will expect keys / values
spec = Hash[url_or_spec.clone.map {|k,v| [k.to_sym, v] }] # symbolize keys
Expand Down
6 changes: 3 additions & 3 deletions spec/inputs/http_poller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Workaround for the bug reported in https://github.com/jruby/jruby/issues/4637
require 'rspec/matchers/built_in/raise_error.rb'

describe LogStash::Inputs::HTTP_Poller do
describe LogStash::Inputs::HTTP_Poller2 do
let(:metadata_target) { "_http_poller_metadata" }
let(:queue) { Queue.new }
let(:default_schedule) {
Expand All @@ -26,7 +26,7 @@
"metadata_target" => metadata_target
}
}
let(:klass) { LogStash::Inputs::HTTP_Poller }
let(:klass) { LogStash::Inputs::HTTP_Poller2 }

describe "instances" do
subject { klass.new(default_opts) }
Expand Down Expand Up @@ -305,7 +305,7 @@
}

shared_examples "unprocessable_requests" do
let(:poller) { LogStash::Inputs::HTTP_Poller.new(settings) }
let(:poller) { LogStash::Inputs::HTTP_Poller2.new(settings) }
subject(:event) {
poller.send(:run_once, queue)
queue.pop(true)
Expand Down