From 3033bfd79f778a22f4c0f81e074747c9818c4ad8 Mon Sep 17 00:00:00 2001 From: uu59 Date: Thu, 22 May 2014 14:20:32 +0900 Subject: [PATCH 01/22] update fluentd gem to v0.10.48+ for Supervisor default_options --- Gemfile.lock | 6 +++--- fluentd-ui.gemspec | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 3e8640c..6d65f36 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,7 +5,7 @@ PATH bcrypt (~> 3.1.5) bundler (~> 1.5) coffee-rails (~> 4.0.0) - fluentd (= 0.10.46) + fluentd (~> 0.10.48) font-awesome-rails haml-rails (~> 0.5.3) httpclient @@ -81,14 +81,14 @@ GEM factory_girl_rails (4.4.1) factory_girl (~> 4.4.0) railties (>= 3.0.0) - fluentd (0.10.46) + fluentd (0.10.48) cool.io (>= 1.1.1, < 2.0.0, != 1.2.0) http_parser.rb (>= 0.5.1, < 0.7.0) json (>= 1.4.3) msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0) sigdump (~> 0.2.2) yajl-ruby (~> 1.0) - font-awesome-rails (4.0.3.1) + font-awesome-rails (4.1.0.0) railties (>= 3.2, < 5.0) haml (4.0.5) tilt diff --git a/fluentd-ui.gemspec b/fluentd-ui.gemspec index 5d63c53..d37dab8 100644 --- a/fluentd-ui.gemspec +++ b/fluentd-ui.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_dependency "fluentd", "0.10.46" + spec.add_dependency "fluentd", "~> 0.10.48" spec.add_dependency 'rails', '4.1.1' spec.add_dependency 'sucker_punch', "~> 1.0.5" spec.add_dependency 'i18n_generators', '1.2.1' From 62e8ea467a88746956d38949fd52e4e902e5d615 Mon Sep 17 00:00:00 2001 From: uu59 Date: Thu, 22 May 2014 15:30:19 +0900 Subject: [PATCH 02/22] Separate fluentd, td-agent, and remote handling by class --- app/controllers/fluentd/daemons_controller.rb | 2 +- app/controllers/fluentd_controller.rb | 2 +- app/models/fluentd.rb | 125 +++++------------- app/models/fluentd/agent.rb | 117 ++++++++++++++++ app/views/fluentd/daemons/show.html.haml | 8 +- app/views/fluentd/index.html.haml | 4 +- db/migrate/20140522055753_create_fluentds.rb | 12 ++ db/schema.rb | 11 +- spec/models/fluentd_spec.rb | 5 + 9 files changed, 188 insertions(+), 98 deletions(-) create mode 100644 app/models/fluentd/agent.rb create mode 100644 db/migrate/20140522055753_create_fluentds.rb create mode 100644 spec/models/fluentd_spec.rb diff --git a/app/controllers/fluentd/daemons_controller.rb b/app/controllers/fluentd/daemons_controller.rb index 1103cf5..56250e6 100644 --- a/app/controllers/fluentd/daemons_controller.rb +++ b/app/controllers/fluentd/daemons_controller.rb @@ -27,6 +27,6 @@ class Fluentd::DaemonsController < ApplicationController private def fluentd - @fluentd ||= Fluentd.new(Rails.root + "tmp" + "fluentd") # TODO + @fluentd = Fluentd.find(params[:fluentd_id]) end end diff --git a/app/controllers/fluentd_controller.rb b/app/controllers/fluentd_controller.rb index 6531678..306810e 100644 --- a/app/controllers/fluentd_controller.rb +++ b/app/controllers/fluentd_controller.rb @@ -2,6 +2,6 @@ class FluentdController < ApplicationController before_action :login_required def index - @daemons = [Fluentd.new(Rails.root + "tmp" + "fluentd")] # TODO + @fluentds = Fluentd.all end end diff --git a/app/models/fluentd.rb b/app/models/fluentd.rb index 91e8e01..ef684a6 100644 --- a/app/models/fluentd.rb +++ b/app/models/fluentd.rb @@ -1,109 +1,56 @@ -Bundler.require(:default, :development) +class Fluentd < ActiveRecord::Base + validate :validate_permissions -require 'fluent/log' -require 'fluent/env' -require 'fluent/version' -require 'fluent/supervisor' - -class Fluentd - attr_reader :root_dir - - def initialize(root_dir) - @root_dir = root_dir - FileUtils.mkdir_p @root_dir + def fluentd? + variant == "fluentd" end - def pid_file - File.join(root_dir, "fluentd.pid") - end - - def pid - return unless File.exists?(pid_file) - File.read(pid_file) - end - - def log_file - File.join(root_dir, "fluentd.log") - end - - def config_file - file = File.join(root_dir, "fluentd.conf") - unless File.exists?(file) - File.open(file, "w") {|f| f.write "\ntype forward\n" } # TODO - end - file - end - - def plugin_dir - dir = File.join(root_dir, "fluentd", "plugins") - unless Dir.exist?(dir) - FileUtils.mkdir_p(dir) - end - dir - end - - def options - # TODO: https://github.com/fluent/fluentd/pull/315 - { - :config_path => Fluent::DEFAULT_CONFIG_PATH, - :plugin_dirs => [Fluent::DEFAULT_PLUGIN_DIR], - :log_level => Fluent::Log::LEVEL_INFO, - :log_path => nil, - :daemonize => false, - :libs => [], - :setup_path => nil, - :chuser => nil, - :chgroup => nil, - :suppress_interval => 0, - :suppress_repeated_stacktrace => false, - :use_v1_config => false, - }.merge({ - :use_v1_config => true, - :plugin_dirs => [plugin_dir], - :config_path => config_file, - :daemonize => pid_file, - :log_path => log_file, - :log_level => Fluent::Log::LEVEL_INFO, - }) - end - - def running? - pid && system("/bin/kill -0 #{pid}", :out => File::NULL, :err => File::NULL) + def td_agent? + variant == "td-agent" end def start - return if running? - spawn("bundle exec fluentd #{options_to_argv(options)}") # TODO + agent.start end def stop - return unless running? - system("/bin/kill -TERM #{pid}") - File.unlink(pid_file) + agent.stop + end + + def reload + agent.reload end - def reload - return unless running? - system("/bin/kill -HUP #{pid}") + def running? + agent.running? end def log - File.read log_file # TODO: large log file + # File.read log_file # TODO: large log file + "log log" end - def config - ::Fluentd::Configuration.new(config_file) + def agent + klass = variant.underscore.camelize + @agent ||= Agent.const_get(klass).new({ + :pid_file => pid_file, + :log_file => log_file, + :config_file => config_file, + }) end - private - - def options_to_argv(options) - argv = "" - argv << " --use-v1-config" if options[:use_v1_config] - argv << " -c #{options[:config_path]}" if options[:config_path].present? - argv << " -p #{options[:plugin_dir].first}" if options[:plugin_dir].present? - argv << " -d #{options[:daemonize]}" if options[:daemonize].present? - argv << " -o #{options[:log_path]}" if options[:log_path].present? - argv + def validate_permissions + %w(pid_file log_file config_file).each do |column| + path = send(column) + if File.exist?(path) + unless File.writable?(path) + errors.add(column, "#{path} fa") + end + else + unless File.world_writable?(File.dirname(path)) + errors.add(column, "#{path} fa") + end + end + end end end diff --git a/app/models/fluentd/agent.rb b/app/models/fluentd/agent.rb new file mode 100644 index 0000000..7718079 --- /dev/null +++ b/app/models/fluentd/agent.rb @@ -0,0 +1,117 @@ +require 'fluent/log' +require 'fluent/env' +require 'fluent/version' +require 'fluent/supervisor' + +class Fluentd + class Agent + class Base + attr_reader :extra_options + + def initialize(options = {}) + @extra_options = options + end + + def pid + return unless File.exists?(pid_file) + File.read(pid_file) + end + + def running? + pid && system("/bin/kill -0 #{pid}", :out => File::NULL, :err => File::NULL) + end + + %w(pid_file log_file config_file start stop reload).each do |method| + define_method(method) do + raise NotImplementedError + end + end + + # pidfile + # td-agent: /var/run/td-agent/td-agent.pid + # - https://github.com/treasure-data/td-agent/blob/master/td-agent.logrotate#L10 + # - https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.init#L25 + # fluentd: nothing (or --daemon PIDFILE) + # + # logfile + # td-agent: /var/log/td-agent/td-agent.log + # - https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.init#L28 + # fluentd: stdout (or --log LOGFILE) + # + # config file + # td-agent: /etc/td-agent/td-agent.conf + # - https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.postinst#L69 + # fluentd: /etc/fluent/fluent.conf (by fluentd -s) + end + + class Fluentd < Base + def pid_file + extra_options[:pid_file] || "/var/run/fluent.pid" + end + + def log_file + extra_options[:log_file] || "/var/log/fluent.log" + end + + def config_file + extra_options[:config_file] || "/etc/fluent/fluent.conf" + end + + def options_to_argv + argv = "" + argv << " --use-v1-config" + argv << " -c #{config_file}" + argv << " -d #{pid_file}" + argv << " -o #{log_file}" + argv + end + + def start + return if running? + spawn("bundle exec fluentd #{options_to_argv}") # TODO + end + + def stop + return unless running? + system("/bin/kill -TERM #{pid}") + File.unlink(pid_file) + end + + def reload + return unless running? + system("/bin/kill -HUP #{pid}") + end + end + + class TdAgent < Base + def pid_file + "/var/run/td-agent/td-agent.pid" + end + + def log_file + "/var/log/td-agent/td-agent.log" + end + + def config_file + "/etc/td-agent/td-agent.conf" + end + + def start + system('/etc/init.d/td-agent start') + end + + def stop + system('/etc/init.d/td-agent stop') + end + + def reload + # NOTE: td-agent has no reload command + # https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.init#L156 + system('/etc/init.d/td-agent restart') + end + end + + class Remote < Base # TODO + end + end +end diff --git a/app/views/fluentd/daemons/show.html.haml b/app/views/fluentd/daemons/show.html.haml index 9542817..5d06080 100644 --- a/app/views/fluentd/daemons/show.html.haml +++ b/app/views/fluentd/daemons/show.html.haml @@ -1,7 +1,7 @@ %h1 = @fluentd.running? ? "running" : "stopped" - = link_to "start", start_fluentd_daemon_path(id: 1), method: :put, remote: true - = link_to "stop", stop_fluentd_daemon_path(id: 1), method: :put, remote: true - = link_to "reload", reload_fluentd_daemon_path(id: 1), method: :put, remote: true - = link_to "log", log_fluentd_daemon_path(id: 1) + = link_to "start", start_fluentd_daemon_path(@fluentd), method: :put, remote: true + = link_to "stop", stop_fluentd_daemon_path(@fluentd), method: :put, remote: true + = link_to "reload", reload_fluentd_daemon_path(@fluentd), method: :put, remote: true + = link_to "log", log_fluentd_daemon_path(@fluentd) diff --git a/app/views/fluentd/index.html.haml b/app/views/fluentd/index.html.haml index 4c6c2ec..5f938c2 100644 --- a/app/views/fluentd/index.html.haml +++ b/app/views/fluentd/index.html.haml @@ -1,2 +1,2 @@ -- @daemons.each do |d| - = link_to d, fluentd_daemon_path(fluentd_id: 1) # TODO +- @fluentds.each do |d| + = link_to d, fluentd_daemon_path(d) # TODO diff --git a/db/migrate/20140522055753_create_fluentds.rb b/db/migrate/20140522055753_create_fluentds.rb new file mode 100644 index 0000000..7c46301 --- /dev/null +++ b/db/migrate/20140522055753_create_fluentds.rb @@ -0,0 +1,12 @@ +class CreateFluentds < ActiveRecord::Migration + def change + create_table :fluentds do |t| + t.string :variant, null: false # fluentd, td-agent, or remote + t.string :pid_file + t.string :log_file + t.string :config_file + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index bbe40f2..a8b2ba2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,16 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140522023140) do +ActiveRecord::Schema.define(version: 20140522055753) do + + create_table "fluentds", force: true do |t| + 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" + end create_table "login_tokens", force: true do |t| t.string "token_id", null: false diff --git a/spec/models/fluentd_spec.rb b/spec/models/fluentd_spec.rb new file mode 100644 index 0000000..a2876ac --- /dev/null +++ b/spec/models/fluentd_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Fluentd do + pending "add some examples to (or delete) #{__FILE__}" +end From dc36bd9e336c42c0b7a8e4904a61854594092dc3 Mon Sep 17 00:00:00 2001 From: uu59 Date: Thu, 22 May 2014 15:56:01 +0900 Subject: [PATCH 03/22] Remove unnecessary method bridge --- app/controllers/fluentd/daemons_controller.rb | 8 ++++---- app/models/fluentd.rb | 17 ----------------- app/models/fluentd/agent.rb | 4 ++++ 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/app/controllers/fluentd/daemons_controller.rb b/app/controllers/fluentd/daemons_controller.rb index 56250e6..09ebdc8 100644 --- a/app/controllers/fluentd/daemons_controller.rb +++ b/app/controllers/fluentd/daemons_controller.rb @@ -6,22 +6,22 @@ class Fluentd::DaemonsController < ApplicationController end def start - fluentd.start + fluentd.agent.start render :show end def stop - fluentd.stop + fluentd.agent.stop render :show end def reload - fluentd.reload + fluentd.agent.reload render :show end def log - render text: fluentd.log, content_type: "text/plain" + render text: fluentd.agent.log, content_type: "text/plain" end private diff --git a/app/models/fluentd.rb b/app/models/fluentd.rb index ef684a6..63fb660 100644 --- a/app/models/fluentd.rb +++ b/app/models/fluentd.rb @@ -9,27 +9,10 @@ class Fluentd < ActiveRecord::Base variant == "td-agent" end - def start - agent.start - end - - def stop - agent.stop - end - - def reload - agent.reload - end - def running? agent.running? end - def log - # File.read log_file # TODO: large log file - "log log" - end - def agent klass = variant.underscore.camelize @agent ||= Agent.const_get(klass).new({ diff --git a/app/models/fluentd/agent.rb b/app/models/fluentd/agent.rb index 7718079..d225583 100644 --- a/app/models/fluentd/agent.rb +++ b/app/models/fluentd/agent.rb @@ -21,6 +21,10 @@ class Fluentd pid && system("/bin/kill -0 #{pid}", :out => File::NULL, :err => File::NULL) end + def log + File.read(log_file) # TODO + end + %w(pid_file log_file config_file start stop reload).each do |method| define_method(method) do raise NotImplementedError From 2c431b4eb6e5a1cad88bf121032016a2c394d881 Mon Sep 17 00:00:00 2001 From: uu59 Date: Thu, 22 May 2014 16:11:25 +0900 Subject: [PATCH 04/22] Fix permission error messages --- app/models/fluentd.rb | 7 +++++-- config/locales/translation_ja.yml | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/fluentd.rb b/app/models/fluentd.rb index 63fb660..559f074 100644 --- a/app/models/fluentd.rb +++ b/app/models/fluentd.rb @@ -27,11 +27,14 @@ class Fluentd < ActiveRecord::Base path = send(column) if File.exist?(path) unless File.writable?(path) - errors.add(column, "#{path} fa") + errors.add(column, :lack_write_permission) + end + unless File.readable?(path) + errors.add(column, :lack_read_permission) end else unless File.world_writable?(File.dirname(path)) - errors.add(column, "#{path} fa") + errors.add(column, :lack_write_permission) end end end diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index 40fbffd..0975622 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -66,6 +66,8 @@ ja: errors: messages: wrong_password: が違います + lack_read_permission: の読み込み権限がありません + lack_write_permission: の書き込み権限がありません models: user: user #g @@ -78,3 +80,7 @@ ja: current_password: 現在のパスワード password: パスワード password_confirmation: パスワード(確認) + fluentd: + log_file: ログファイル + pid_file: PIDファイル + config_file: 設定ファイル From feb392cd753efbc0ae60346074ff1f892b27c1a1 Mon Sep 17 00:00:00 2001 From: uu59 Date: Thu, 22 May 2014 16:25:41 +0900 Subject: [PATCH 05/22] trivial refactoring --- app/controllers/fluentd/daemons_controller.rb | 13 ++++++------- app/controllers/fluentd_controller.rb | 2 -- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/controllers/fluentd/daemons_controller.rb b/app/controllers/fluentd/daemons_controller.rb index 09ebdc8..cf3c88e 100644 --- a/app/controllers/fluentd/daemons_controller.rb +++ b/app/controllers/fluentd/daemons_controller.rb @@ -1,32 +1,31 @@ class Fluentd::DaemonsController < ApplicationController - before_action :login_required - before_action :fluentd + before_action :find_fluentd def show end def start - fluentd.agent.start + @fluentd.agent.start render :show end def stop - fluentd.agent.stop + @fluentd.agent.stop render :show end def reload - fluentd.agent.reload + @fluentd.agent.reload render :show end def log - render text: fluentd.agent.log, content_type: "text/plain" + render text: @fluentd.agent.log, content_type: "text/plain" end private - def fluentd + def find_fluentd @fluentd = Fluentd.find(params[:fluentd_id]) end end diff --git a/app/controllers/fluentd_controller.rb b/app/controllers/fluentd_controller.rb index 306810e..2abe437 100644 --- a/app/controllers/fluentd_controller.rb +++ b/app/controllers/fluentd_controller.rb @@ -1,6 +1,4 @@ class FluentdController < ApplicationController - before_action :login_required - def index @fluentds = Fluentd.all end From c23d5254b39798c3b390b46709e318b4af0b0e3e Mon Sep 17 00:00:00 2001 From: uu59 Date: Thu, 22 May 2014 17:24:27 +0900 Subject: [PATCH 06/22] Add Fluentd CRUD --- app/controllers/fluentd_controller.rb | 42 +++++++++++++++++++++++ app/models/fluentd.rb | 21 ++++++++++++ app/models/fluentd/agent.rb | 48 +++++++++++++-------------- app/views/fluentd/_form.html.haml | 18 ++++++++++ app/views/fluentd/edit.html.haml | 3 ++ app/views/fluentd/index.html.haml | 13 +++++++- app/views/fluentd/new.html.haml | 3 ++ config/locales/translation_ja.yml | 22 ++++++++++++ config/routes.rb | 2 +- 9 files changed, 146 insertions(+), 26 deletions(-) create mode 100644 app/views/fluentd/_form.html.haml create mode 100644 app/views/fluentd/edit.html.haml create mode 100644 app/views/fluentd/new.html.haml diff --git a/app/controllers/fluentd_controller.rb b/app/controllers/fluentd_controller.rb index 2abe437..dbad858 100644 --- a/app/controllers/fluentd_controller.rb +++ b/app/controllers/fluentd_controller.rb @@ -1,5 +1,47 @@ class FluentdController < ApplicationController + before_action :find_fluentd, only: [:edit, :update, :destroy] + def index @fluentds = Fluentd.all end + + def new + @fluentd = Fluentd.new(Fluentd::Agent::Fluentd::DEFAULT_OPTIONS) # TODO: not fluentd type + end + + def create + @fluentd = Fluentd.new(fluentd_params) + unless @fluentd.save + return render :new + end + redirect_to fluentd_index_path + end + + def edit + end + + def update + # TODO: should restart if changed file path? or just do "dirty" flagged? + @fluentd.update_attributes(fluentd_params) + unless @fluentd.save + return render :edit + end + redirect_to fluentd_index_path + end + + def destroy + @fluentd.agent.stop if @fluentd.agent.running? + @fluentd.destroy + redirect_to fluentd_index_path + end + + private + + def find_fluentd + @fluentd = Fluentd.find(params[:id]) + end + + def fluentd_params + params.require(:fluentd).permit(:log_file, :pid_file, :config_file, :variant) + end end diff --git a/app/models/fluentd.rb b/app/models/fluentd.rb index 559f074..0123d7d 100644 --- a/app/models/fluentd.rb +++ b/app/models/fluentd.rb @@ -1,6 +1,15 @@ class Fluentd < ActiveRecord::Base + before_validation :expand_paths + validates :variant, inclusion: { in: proc { Fluentd.variants } } + validates :log_file, presence: true + validates :pid_file, presence: true + validates :config_file, presence: true validate :validate_permissions + def self.variants + %w(fluentd) # TODO: + end + def fluentd? variant == "fluentd" end @@ -22,10 +31,22 @@ class Fluentd < ActiveRecord::Base }) end + def expand_paths + %w(pid_file log_file config_file).each do |column| + self.send("#{column}=", File.expand_path(send(column))) + end + end + def validate_permissions %w(pid_file log_file config_file).each do |column| path = send(column) + next if path.empty? # if empty, presence: true will catch it + if File.exist?(path) + if File.directory?(path) + errors.add(column, :is_a_directory) + end + unless File.writable?(path) errors.add(column, :lack_write_permission) end diff --git a/app/models/fluentd/agent.rb b/app/models/fluentd/agent.rb index d225583..63eb79a 100644 --- a/app/models/fluentd/agent.rb +++ b/app/models/fluentd/agent.rb @@ -22,10 +22,22 @@ class Fluentd end def log - File.read(log_file) # TODO + File.read(log_file) # TODO: large log file end - %w(pid_file log_file config_file start stop reload).each do |method| + def pid_file + extra_options[:pid_file] || DEFAULT_OPTIONS[:pid_file] + end + + def log_file + extra_options[:log_file] || DEFAULT_OPTIONS[:pid_file] + end + + def config_file + extra_options[:config_file] || DEFAULT_OPTIONS[:pid_file] + end + + %w(start stop reload).each do |method| define_method(method) do raise NotImplementedError end @@ -49,17 +61,11 @@ class Fluentd end class Fluentd < Base - def pid_file - extra_options[:pid_file] || "/var/run/fluent.pid" - end - - def log_file - extra_options[:log_file] || "/var/log/fluent.log" - end - - def config_file - extra_options[:config_file] || "/etc/fluent/fluent.conf" - end + DEFAULT_OPTIONS = { + :pid_file => "/var/run/fluent.pid", + :log_file => "/var/log/fluent.log", + :config_file => "/etc/fluent/fluent.conf", + } def options_to_argv argv = "" @@ -88,17 +94,11 @@ class Fluentd end class TdAgent < Base - def pid_file - "/var/run/td-agent/td-agent.pid" - end - - def log_file - "/var/log/td-agent/td-agent.log" - end - - def config_file - "/etc/td-agent/td-agent.conf" - end + DEFAULT_OPTIONS = { + :pid_file => "/var/run/td-agent/td-agent.pid", + :log_file => "/var/log/td-agent/td-agent.log", + :config_file => "/etc/td-agent/td-agent.conf", + } def start system('/etc/init.d/td-agent start') diff --git a/app/views/fluentd/_form.html.haml b/app/views/fluentd/_form.html.haml new file mode 100644 index 0000000..b266e65 --- /dev/null +++ b/app/views/fluentd/_form.html.haml @@ -0,0 +1,18 @@ +%div.col-lg-6 + - @fluentd.errors.full_messages.each do |e| + %div.alert.alert-danger= e + + = form_for(:fluentd, url: url, method: method) do |f| + %div.form-group + = f.label :variant + = f.select :variant, Fluentd.variants + %div.form-group + = f.label :pid_file + = f.text_field :pid_file, class: "form-control" + %div.form-group + = f.label :log_file + = f.text_field :log_file, class: "form-control" + %div.form-group + = f.label :config_file + = f.text_field :config_file, class: "form-control" + = f.submit btn, class: "btn btn-primary" diff --git a/app/views/fluentd/edit.html.haml b/app/views/fluentd/edit.html.haml new file mode 100644 index 0000000..3a1facb --- /dev/null +++ b/app/views/fluentd/edit.html.haml @@ -0,0 +1,3 @@ +- page_title t('.page_title') + += render partial: "form", locals: { btn: t(".update"), url: fluentd_path(@fluentd), method: :patch } diff --git a/app/views/fluentd/index.html.haml b/app/views/fluentd/index.html.haml index 5f938c2..c078f03 100644 --- a/app/views/fluentd/index.html.haml +++ b/app/views/fluentd/index.html.haml @@ -1,2 +1,13 @@ +- page_title t('.page_title') + +%p= link_to t(".new"), new_fluentd_path + - @fluentds.each do |d| - = link_to d, fluentd_daemon_path(d) # TODO + %div.col-lg-6 + %div.panel.panel-default + %div.panel-heading + %h4= d.inspect + %div.panel-body + = link_to d, fluentd_daemon_path(d) # TODO + = link_to t(".edit"), edit_fluentd_path(d) + = link_to t(".destroy"), fluentd_path(d), method: :delete diff --git a/app/views/fluentd/new.html.haml b/app/views/fluentd/new.html.haml new file mode 100644 index 0000000..95c4d3a --- /dev/null +++ b/app/views/fluentd/new.html.haml @@ -0,0 +1,3 @@ +- page_title t('.page_title') + += render partial: "form", locals: { btn: t(".create"), url: fluentd_index_path, method: :post } diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index 0975622..bce32c1 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -16,6 +16,11 @@ ja: fluent_version: "fluentd %{version}" no_alert: なし update_password: パスワード更新 + create: 作成 + update: 更新 + edit: 編集 + destroy: 削除 + new: 新規作成 plugins: common: &plugin_common @@ -45,6 +50,21 @@ ja: <<: *terms page_title: ユーザー管理 + fluentd: &fluentd + common: &fluentd_common + <<: *terms + form: + <<: *fluentd_common + index: + <<: *fluentd_common + page_title: fluentd + new: + <<: *fluentd_common + page_title: fluentd | 追加 + edit: + <<: *fluentd_common + page_title: fluentd | 編集 + misc: common: &misc_common <<: *terms @@ -68,6 +88,7 @@ ja: wrong_password: が違います lack_read_permission: の読み込み権限がありません lack_write_permission: の書き込み権限がありません + is_a_directory: はディレクトリです。ファイルを指定してください models: user: user #g @@ -84,3 +105,4 @@ ja: log_file: ログファイル pid_file: PIDファイル config_file: 設定ファイル + variant: タイプ diff --git a/config/routes.rb b/config/routes.rb index b41c889..78077d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do root "fluentd#index" # TODO: change to dashboard - resources :fluentd, only: [:index] do + resources :fluentd do resource :daemon, only: [:show], module: :fluentd do put "start" put "stop" From 5a4fd2b791c3e31af7efe8e3874543a054dbd747 Mon Sep 17 00:00:00 2001 From: uu59 Date: Thu, 22 May 2014 17:48:05 +0900 Subject: [PATCH 07/22] Add i18n --- app/views/fluentd/daemons/show.html.haml | 11 ++++++----- config/locales/translation_ja.yml | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/views/fluentd/daemons/show.html.haml b/app/views/fluentd/daemons/show.html.haml index 5d06080..3e1677a 100644 --- a/app/views/fluentd/daemons/show.html.haml +++ b/app/views/fluentd/daemons/show.html.haml @@ -1,7 +1,8 @@ %h1 - = @fluentd.running? ? "running" : "stopped" + = @fluentd.inspect + = @fluentd.running? ? t(".running") : t(".stopped") - = link_to "start", start_fluentd_daemon_path(@fluentd), method: :put, remote: true - = link_to "stop", stop_fluentd_daemon_path(@fluentd), method: :put, remote: true - = link_to "reload", reload_fluentd_daemon_path(@fluentd), method: :put, remote: true - = link_to "log", log_fluentd_daemon_path(@fluentd) += link_to t(".start"), start_fluentd_daemon_path(@fluentd), method: :put, remote: true += link_to t(".stop"), stop_fluentd_daemon_path(@fluentd), method: :put, remote: true += link_to t(".reload"), reload_fluentd_daemon_path(@fluentd), method: :put, remote: true += link_to t(".log"), log_fluentd_daemon_path(@fluentd) diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index bce32c1..5085b80 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -53,6 +53,12 @@ ja: fluentd: &fluentd common: &fluentd_common <<: *terms + start: 開始 + stop: 停止 + reload: リロード + log: ログ + stopped: 停止中 + running: 稼働中 form: <<: *fluentd_common index: @@ -64,6 +70,9 @@ ja: edit: <<: *fluentd_common page_title: fluentd | 編集 + daemons: + show: + <<: *fluentd_common misc: common: &misc_common From 3034a42d9b462d4dc0687217eddcf42a193e87b4 Mon Sep 17 00:00:00 2001 From: uu59 Date: Thu, 22 May 2014 18:04:53 +0900 Subject: [PATCH 08/22] Styling --- app/views/fluentd/daemons/show.html.haml | 5 +++-- app/views/fluentd/index.html.haml | 11 ++++++----- app/views/shared/_global_nav.html.erb | 8 ++++++++ config/locales/translation_ja.yml | 2 ++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/views/fluentd/daemons/show.html.haml b/app/views/fluentd/daemons/show.html.haml index 3e1677a..a863c1e 100644 --- a/app/views/fluentd/daemons/show.html.haml +++ b/app/views/fluentd/daemons/show.html.haml @@ -1,5 +1,6 @@ -%h1 - = @fluentd.inspect +- page_title t('.page_title', label: "##{@fluentd.id}") + +%h4 = @fluentd.running? ? t(".running") : t(".stopped") = link_to t(".start"), start_fluentd_daemon_path(@fluentd), method: :put, remote: true diff --git a/app/views/fluentd/index.html.haml b/app/views/fluentd/index.html.haml index c078f03..0b52820 100644 --- a/app/views/fluentd/index.html.haml +++ b/app/views/fluentd/index.html.haml @@ -1,13 +1,14 @@ - page_title t('.page_title') -%p= link_to t(".new"), new_fluentd_path +%p= link_to icon('fa-plus') << " " << t(".new"), new_fluentd_path - @fluentds.each do |d| %div.col-lg-6 %div.panel.panel-default %div.panel-heading - %h4= d.inspect + %h4 + = "fluentd ##{d.id}" + = link_to t(".edit"), edit_fluentd_path(d) + = link_to t(".destroy"), fluentd_path(d), method: :delete %div.panel-body - = link_to d, fluentd_daemon_path(d) # TODO - = link_to t(".edit"), edit_fluentd_path(d) - = link_to t(".destroy"), fluentd_path(d), method: :delete + = link_to t(".operation"), fluentd_daemon_path(d) # TODO diff --git a/app/views/shared/_global_nav.html.erb b/app/views/shared/_global_nav.html.erb index fb03829..f68fab9 100644 --- a/app/views/shared/_global_nav.html.erb +++ b/app/views/shared/_global_nav.html.erb @@ -2,6 +2,14 @@
  • <%= link_to_other icon("fa-dashboard fa-fw") << " Dashboard", root_path %>
  • +
  • + <%= link_to_other icon("fa-puzzle-piece fa-fw") << " fluentd", fluentd_index_path %> + +
  • <%= link_to_other icon("fa-cogs fa-fw") << " " << t('terms.plugins') << icon('fa pull-right fa-caret-down'), plugins_path %>