mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-12 09:17:05 +02:00
Add primitive Fluentd::Configuration class
This commit is contained in:
parent
9b317602b6
commit
07ea7befb8
@ -92,7 +92,7 @@ class Fluentd
|
||||
end
|
||||
|
||||
def config
|
||||
File.read config_file # TODO: Use Fluent::Engine or Fluent::V1Config
|
||||
::Fluentd::Configuration.new(config_file)
|
||||
end
|
||||
|
||||
private
|
||||
|
33
app/models/fluentd/configuration.rb
Normal file
33
app/models/fluentd/configuration.rb
Normal file
@ -0,0 +1,33 @@
|
||||
require 'fluent/config/v1_parser'
|
||||
|
||||
class Fluentd
|
||||
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
|
Loading…
Reference in New Issue
Block a user