diff --git a/app/controllers/fluentd/settings/out_elasticsearch_controller.rb b/app/controllers/fluentd/settings/out_elasticsearch_controller.rb
new file mode 100644
index 0000000..0d5d5d9
--- /dev/null
+++ b/app/controllers/fluentd/settings/out_elasticsearch_controller.rb
@@ -0,0 +1,22 @@
+class Fluentd::Settings::OutElasticsearchController < ApplicationController
+ include SettingConcern
+
+ private
+
+ def target_class
+ Fluentd::Setting::OutElasticsearch
+ end
+
+ def initial_params
+ {
+ host: "127.0.0.1",
+ port: 9200,
+ index_name: "via_fluentd",
+ type_name: "via_fluentd",
+ logstash_format: true,
+ include_tag_key: false,
+ tag_key: "tag",
+ utc_index: true,
+ }
+ end
+end
diff --git a/app/models/fluentd/setting/out_elasticsearch.rb b/app/models/fluentd/setting/out_elasticsearch.rb
new file mode 100644
index 0000000..e602b09
--- /dev/null
+++ b/app/models/fluentd/setting/out_elasticsearch.rb
@@ -0,0 +1,24 @@
+class Fluentd
+ module Setting
+ class OutElasticsearch
+ include Common
+
+ KEYS = [
+ :match,
+ :host, :port, :index_name, :type_name,
+ :logstash_format, :logstash_prefix, :logstash_dateformat, :utc_index,
+ :hosts, :request_timeout, :include_tag_key, :tag_key
+ ].freeze
+
+ attr_accessor(*KEYS)
+
+ booleans :logstash_format, :utc_index, :include_tag_key
+
+ validates :match, presence: true
+ validates :host, presence: true
+ validates :port, presence: true
+ validates :index_name, presence: true
+ validates :type_name, presence: true
+ end
+ end
+end
diff --git a/app/views/fluentd/settings/out_elasticsearch/_form.html.haml b/app/views/fluentd/settings/out_elasticsearch/_form.html.haml
new file mode 100644
index 0000000..faf8db9
--- /dev/null
+++ b/app/views/fluentd/settings/out_elasticsearch/_form.html.haml
@@ -0,0 +1,25 @@
+= render "shared/setting_errors"
+
+= form_for(@setting, url: finish_daemon_setting_out_elasticsearch_path(@fluentd), html: {class: "ignore-rails-error-div"}) do |f|
+ = field(f, :match)
+ = field(f, :host)
+ = field(f, :port)
+ = field(f, :logstash_format)
+ = field(f, :index_name)
+ = field(f, :type_name)
+
+ .well.well-sm
+ %h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
+ = icon('fa-caret-down')
+ = t('terms.advanced_setting')
+ #advanced-setting.collapse
+ = field(f, :hosts)
+ = field(f, :logstash_prefix)
+ = field(f, :logstash_dateformat)
+ = field(f, :utc_index)
+ = field(f, :request_timeout)
+ = field(f, :include_tag_key)
+ = field(f, :tag_key)
+ = field(f, :tag_key)
+ = f.submit t('fluentd.common.finish'), class: "btn btn-lg btn-primary pull-right"
+
diff --git a/app/views/fluentd/settings/out_elasticsearch/show.html.haml b/app/views/fluentd/settings/out_elasticsearch/show.html.haml
new file mode 100644
index 0000000..8e4354c
--- /dev/null
+++ b/app/views/fluentd/settings/out_elasticsearch/show.html.haml
@@ -0,0 +1,6 @@
+- page_title t(".page_title")
+
+.well
+ = raw t('fluentd.settings.out_elasticsearch.option_guide')
+
+= render "form"
diff --git a/app/views/fluentd/settings/source_and_output.html.haml b/app/views/fluentd/settings/source_and_output.html.haml
index 318a70e..c5a5cbd 100644
--- a/app/views/fluentd/settings/source_and_output.html.haml
+++ b/app/views/fluentd/settings/source_and_output.html.haml
@@ -39,6 +39,10 @@
= link_to(daemon_setting_out_mongo_path(@fluentd)) do
= icon('fa-file-text-o fa-lg')
= t("fluentd.common.setup_out_mongo")
+ %p
+ = link_to(daemon_setting_out_elasticsearch_path(@fluentd)) do
+ = icon('fa-file-text-o fa-lg')
+ = t("fluentd.common.setup_out_elasticsearch")
%p
= link_to(daemon_setting_out_forward_path(@fluentd)) do
= icon('fa-file-text-o fa-lg')
diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml
index 31835dc..2d698a5 100644
--- a/config/locales/translation_en.yml
+++ b/config/locales/translation_en.yml
@@ -97,6 +97,7 @@ en:
setup_out_mongo: MongoDB
setup_out_forward: Forwarding
setup_out_s3: Amazon S3
+ setup_out_elasticsearch: Elasticsearch
finish: Update & Restart
fluentd_info: Setting info
recent_errors: "Errors within recent %{days} days"
@@ -144,6 +145,11 @@ en:
For each config parameter, pelase refer to the Treasure Data output plugin documentation page.
show:
page_title: Add Output to Treasure Data
+ out_elasticsearch:
+ option_guide: |
+ For each config parameter, pelase refer to the Elasticsearch output plugin documentation page.
+ show:
+ page_title: Add Output to Elasticsearch
out_mongo:
option_guide: |
For each config parameter, pelase refer to the MongoDB output plugin documentation page.
diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml
index 1d25fd8..c172ca1 100644
--- a/config/locales/translation_ja.yml
+++ b/config/locales/translation_ja.yml
@@ -96,6 +96,7 @@ ja:
setup_out_mongo: MongoDB
setup_out_forward: 転送
setup_out_s3: AWS S3
+ setup_out_elasticsearch: Elasticsearch
finish: 設定する
fluentd_info: 設定情報
recent_errors: "直近 %{days} 日内のエラー"
@@ -143,6 +144,12 @@ ja:
fluent-plugin-tdプラグインのインストールが必要です。
show:
page_title: Treasure Data書き出し設定
+ out_elasticsearch:
+ option_guide: |
+ fluent-plugin-elasticsearchプラグインのインストールが必要です。
+ out_elasticsearchプラグインの解説もご参照ください。
+ show:
+ page_title: Elasticsearch設定
out_mongo:
option_guide: |
fluent-plugin-mongoプラグインのインストールが必要です。
diff --git a/config/routes.rb b/config/routes.rb
index f7af73c..6bfc44d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -43,6 +43,10 @@ Rails.application.routes.draw do
resource :out_forward, only: [:show], module: :settings, controller: :out_forward do
post "finish"
end
+
+ resource :out_elasticsearch, only: [:show], module: :settings, controller: :out_elasticsearch do
+ post "finish"
+ end
end
end
end
diff --git a/spec/features/fluentd/setting/out_elasticsearch_spec.rb b/spec/features/fluentd/setting/out_elasticsearch_spec.rb
new file mode 100644
index 0000000..9d967dc
--- /dev/null
+++ b/spec/features/fluentd/setting/out_elasticsearch_spec.rb
@@ -0,0 +1,38 @@
+require "spec_helper"
+
+describe "out_elasticsearch" do
+ let(:exists_user) { build(:user) }
+ let(:daemon) { build(:fluentd, variant: "td-agent") }
+ let(:match) { "test.out_elasticsearch.#{Time.now.to_i}.*" }
+ let(:location) { daemon_setting_out_elasticsearch_path }
+
+ before do
+ Fluentd.stub(:instance).and_return(daemon)
+ Fluentd::Agent::TdAgent.any_instance.stub(:detached_command).and_return(true)
+ daemon.agent.config_write ""
+
+ visit '/sessions/new'
+ within("form") do
+ fill_in 'session_name', :with => exists_user.name
+ fill_in 'session_password', :with => exists_user.password
+ end
+ click_button I18n.t("terms.sign_in")
+ end
+
+ it "Shown form" do
+ visit location
+ page.should have_css('input[name="fluentd_setting_out_elasticsearch[match]"]')
+ end
+
+ it "Updated config after submit", js: true do
+ daemon.agent.config.should_not include(match)
+ visit location
+ within('#new_fluentd_setting_out_elasticsearch') do
+ fill_in "Match", with: match
+ fill_in "Index name", with: "index"
+ fill_in "Type name", with: "type_name"
+ end
+ click_button I18n.t("fluentd.common.finish")
+ daemon.agent.config.should include(match)
+ end
+end