diff --git a/Gemfile.lock b/Gemfile.lock index 2d78f1a..e1e6ce5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ PATH remote: . specs: fluentd-ui (0.0.1.pre) + addressable bcrypt (~> 3.1.5) bundler (~> 1.5) coffee-rails (~> 4.0.0) diff --git a/app/controllers/fluentd_controller.rb b/app/controllers/fluentd_controller.rb index 41c8538..4a98e52 100644 --- a/app/controllers/fluentd_controller.rb +++ b/app/controllers/fluentd_controller.rb @@ -42,6 +42,6 @@ class FluentdController < ApplicationController end def fluentd_params - params.require(:fluentd).permit(:log_file, :pid_file, :config_file, :variant) + params.require(:fluentd).permit(:log_file, :pid_file, :config_file, :variant, :api_endpoint) end end diff --git a/app/models/fluentd.rb b/app/models/fluentd.rb index e36161c..bbfeecf 100644 --- a/app/models/fluentd.rb +++ b/app/models/fluentd.rb @@ -27,6 +27,10 @@ class Fluentd < ActiveRecord::Base }) end + def api + @api ||= Api::Http.new(api_endpoint) + end + def label "#{variant} ##{id}" end diff --git a/app/models/fluentd/api.rb b/app/models/fluentd/api.rb new file mode 100644 index 0000000..8c938a8 --- /dev/null +++ b/app/models/fluentd/api.rb @@ -0,0 +1,6 @@ +require "fluentd/api/http" + +class Fluentd + class Api + end +end diff --git a/app/models/fluentd/api/http.rb b/app/models/fluentd/api/http.rb new file mode 100644 index 0000000..15facb6 --- /dev/null +++ b/app/models/fluentd/api/http.rb @@ -0,0 +1,26 @@ +require "httpclient" +require "addressable/uri" + +class Fluentd + class Api + class Http + def initialize(endpoint) + @endpoint = Addressable::URI.parse(endpoint) + end + + def config + request("/api/config.json") + end + + private + + def request(path) + uri = @endpoint.dup + uri.path = path + res = HTTPClient.get(uri) + JSON.parse res.body + end + end + end +end + diff --git a/app/views/fluentd/_form.html.haml b/app/views/fluentd/_form.html.haml index b266e65..3b929fd 100644 --- a/app/views/fluentd/_form.html.haml +++ b/app/views/fluentd/_form.html.haml @@ -15,4 +15,7 @@ %div.form-group = f.label :config_file = f.text_field :config_file, class: "form-control" + %div.form-group + = f.label :api_endpoint + = f.text_field :api_endpoint, class: "form-control" = f.submit btn, class: "btn btn-primary" diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index 085ad73..0da82e1 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -126,3 +126,4 @@ ja: pid_file: PIDファイル config_file: 設定ファイル variant: タイプ + api_endpoint: APIエンドポイント diff --git a/db/migrate/20140526042609_add_fluentd_api_endpoint.rb b/db/migrate/20140526042609_add_fluentd_api_endpoint.rb new file mode 100644 index 0000000..7ed45a8 --- /dev/null +++ b/db/migrate/20140526042609_add_fluentd_api_endpoint.rb @@ -0,0 +1,5 @@ +class AddFluentdApiEndpoint < ActiveRecord::Migration + def change + add_column :fluentds, :api_endpoint, :string, default: "http://localhost:24220/" + end +end diff --git a/db/schema.rb b/db/schema.rb index a8b2ba2..ebb533b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,15 +11,16 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140522055753) do +ActiveRecord::Schema.define(version: 20140526042609) do create_table "fluentds", force: true do |t| - t.string "variant", null: false + t.string "variant", null: false t.string "pid_file" t.string "log_file" t.string "config_file" t.datetime "created_at" t.datetime "updated_at" + t.string "api_endpoint", default: "http://localhost:24220/" end create_table "login_tokens", force: true do |t| diff --git a/fluentd-ui.gemspec b/fluentd-ui.gemspec index 8e4a45d..63b99fb 100644 --- a/fluentd-ui.gemspec +++ b/fluentd-ui.gemspec @@ -24,6 +24,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'i18n_generators', '1.2.1' spec.add_dependency 'bcrypt', '~> 3.1.5' spec.add_dependency 'sqlite3' + spec.add_dependency 'addressable' spec.add_dependency "font-awesome-rails" spec.add_dependency 'sass-rails', '~> 4.0.3' spec.add_dependency 'uglifier', '>= 1.3.0'