diff --git a/.gitignore b/.gitignore
index fd20d2d..a3b7a58 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,22 +1,17 @@
-.idea/
-
+.vagrant
+Berksfile.lock
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
-pkg/
-
-# Berkshelf
-.vagrant
-/cookbooks
-Berksfile.lock
# Bundler
+Gemfile.lock
bin/*
.bundle/*
.kitchen/
.kitchen.local.yml
-
+.idea
diff --git a/attributes/default.rb b/attributes/default.rb
index 6605984..88cb513 100644
--- a/attributes/default.rb
+++ b/attributes/default.rb
@@ -1,27 +1,30 @@
-default["td_agent"]["api_key"] = ''
+default['td_agent']['api_key'] = ''
-default["td_agent"]["plugins"] = []
+# Enable td-agent Prometheus monitoring
+default['td_agent']['enable_prometheus'] = false
-default["td_agent"]["uid"] = nil
-default["td_agent"]["gid"] = nil
+default['td_agent']['plugins'] = []
-default["td_agent"]["user"] = 'td-agent'
-default["td_agent"]["group"] = 'td-agent'
+default['td_agent']['uid'] = nil
+default['td_agent']['gid'] = nil
-default["td_agent"]["includes"] = false
-default["td_agent"]["default_config"] = true
-default["td_agent"]["template_cookbook"] = 'td-agent'
-default["td_agent"]["in_http"]["enable_api"] = true
-default["td_agent"]["version"] = "2.2.0"
-default["td_agent"]["pinning_version"] = false
-default["td_agent"]["apt_arch"] = 'amd64'
-default["td_agent"]["in_forward"] = {
+default['td_agent']['user'] = 'td-agent'
+default['td_agent']['group'] = 'td-agent'
+
+default['td_agent']['includes'] = true
+default['td_agent']['default_config'] = true
+default['td_agent']['template_cookbook'] = 'td-agent'
+default['td_agent']['in_http']['enable_api'] = true
+default['td_agent']['version'] = '3.1.1'
+default['td_agent']['pinning_version'] = false
+default['td_agent']['apt_arch'] = 'amd64'
+default['td_agent']['in_forward'] = {
port: 24224,
- bind: '0.0.0.0'
+ bind: '0.0.0.0',
}
-default["td_agent"]["in_http"] = {
+default['td_agent']['in_http'] = {
port: 8888,
- bind: '0.0.0.0'
+ bind: '0.0.0.0',
}
-default["td_agent"]["yum_amazon_releasever"] = "$releasever"
+default['td_agent']['yum_amazon_releasever'] = '$releasever'
default['td_agent']['skip_repository'] = false
diff --git a/libraries/helpers.rb b/libraries/helpers.rb
index 11846de..c523df9 100644
--- a/libraries/helpers.rb
+++ b/libraries/helpers.rb
@@ -9,13 +9,11 @@ def self.params_to_text(parameters)
body += params_to_text(param_value)
body += "#{param_key}>\n"
elsif param_value.is_a?(Array)
- if param_value.all? { |array_value| array_value.is_a?(Hash) }
- body += param_value.map { |array_value|
- "<#{param_key}>\n#{params_to_text(array_value)}#{param_key}>\n"
- }.join
- else
- body += "#{param_key} [#{param_value.map { |array_value| array_value.to_s.dump }.join(", ")}]\n"
- end
+ body += if param_value.all? { |array_value| array_value.is_a?(Hash) }
+ param_value.map { |array_value| "<#{param_key}>\n#{params_to_text(array_value)}#{param_key}>\n" }.join
+ else
+ "#{param_key} [#{param_value.map { |array_value| array_value.to_s.dump }.join(', ')}]\n"
+ end
else
body += "#{param_key} #{param_value}\n"
end
@@ -24,13 +22,13 @@ def self.params_to_text(parameters)
body.each_line.map { |line| "#{indent}#{line}" }.join
end
- def self.apply_params_kludge?()
+ def self.apply_params_kludge?
if ::Chef::Config[:treat_deprecation_warnings_as_errors]
# Skip setting up backward compatibility code for `params` (#112)
false
else
# Workaround for backward compatibility for Chef pre-13 (#99)
- chef_major_version = ::Chef::VERSION.split(".").first.to_i
+ chef_major_version = ::Chef::VERSION.split('.').first.to_i
chef_major_version < 13
end
end
diff --git a/libraries/matchers.rb b/libraries/matchers.rb
index 33be9c0..bc4c3b2 100644
--- a/libraries/matchers.rb
+++ b/libraries/matchers.rb
@@ -2,28 +2,31 @@
def install_td_agent_gem(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_gem, :install, resource_name)
end
+
def upgrade_td_agent_gem(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_gem, :upgrade, resource_name)
end
+
def remove_td_agent_gem(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_gem, :remove, resource_name)
end
+
def purge_td_agent_gem(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_gem, :purge, resource_name)
end
-
def create_td_agent_source(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_source, :create, resource_name)
end
+
def delete_td_agent_source(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_source, :delete, resource_name)
end
-
def create_td_agent_match(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_match, :create, resource_name)
end
+
def delete_td_agent_match(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_match, :delete, resource_name)
end
@@ -31,6 +34,7 @@ def delete_td_agent_match(resource_name)
def create_td_agent_filter(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_filter, :create, resource_name)
end
+
def delete_td_agent_filter(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_filter, :delete, resource_name)
end
@@ -38,6 +42,7 @@ def delete_td_agent_filter(resource_name)
def create_td_agent_plugin(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_plugin, :create, resource_name)
end
+
def delete_td_agent_plugin(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:td_agent_plugin, :delete, resource_name)
end
diff --git a/libraries/provider_td_rubygems.rb b/libraries/provider_td_rubygems.rb
index 626484a..d63e650 100644
--- a/libraries/provider_td_rubygems.rb
+++ b/libraries/provider_td_rubygems.rb
@@ -6,14 +6,14 @@
#
# Copyright 2013, Treasure Data, Inc.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
+# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
+# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
@@ -23,13 +23,12 @@ class Chef
class Provider
class Package
class TdRubygems < Chef::Provider::Package::Rubygems
-
class TdGemEnvironment < AlternateGemEnvironment
end
def initialize(new_resource, run_context = nil)
super
- gem_binary_path = new_resource.gem_binary.empty? ? td_gem_binary_path : new_resource.gem_binary
+ gem_binary_path = new_resource.gem_binary.empty? ? td_gem_binary_path : new_resource.gem_binary
@new_resource.gem_binary gem_binary_path
@new_resource.package_name td_plugin_name if @new_resource.plugin
@gem_env = TdGemEnvironment.new(gem_binary_path)
@@ -37,18 +36,18 @@ def initialize(new_resource, run_context = nil)
end
def td_plugin_name
- "fluent-plugin-#{@new_resource.package_name}"
+ "fluent-plugin-#{@new_resource.package_name}"
end
def td_gem_binary_path
if major && major != '1'
# td-agent 2.x or later works with /opt
'/usr/sbin/td-agent-gem'
- elsif node['platform_family'] == "rhel" && node["kernel"]["machine"] == "x86_64"
- "/usr/lib64/fluent/ruby/bin/fluent-gem"
+ elsif node['platform_family'] == 'rhel' && node['kernel']['machine'] == 'x86_64'
+ '/usr/lib64/fluent/ruby/bin/fluent-gem'
else
# older Ubuntu/Debian works with /usr/lib
- "/usr/lib/fluent/ruby/bin/fluent-gem"
+ '/usr/lib/fluent/ruby/bin/fluent-gem'
end
end
end
diff --git a/libraries/resource_td_agent_gem.rb b/libraries/resource_td_agent_gem.rb
index bda3a65..6b1d467 100644
--- a/libraries/resource_td_agent_gem.rb
+++ b/libraries/resource_td_agent_gem.rb
@@ -9,15 +9,15 @@ def initialize(*args)
@provider = Chef::Provider::Package::TdRubygems
@plugin = false
- @gem_binary = ""
+ @gem_binary = ''
end
- def response_file(arg=nil)
- set_or_return(:response_file, arg, :kind_of => String)
+ def response_file(arg = nil)
+ set_or_return(:response_file, arg, kind_of: String)
end
- def plugin(arg=nil)
- set_or_return(:plugin, arg, :kind_of => [ TrueClass, FalseClass ])
+ def plugin(arg = nil)
+ set_or_return(:plugin, arg, kind_of: [TrueClass, FalseClass])
end
end
end
diff --git a/libraries/version.rb b/libraries/version.rb
index ec99177..c0209ca 100644
--- a/libraries/version.rb
+++ b/libraries/version.rb
@@ -1,25 +1,25 @@
-require "rubygems"
+require 'rubygems'
module TdAgent
module Version
def major
unless @major
- version = node["td_agent"]["version"]
+ version = node['td_agent']['version']
@major = version.nil? ? nil : version.to_s.split('.').first
end
@major
end
def reload_available?
- case node["platform_family"]
- when "debian"
+ case node['platform_family']
+ when 'debian'
# td-agent's init script for debian starts supporting reload starting from 2.1.4
- if node["td_agent"]["version"]
- ::Gem::Version.new("2.1.4") <= ::Gem::Version.new(node["td_agent"]["version"].to_s)
+ if node['td_agent']['version']
+ ::Gem::Version.new('2.1.4') <= ::Gem::Version.new(node['td_agent']['version'].to_s)
else
false
end
- when "rhel"
+ when 'rhel'
# td-agent's init script for redhat is supporting reload
true
else
diff --git a/metadata.rb b/metadata.rb
index ad9a413..25bd6f3 100644
--- a/metadata.rb
+++ b/metadata.rb
@@ -1,17 +1,17 @@
-name "td-agent"
-maintainer "Treasure Data, Inc."
-maintainer_email "k@treasure-data.com"
-license "Apache 2.0"
-description "Installs/Configures td-agent"
+name 'td-agent'
+maintainer 'Treasure Data, Inc.'
+maintainer_email 'k@treasure-data.com'
+license 'Apache 2.0'
+description 'Installs/Configures td-agent'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version "3.1.0"
-recipe "td-agent", "td-agent configuration"
+version '3.1.0'
+recipe 'td-agent', 'td-agent configuration'
-chef_version ">= 12" if respond_to?(:chef_version)
-issues_url "https://github.com/treasure-data/chef-td-agent/issues" if respond_to?(:issues_url)
-source_url "https://github.com/treasure-data/chef-td-agent" if respond_to?(:source_url)
+chef_version '>= 12' if respond_to?(:chef_version)
+issues_url 'https://github.com/treasure-data/chef-td-agent/issues' if respond_to?(:issues_url)
+source_url 'https://github.com/treasure-data/chef-td-agent' if respond_to?(:source_url)
-%w{redhat centos debian ubuntu}.each do |os|
+%w[redhat centos debian ubuntu].each do |os|
supports os
end
diff --git a/providers/filter.rb b/providers/filter.rb
index e70b0d6..ec68a42 100644
--- a/providers/filter.rb
+++ b/providers/filter.rb
@@ -21,8 +21,12 @@
include ::TdAgent::Version
+provides :fluentd_filter
+
+use_inline_resources
+
action :create do
- fail 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']
+ raise 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']
template "/etc/td-agent/conf.d/#{new_resource.filter_name}.conf" do
source 'filter.conf.erb'
@@ -32,7 +36,7 @@
# Workaround for backward compatibility for Chef pre-13 (#99)
if TdAgent::Helpers.apply_params_kludge?
- ::Chef::Log.warn("chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent")
+ ::Chef::Log.warn('chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent')
parameters = Hash(new_resource.params).merge(Hash(new_resource.parameters))
else
parameters = new_resource.parameters
@@ -42,10 +46,10 @@
parameters: TdAgent::Helpers.params_to_text(parameters),
tag: new_resource.tag)
cookbook 'td-agent'
- notifies reload_action, 'service[td-agent]'
+ notifies reload_action, 'service[td-agent]', :delayed
end
- new_resource.updated_by_last_action(true)
+ converge_by('created') {}
end
action :delete do
@@ -55,13 +59,13 @@
notifies reload_action, 'service[td-agent]'
end
- new_resource.updated_by_last_action(true)
+ converge_by('deleted') {}
end
def reload_action
if reload_available?
:reload
- else
+ else
:restart
end
end
diff --git a/providers/match.rb b/providers/match.rb
index 8b030fe..ab62a89 100644
--- a/providers/match.rb
+++ b/providers/match.rb
@@ -21,8 +21,12 @@
include ::TdAgent::Version
+provides :fluentd_match
+
+use_inline_resources
+
action :create do
- fail 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']
+ raise 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']
template "/etc/td-agent/conf.d/#{new_resource.match_name}.conf" do
source 'match.conf.erb'
@@ -32,7 +36,7 @@
# Workaround for backward compatibility for Chef pre-13 (#99)
if TdAgent::Helpers.apply_params_kludge?
- ::Chef::Log.warn("chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent")
+ ::Chef::Log.warn('chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent')
parameters = Hash(new_resource.params).merge(Hash(new_resource.parameters))
else
parameters = new_resource.parameters
@@ -42,10 +46,10 @@
parameters: TdAgent::Helpers.params_to_text(parameters),
tag: new_resource.tag)
cookbook 'td-agent'
- notifies reload_action, 'service[td-agent]'
+ notifies reload_action, 'service[td-agent]', :delayed
end
- new_resource.updated_by_last_action(true)
+ converge_by('created') {}
end
action :delete do
@@ -55,7 +59,7 @@
notifies reload_action, 'service[td-agent]'
end
- new_resource.updated_by_last_action(true)
+ converge_by('deleted') {}
end
def reload_action
diff --git a/providers/plugin.rb b/providers/plugin.rb
index 61ede2d..f753cf5 100644
--- a/providers/plugin.rb
+++ b/providers/plugin.rb
@@ -6,24 +6,28 @@
#
#
#
-# Licensed under the Apache License, Version 2.0 (the "License");
+# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
+# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
+provides :fluentd_plugin
+
+use_inline_resources
+
action :create do
directory '/etc/td-agent/plugin' do
- owner "root"
- group "root"
- mode "0755"
+ owner 'root'
+ group 'root'
+ mode '0755'
action :create
end
@@ -33,18 +37,18 @@
group 'root'
mode '0644'
source new_resource.url
- notifies :restart, "service[td-agent]"
+ notifies :restart, 'service[td-agent]'
end
- new_resource.updated_by_last_action(true)
+ converge_by('created') {}
end
action :delete do
file "/etc/td-agent/plugin/#{new_resource.plugin_name}.rb" do
action :delete
only_if { ::File.exist?("/etc/td-agent/plugin/#{new_resource.plugin_name}.rb") }
- notifies :restart, "service[td-agent]"
+ notifies :restart, 'service[td-agent]'
end
- new_resource.updated_by_last_action(true)
+ converge_by('deleted') {}
end
diff --git a/providers/source.rb b/providers/source.rb
index 70a6d93..e6fb704 100644
--- a/providers/source.rb
+++ b/providers/source.rb
@@ -21,8 +21,12 @@
include ::TdAgent::Version
+provides :fluentd_source
+
+use_inline_resources
+
action :create do
- fail 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']
+ raise 'You should set the node[:td_agent][:includes] attribute to true to use this resource.' unless node['td_agent']['includes']
template "/etc/td-agent/conf.d/#{new_resource.source_name}.conf" do
source 'source.conf.erb'
@@ -32,7 +36,7 @@
# Workaround for backward compatibility for Chef pre-13 (#99)
if TdAgent::Helpers.apply_params_kludge?
- ::Chef::Log.warn("chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent")
+ ::Chef::Log.warn('chef-td-agent: property `params` has been renamed to `parameters` since `params` is reserved in Chef 13+. The `params` will not be supported anymore with future release of chef-td-agent')
parameters = Hash(new_resource.params).merge(Hash(new_resource.parameters))
else
parameters = new_resource.parameters
@@ -42,20 +46,20 @@
parameters: TdAgent::Helpers.params_to_text(parameters),
tag: new_resource.tag)
cookbook new_resource.template_source
- notifies reload_action, 'service[td-agent]'
+ notifies reload_action, 'service[td-agent]', :delayed
end
- new_resource.updated_by_last_action(true)
+ converge_by('created') {}
end
action :delete do
file "/etc/td-agent/conf.d/#{new_resource.source_name}.conf" do
action :delete
only_if { ::File.exist?("/etc/td-agent/conf.d/#{new_resource.source_name}.conf") }
- notifies reload_action, 'service[td-agent]'
+ notifies reload_action, 'service[td-agent]', :delayed
end
- new_resource.updated_by_last_action(true)
+ converge_by('deleted') {}
end
def reload_action
diff --git a/recipes/configure.rb b/recipes/configure.rb
index 326b9e8..d75f791 100644
--- a/recipes/configure.rb
+++ b/recipes/configure.rb
@@ -7,43 +7,74 @@
Chef::Recipe.send(:include, TdAgent::Version)
Chef::Provider.send(:include, TdAgent::Version)
-reload_action = (reload_available?) ? :reload : :restart
+reload_action = reload_available? ? :reload : :restart
major_version = major
-template "/etc/td-agent/td-agent.conf" do
- owner node["td_agent"]["user"]
- group node["td_agent"]["group"]
- mode "0644"
+
+template '/etc/td-agent/td-agent.conf' do # ~FC037
+ owner node['td_agent']['user']
+ group node['td_agent']['group']
+ mode '0644'
cookbook node['td_agent']['template_cookbook']
- source "td-agent.conf.erb"
+ source 'td-agent.conf.erb'
variables(
- :major_version => major_version
+ major_version: major_version
)
- notifies reload_action, "service[td-agent]", :delayed
+ notifies reload_action, 'service[td-agent]', :delayed
+end
+
+if node['td_agent']['enable_prometheus']
+ node.normal['td_agent']['plugins'] = (node['td_agent']['plugins'] + ['prometheus']).uniq.sort
end
-node["td_agent"]["plugins"].each do |plugin|
+node['td_agent']['plugins'].each do |plugin|
if plugin.is_a?(Hash)
plugin_name, plugin_attributes = plugin.first
td_agent_gem plugin_name do
plugin true
- %w{action version source options gem_binary}.each do |attr|
+ %w(action version source options gem_binary).each do |attr|
send(attr, plugin_attributes[attr]) if plugin_attributes[attr]
end
- notifies :restart, "service[td-agent]", :delayed
+ notifies :restart, 'service[td-agent]', :delayed
end
elsif plugin.is_a?(String)
td_agent_gem plugin do
plugin true
- notifies :restart, "service[td-agent]", :delayed
+ notifies :restart, 'service[td-agent]', :delayed
end
end
end
-service "td-agent" do
- supports :restart => true, :reload => (reload_action == :reload), :status => true
- restart_command "/etc/init.d/td-agent restart || /etc/init.d/td-agent start"
- action [ :enable, :start ]
+#
+# Enable prometheus exporter
+#
+if node['td_agent']['enable_prometheus']
+ fluentd_source '01_prometheus' do
+ type 'prometheus'
+ end
+
+ fluentd_source '01_prometheus_monitor_agent' do
+ type 'monitor_agent'
+ end
+
+ fluentd_source '01_prometheus_monitor' do
+ type 'prometheus_monitor'
+ end
+
+ fluentd_source '01_prometheus_output_monitor' do
+ type 'prometheus_output_monitor'
+ end
+
+ fluentd_source '01_prometheus_tail_monitor' do
+ type 'prometheus_tail_monitor'
+ end
+end
+
+service 'td-agent' do
+ supports restart: true, reload: (reload_action == :reload), status: true
+ retries 3
+ retry_delay 2
+ action [:enable, :start]
end
##### /var/log/td-agent
diff --git a/recipes/default.rb b/recipes/default.rb
index 9438d9b..31c523a 100644
--- a/recipes/default.rb
+++ b/recipes/default.rb
@@ -5,5 +5,5 @@
# Copyright 2011, Treasure Data, Inc.
#
-include_recipe 'td-agent::install'
-include_recipe 'td-agent::configure'
+include_recipe "#{cookbook_name}::install"
+include_recipe "#{cookbook_name}::configure"
diff --git a/recipes/install.rb b/recipes/install.rb
index a948558..3e3d92d 100644
--- a/recipes/install.rb
+++ b/recipes/install.rb
@@ -7,43 +7,45 @@
Chef::Recipe.send(:include, TdAgent::Version)
Chef::Provider.send(:include, TdAgent::Version)
-group node["td_agent"]["group"] do
- group_name node["td_agent"]["group"]
- gid node["td_agent"]["gid"] if node["td_agent"]["gid"]
+group node['td_agent']['group'] do
+ group_name node['td_agent']['group']
+ gid node['td_agent']['gid'] if node['td_agent']['gid']
system true
- action [:create]
+ action [:create]
+ not_if { node['td_agent']['group'] == 'root' }
end
-user node["td_agent"]["user"] do
+user node['td_agent']['user'] do
comment 'td-agent'
- uid node["td_agent"]["uid"] if node["td_agent"]["uid"]
+ uid node['td_agent']['uid'] if node['td_agent']['uid']
system true
- group node["td_agent"]["group"]
+ group node['td_agent']['group']
home '/var/run/td-agent'
shell '/bin/false'
password nil
manage_home true
- action [:create, :manage]
+ action [:create, :manage]
+ not_if { node['td_agent']['group'] == 'root' }
end
directory '/var/run/td-agent/' do
- owner node["td_agent"]["user"]
- group node["td_agent"]["group"]
+ owner node['td_agent']['user']
+ group node['td_agent']['group']
mode '0755'
action :create
end
directory '/etc/td-agent/' do
- owner node["td_agent"]["user"]
- group node["td_agent"]["group"]
+ owner node['td_agent']['user']
+ group node['td_agent']['group']
mode '0755'
action :create
end
case node['platform_family']
-when "debian"
+when 'debian'
dist = node['lsb']['codename']
- platform = node["platform"]
+ platform = node['platform']
source =
if major.nil? || major == '1'
# version 1.x or no version
@@ -57,44 +59,43 @@
"http://packages.treasuredata.com/#{major}/#{platform}/#{dist}/"
end
- apt_repository "treasure-data" do
+ apt_repository 'treasure-data' do
uri source
- arch node["td_agent"]["apt_arch"]
+ arch node['td_agent']['apt_arch']
distribution dist
- components ["contrib"]
- key "https://packages.treasuredata.com/GPG-KEY-td-agent"
+ components ['contrib']
+ key 'https://packages.treasuredata.com/GPG-KEY-td-agent'
action :add
not_if { node['td_agent']['skip_repository'] }
end
-when "fedora"
- platform = node["platform"]
+when 'fedora'
source =
if major.nil? || major == '1'
- "http://packages.treasuredata.com/redhat/$basearch"
+ 'http://packages.treasuredata.com/redhat/$basearch'
else
# version 2.x or later
- "http://packages.treasuredata.com/#{major}/redhat/7/$basearch"
+ "http://packages.treasuredata.com/#{major}/redhat/7/$basearch"
end
- yum_repository "treasure-data" do
- description "TreasureData"
+ yum_repository 'treasure-data' do
+ description 'TreasureData'
url source
- gpgkey "https://packages.treasuredata.com/GPG-KEY-td-agent"
+ gpgkey 'https://packages.treasuredata.com/GPG-KEY-td-agent'
action :add
not_if { node['td_agent']['skip_repository'] }
end
-when "rhel", "amazon"
+when 'rhel', 'amazon'
# platform_family of Amazon Linux is judged as amazon in new version of ohai: https://github.com/chef/ohai/pull/971
- platform = node["platform"]
+ platform = node['platform']
source =
case major
when nil?,'1'
- "http://packages.treasuredata.com/redhat/$basearch"
+ 'http://packages.treasuredata.com/redhat/$basearch'
when '2'
# version 2.x or later
- if platform == "amazon"
- if node["td_agent"]["yum_amazon_releasever"] != "$releasever"
+ if platform == 'amazon'
+ if node['td_agent']['yum_amazon_releasever'] != '$releasever'
Chef::Log.warn("Treasure Data doesn't guarantee td-agent works on older Amazon Linux releases. td-agent could be used on such environment at your own risk.")
end
"http://packages.treasuredata.com/#{major}/redhat/#{node["td_agent"]["yum_amazon_releasever"]}/$basearch"
@@ -102,35 +103,35 @@
"http://packages.treasuredata.com/#{major}/redhat/$releasever/$basearch"
end
when '3'
- if platform == "amazon"
+ if platform == 'amazon'
amazon_version = node['kernel']['release'].match(/\.amzn([[:digit:]]+)\./)[1]
"https://packages.treasuredata.com/#{major}/amazon/#{amazon_version}/#{node["td_agent"]["yum_amazon_releasever"]}/$basearch"
else
"http://packages.treasuredata.com/#{major}/redhat/$releasever/$basearch"
end
end
- yum_repository "treasure-data" do
- description "TreasureData"
+ yum_repository 'treasure-data' do
+ description 'TreasureData'
url source
- gpgkey "https://packages.treasuredata.com/GPG-KEY-td-agent"
+ gpgkey 'https://packages.treasuredata.com/GPG-KEY-td-agent'
action :add
not_if { node['td_agent']['skip_repository'] }
end
end
-directory "/etc/td-agent/conf.d" do
- owner node["td_agent"]["user"]
- group node["td_agent"]["group"]
- mode "0755"
- only_if { node["td_agent"]["includes"] }
+directory '/etc/td-agent/conf.d' do
+ owner node['td_agent']['user']
+ group node['td_agent']['group']
+ mode '0755'
+ only_if { node['td_agent']['includes'] }
end
-package "td-agent" do
+package 'td-agent' do
retries 3
retry_delay 10
- if node["td_agent"]["pinning_version"]
+ if node['td_agent']['pinning_version']
action :install
- version node["td_agent"]["version"]
+ version node['td_agent']['version']
else
action :upgrade
end
diff --git a/resources/filter.rb b/resources/filter.rb
index 0c5a433..9ca6d23 100644
--- a/resources/filter.rb
+++ b/resources/filter.rb
@@ -21,13 +21,12 @@
actions :create, :delete
default_action :create
+provides :fluentd_filter
-attribute :filter_name, :kind_of => String, :name_attribute => true, :required => true
-attribute :type, :kind_of => String, :required => true
-attribute :tag, :kind_of => String, :required => true
-attribute :parameters, :default => {}
+attribute :filter_name, kind_of: String, name_attribute: true, required: true
+attribute :type, kind_of: String, required: true
+attribute :tag, kind_of: String, required: true
+attribute :parameters, default: {}
# Workaround for backward compatibility for Chef pre-13 (#99)
-if TdAgent::Helpers.apply_params_kludge?
- attribute :params, :default => {}
-end
+attribute :params, default: {} if TdAgent::Helpers.apply_params_kludge?
diff --git a/resources/match.rb b/resources/match.rb
index 9663244..551461f 100644
--- a/resources/match.rb
+++ b/resources/match.rb
@@ -21,13 +21,12 @@
actions :create, :delete
default_action :create
+provides :fluentd_match
-attribute :match_name, :kind_of => String, :name_attribute => true, :required => true
-attribute :type, :kind_of => String, :required => true
-attribute :tag, :kind_of => String, :required => true
-attribute :parameters, :default => {}
+attribute :match_name, kind_of: String, name_attribute: true, required: true
+attribute :type, kind_of: String, required: true
+attribute :tag, kind_of: String, required: true
+attribute :parameters, default: {}
# Workaround for backward compatibility for Chef pre-13 (#99)
-if TdAgent::Helpers.apply_params_kludge?
- attribute :params, :default => {}
-end
+attribute :params, default: {} if TdAgent::Helpers.apply_params_kludge?
diff --git a/resources/plugin.rb b/resources/plugin.rb
index 5fc61f5..813732e 100644
--- a/resources/plugin.rb
+++ b/resources/plugin.rb
@@ -21,6 +21,7 @@
actions :create, :delete
default_action :create
+provides :fluentd_plugin
-attribute :plugin_name, :kind_of => String, :name_attribute => true, :required => true
-attribute :url, :kind_of => String, :required => true
+attribute :plugin_name, kind_of: String, name_attribute: true, required: true
+attribute :url, kind_of: String, required: true
diff --git a/resources/source.rb b/resources/source.rb
index 428ce5f..ffec954 100644
--- a/resources/source.rb
+++ b/resources/source.rb
@@ -21,15 +21,14 @@
actions :create, :delete
default_action :create
+provides :fluentd_source
-attribute :source_name, :kind_of => String, :name_attribute => true, :required => true
-attribute :type, :kind_of => String, :required => true
-attribute :tag, :kind_of => String
-attribute :parameters, :kind_of => Hash, :default => {}
+attribute :source_name, kind_of: String, name_attribute: true, required: true
+attribute :type, kind_of: String, required: true
+attribute :tag, kind_of: String
+attribute :parameters, kind_of: Hash, default: {}
# Workaround for backward compatibility for Chef pre-13 (#99)
-if TdAgent::Helpers.apply_params_kludge?
- attribute :params, :default => {}
-end
+attribute :params, default: {} if TdAgent::Helpers.apply_params_kludge?
-attribute :template_source, :kind_of => String, default: 'td-agent'
+attribute :template_source, kind_of: String, default: 'td-agent'
diff --git a/templates/default/td-agent.conf.erb b/templates/default/td-agent.conf.erb
index 1fe0679..17b2de7 100644
--- a/templates/default/td-agent.conf.erb
+++ b/templates/default/td-agent.conf.erb
@@ -1,3 +1,5 @@
+<% _type = node['td_agent']['version'].to_i < 3 ? 'type' : '@type' %>
+
<% if node['td_agent']['includes'] %>
<% if @major_version.to_i < 2 %>
include conf.d/*.conf
@@ -17,17 +19,24 @@ include conf.d/*.conf
#
# This section matches events whose tag is td.DATABASE.TABLE
- type tdlog
+ <%= _type %> tdlog
apikey <%= node['td_agent']['api_key'] %>
auto_create_table
+<% if @major_version.to_i < 3 %>
buffer_type file
buffer_path /var/log/td-agent/buffer/td
+<% else %>
+
+ <%= _type %> file
+ path /var/log/td-agent/buffer/td
+
+<% end %>
## match tag=debug.** and dump to console
- type stdout
+ <%= _type %> stdout
####
@@ -37,7 +46,7 @@ include conf.d/*.conf
## built-in TCP input
## @see http://docs.fluentd.org/articles/in_forward
- type forward
+ <%= _type %> forward
port <%= node['td_agent']['in_forward']['port'] %>
bind <%= node['td_agent']['in_forward']['bind'] %>
@@ -53,7 +62,7 @@ include conf.d/*.conf
# POST http://localhost:8888/td.myapp.login?json={"user"%3A"me"}
# @see http://docs.fluentd.org/articles/in_http
- type http
+ <%= _type %> http
port <%= node['td_agent']['in_http']['port'] %>
bind <%= node['td_agent']['in_http']['bind'] %>
@@ -61,7 +70,7 @@ include conf.d/*.conf
## live debugging agent
- type debug_agent
+ <%= _type %> debug_agent
bind 127.0.0.1
port 24230