Merge pull request #26 from treasure-data/config_parse_http

Use http port from parsed config file
This commit is contained in:
uu59 2014-06-09 14:20:21 +09:00
commit 1b38e1e92d
4 changed files with 48 additions and 2 deletions

View File

@ -1,6 +1,7 @@
class TutorialsController < ApplicationController
before_action :find_fluentd
before_action :check_ready, only: [:chapter1, :chapter2]
before_action :set_in_http, only: [:chapter1, :request_fluentd]
helper_method :tutorial_ready?
def index
@ -20,12 +21,16 @@ class TutorialsController < ApplicationController
end
def request_fluentd
HTTPClient.post("http://localhost:9880#{params[:path]}", json: params[:data].to_json)
HTTPClient.post("http://localhost:#{@in_http["port"]}#{params[:path]}", json: params[:data].to_json)
render nothing: true, status: 204
end
private
def set_in_http
@in_http = @fluentd.agent.configuration.sources.find{|directive| directive["type"] == "http"}
end
def find_fluentd
# NOTE: use first fluentd for tutorial
@fluentd = Fluentd.first

View File

@ -90,6 +90,12 @@ class Fluentd
extra_options[:config_file] || self.class.default_options[:config_file]
end
def configuration
if File.exists? config_file
::Fluentd::Agent::Configuration.new(config_file)
end
end
%w(start stop restart).each do |method|
define_method(method) do
raise NotImplementedError

View File

@ -0,0 +1,35 @@
require "fluent/config/v1_parser"
class Fluentd
class Agent
class Configuration
include Enumerable
attr_reader :file
def initialize(config_file)
@file = config_file
end
def config
@config ||= ::Fluent::Config::V1Parser.read(file)
end
def to_s
config.to_s.gsub(/\A<ROOT>\n/, "").gsub(/<\/ROOT>\n\z/, "").gsub(/^ {2}/, "")
end
def each(&block)
config.each_element(&block)
end
def sources
find_all{|e| e.name == "source"}
end
def matches
find_all{|e| e.name == "match"}
end
end
end
end

View File

@ -16,7 +16,7 @@
<p v-repeat="payloads">
<input type="button" class="btn btn-default" v-on="click: sendRequest($data)" value="<%= t ".send" %>" />
<code>
$ curl -X POST http://localhost:9880{{ path }} -F 'json={{ data | to_json }}'
$ curl -X POST http://localhost:<%= @in_http["port"] %>{{ path }} -F 'json={{ data | to_json }}'
</code>
</p>
</form>