Add Fluentd::Setting::Config#{filters,labels,group_by_label}

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
This commit is contained in:
Kenji Okimoto 2018-08-23 17:09:13 +09:00
parent ea6c6f3765
commit 1fabed0b47
No known key found for this signature in database
GPG Key ID: F9E3E329A5C5E4A1

View File

@ -21,12 +21,48 @@ class Fluentd
end
end
def filters
elements.find_all do |elm|
elm.name == "filter"
end
end
def matches
elements.find_all do |elm|
elm.name == "match"
end
end
def labels
elements.find_all do |elm|
elm.name == "label"
end
end
def group_by_label
hash = Hash.new{|h, k| h[k] = {} }
sources.each do |source|
label = source["@label"] || source["label"]
if label
hash[label][:sources] = [source]
else
hash["ROOT"][:sources] = [source]
end
end
hash["ROOT"][:filters] = filters unless filters.empty?
hash["ROOT"][:matches] = matches unless matches.empty?
labels.each do |label|
hash[label.arg][:filters] = label.elements.find_all do |e|
e.name == "filter"
end
hash[label.arg][:matches] = label.elements.find_all do |e|
e.name == "match"
end
end
hash
end
def write_to_file
return unless Fluentd.instance
Fluentd.instance.agent.config_write formatted