From 22dd9c4bdb7eb3f68ee46d5c6a7cc5600bc6cbc4 Mon Sep 17 00:00:00 2001 From: uu59 Date: Wed, 12 Nov 2014 12:50:20 +0900 Subject: [PATCH] Display current setting --- .../fluentd/settings_controller.rb | 4 +++ app/models/fluentd/setting/config.rb | 27 +++++++++++++++++++ .../settings/source_and_output.html.haml | 27 +++++++++++++++++-- config/locales/translation_en.yml | 1 + config/locales/translation_ja.yml | 1 + 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 app/models/fluentd/setting/config.rb diff --git a/app/controllers/fluentd/settings_controller.rb b/app/controllers/fluentd/settings_controller.rb index 00a5e21..4d5ad67 100644 --- a/app/controllers/fluentd/settings_controller.rb +++ b/app/controllers/fluentd/settings_controller.rb @@ -15,4 +15,8 @@ class Fluentd::SettingsController < ApplicationController @fluentd.agent.restart if @fluentd.agent.running? redirect_to daemon_setting_path(@fluentd) end + + def source_and_output + @config = Fluentd::Setting::Config.new(@fluentd.config_file) + end end diff --git a/app/models/fluentd/setting/config.rb b/app/models/fluentd/setting/config.rb new file mode 100644 index 0000000..bddc694 --- /dev/null +++ b/app/models/fluentd/setting/config.rb @@ -0,0 +1,27 @@ +require 'fluent/config' + +class Fluentd + module Setting + class Config + attr_reader :config, :file + + def initialize(config_file) + config = Fluent::Config.parse(IO.read(config_file), config_file, nil, true) + @config = config + @file = config_file + end + + def sources + config.elements.find_all do |elm| + elm.name == "source" + end + end + + def matches + config.elements.find_all do |elm| + elm.name == "match" + end + end + end + end +end diff --git a/app/views/fluentd/settings/source_and_output.html.haml b/app/views/fluentd/settings/source_and_output.html.haml index c5a5cbd..e230408 100644 --- a/app/views/fluentd/settings/source_and_output.html.haml +++ b/app/views/fluentd/settings/source_and_output.html.haml @@ -1,7 +1,5 @@ - page_title t('.page_title') -%h2 - .row.fluentd-setting-inout .col-xs-4 .panel.panel-default @@ -47,3 +45,28 @@ = link_to(daemon_setting_out_forward_path(@fluentd)) do = icon('fa-file-text-o fa-lg') = t("fluentd.common.setup_out_forward") + +%h2= t('.current') + +.row + .col-xs-6 + %h3= t('.in') + - @config.sources.each_with_index do |elm, idx| + .panel.panel-default + .panel-heading{"data-toggle" => "collapse", "href" => "#source#{idx}", "title" => elm.inspect} + = elm["type"] + = icon('fa-caret-down') + .panel-body.collapse{"id" => "source#{idx}"} + %pre= elm.to_s + .col-xs-6 + %h3= t('.out') + - @config.matches.each_with_index do |elm, idx| + .panel.panel-default + .panel-heading{"data-toggle" => "collapse", "href" => "#match#{idx}", "title" => elm.inspect} + = elm["type"] + ( + = elm.arg + ) + = icon('fa-caret-down') + .panel-body.collapse{"id" => "match#{idx}"} + %pre= elm.to_s diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml index c13bab9..664d679 100644 --- a/config/locales/translation_en.yml +++ b/config/locales/translation_en.yml @@ -125,6 +125,7 @@ en: page_title: Add Source and Output in: Source out: Output + current: Current setting show: page_title: Config File in_out_head: In/Out setting diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index 65fdcf9..51b688e 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -124,6 +124,7 @@ ja: page_title: ソースと出力先の追加 in: 入力 out: 出力 + current: 現在の設定 show: page_title: 設定ファイルの編集 edit: