lib/logstash/inputs/http_poller.rb in logstash-input-http_poller-3.3.4 vs lib/logstash/inputs/http_poller.rb in logstash-input-http_poller-4.0.0
- old
+ new
@@ -15,25 +15,21 @@
# A Hash of urls in this format : `"name" => "url"`.
# The name and the url will be passed in the outputed event
config :urls, :validate => :hash, :required => true
- # How often (in seconds) the urls will be called
- # DEPRECATED. Use 'schedule' option instead.
- # If both interval and schedule options are specified, interval
- # option takes higher precedence
- config :interval, :validate => :number, :deprecated => true
+ config :interval, :validate => :number, :obsolete => "The interval options is obsolete. Use schedule instead"
# Schedule of when to periodically poll from the urls
# Format: A hash with
# + key: "cron" | "every" | "in" | "at"
# + value: string
# Examples:
# a) { "every" => "1h" }
# b) { "cron" => "* * * * * UTC" }
# See: rufus/scheduler for details about different schedule options and value string format
- config :schedule, :validate => :hash
+ config :schedule, :validate => :hash, :required => true
# Define the target field for placing the received data. If this setting is omitted, the data will be stored at the root (top level) of the event.
config :target, :validate => :string
# If you'd like to work with the request/response metadata.
@@ -44,11 +40,12 @@
public
Schedule_types = %w(cron every at in)
def register
@host = Socket.gethostname.force_encoding(Encoding::UTF_8)
- @logger.info("Registering http_poller Input", :type => @type, :interval => @interval, :schedule => @schedule, :timeout => @timeout)
+ @logger.info("Registering http_poller Input", :type => @type,
+ :urls => @urls, :schedule => @schedule, :timeout => @timeout)
setup_requests!
end
def stop
@@ -121,34 +118,13 @@
request
end
public
def run(queue)
- #interval or schedule must be provided. Must be exclusively either one. Not neither. Not both.
- raise LogStash::ConfigurationError, "Invalid config. Neither interval nor schedule was specified." \
- unless @interval || @schedule
- raise LogStash::ConfigurationError, "Invalid config. Specify only interval or schedule. Not both." \
- if @interval && @schedule
-
- if @interval
- setup_interval(queue)
- elsif @schedule
- setup_schedule(queue)
- else
- #should not reach here
- raise LogStash::ConfigurationError, "Invalid config. Neither interval nor schedule was specified."
- end
+ setup_schedule(queue)
end
- private
- def setup_interval(queue)
- @interval_thread = Thread.current
- Stud.interval(@interval) do
- run_once(queue)
- end
- end
-
def setup_schedule(queue)
#schedule hash must contain exactly one of the allowed keys
msg_invalid_schedule = "Invalid config. schedule hash must contain " +
"exactly one of the following keys - cron, at, every or in"
raise Logstash::ConfigurationError, msg_invalid_schedule if @schedule.keys.length !=1
@@ -240,16 +216,9 @@
:exception_message => e.message,
:exception_backtrace => e.backtrace,
:name => name,
:url => request
)
-
- @logger.debug? && @logger.debug("Cannot read URL or send the error as an event!",
- :exception => e,
- :exception_message => e.message,
- :exception_backtrace => e.backtrace,
- :name => name,
- :url => request)
end
private
def apply_metadata(event, name, request, response=nil, execution_time=nil)
return unless @metadata_target