Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.2
- PR#xx - Fix Chef-13 warning for https://docs.chef.io/deprecations_namespace_collisions.html
- Cleanup all foodcritic warnings

## 0.9.1

- PR#65 - Chef-13 amazon compatibility fix
Expand Down
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name 'telegraf'
maintainer 'E Camden Fisher'
maintainer_email '[email protected]'
license 'apache2'
license 'Apache-2.0'
description 'Installs/Configures telegraf'
long_description 'Installs/Configures telegraf'
version '0.9.1'
version '0.9.2'
source_url 'https://github.com/NorthPage/telegraf-cookbook'
issues_url 'https://github.com/NorthPage/telegraf-cookbook/issues'

Expand Down
11 changes: 5 additions & 6 deletions resources/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

property :name, String, name_property: true
property :config, Hash, default: {}
property :outputs, Hash, default: {}
property :inputs, Hash, default: {}
Expand All @@ -43,9 +42,9 @@
action :nothing
end

file path do
file new_resource.path do
content TomlRB.dump(new_resource.config)
unless node.platform_family? 'windows'
unless platform_family? 'windows'
user 'root'
group 'telegraf'
mode '0644'
Expand All @@ -55,7 +54,7 @@

telegraf_d = ::File.dirname(new_resource.path) + '/telegraf.d'

telegraf_outputs name do
telegraf_outputs new_resource.name do
path telegraf_d
outputs new_resource.outputs
reload false
Expand All @@ -64,7 +63,7 @@
notifies :restart, "service[telegraf_#{new_resource.name}]", :delayed
end

telegraf_inputs name do
telegraf_inputs new_resource.name do
path telegraf_d
inputs new_resource.inputs
reload false
Expand All @@ -73,7 +72,7 @@
notifies :restart, "service[telegraf_#{new_resource.name}]", :delayed
end

telegraf_perf_counters name do
telegraf_perf_counters new_resource.name do
path telegraf_d
perf_counters new_resource.perf_counters
reload false
Expand Down
12 changes: 5 additions & 7 deletions resources/inputs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

property :name, String, name_property: true
property :inputs, Hash, required: true
property :path, String,
default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
property :path, String, default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
property :service_name, String, default: 'default'
property :reload, kind_of: [TrueClass, FalseClass], default: true
property :rootonly, kind_of: [TrueClass, FalseClass], default: false

default_action :create

action :create do
directory path do
directory new_resource.path do
recursive true
action :create
end
Expand All @@ -51,19 +49,19 @@

file "#{new_resource.path}/#{new_resource.name}_inputs.conf" do
content TomlRB.dump('inputs' => new_resource.inputs)
unless node.platform_family? 'windows'
unless platform_family? 'windows'
user 'root'
group 'telegraf'
mode new_resource.rootonly ? '0640' : '0644'
end
sensitive new_resource.rootonly
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
end
end

action :delete do
file "#{new_resource.path}/#{new_resource.name}_inputs.conf" do
action :delete
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
end
end
21 changes: 10 additions & 11 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# limitations under the License.

property :include_repository, [TrueClass, FalseClass], default: true
property :name, String, name_property: true
property :install_version, [String, nil], default: nil
property :install_type, String, default: 'package'

Expand All @@ -41,7 +40,7 @@
gpgkey "#{node['telegraf']['package_url']}/influxdb.key"
only_if { new_resource.include_repository }
end
elsif node.platform_family? 'debian'
elsif platform_family? 'debian'
package 'apt-transport-https' do
only_if { new_resource.include_repository }
end
Expand All @@ -54,9 +53,9 @@
key "#{node['telegraf']['package_url']}/influxdb.key"
only_if { new_resource.include_repository }
end
elsif node.platform_family? 'windows'
elsif platform_family? 'windows'
include_recipe 'chocolatey'
elsif node.platform_family? 'mac_os_x'
elsif platform_family? 'mac_os_x'
include_recipe 'homebrew'

group 'telegraf' do
Expand All @@ -74,23 +73,23 @@
raise "I do not support your platform: #{node['platform_family']}"
end

if node.platform_family? 'windows'
if platform_family? 'windows'
chocolatey_package 'telegraf' do
version install_version
version new_resource.install_version
source node['telegraf']['chocolatey_source']
action :install
end
else
package 'telegraf' do
version install_version
version new_resource.install_version
action :install
end
end
when 'tarball'
# TODO: implement me
Chef::Log.warn('Sorry, installing from a tarball is not yet implemented.')
when 'file'
if node.platform_family?('rhel', 'amazon')
if platform_family?('rhel', 'amazon')
file_name = "telegraf-#{new_resource.install_version}.x86_64.rpm"
remote_file "#{Chef::Config[:file_cache_path]}/#{file_name}" do
source "#{node['telegraf']['download_urls']['rhel']}/#{file_name}"
Expand All @@ -102,7 +101,7 @@
source "#{Chef::Config[:file_cache_path]}/#{file_name}"
action :install
end
elsif node.platform_family? 'debian'
elsif platform_family? 'debian'
# NOTE: file_name would be influxdb_<version> instead.
file_name = "telegraf_#{new_resource.install_version}_amd64.deb"
remote_file "#{Chef::Config[:file_cache_path]}/#{file_name}" do
Expand All @@ -116,7 +115,7 @@
options '--force-confdef --force-confold'
action :install
end
elsif node.platform_family? 'windows'
elsif platform_family? 'windows'

service "telegraf_#{new_resource.name}" do
service_name 'telegraf'
Expand Down Expand Up @@ -169,7 +168,7 @@
action [:stop, :disable]
end

if node.platform_family? 'windows'
if platform_family? 'windows'
if new_resource.install_type == 'package'
chocolatey_package 'telegraf' do
action :remove
Expand Down
18 changes: 8 additions & 10 deletions resources/outputs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

property :name, String, name_property: true
property :outputs, Hash, required: true
property :path, String,
default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
property :path, String, default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
property :service_name, String, default: 'default'
property :reload, kind_of: [TrueClass, FalseClass], default: true
property :rootonly, kind_of: [TrueClass, FalseClass], default: false

default_action :create

action :create do
directory path do
directory new_resource.path do
recursive true
action :create
end
Expand All @@ -49,15 +47,15 @@
action :nothing
end

file "#{path}/#{name}_outputs.conf" do
content TomlRB.dump('outputs' => outputs)
unless node.platform_family? 'windows'
file "#{new_resource.path}/#{new_resource.name}_outputs.conf" do
content TomlRB.dump('outputs' => new_resource.outputs)
unless platform_family? 'windows'
user 'root'
group 'telegraf'
mode new_resource.rootonly ? '0640' : '0644'
end
sensitive new_resource.rootonly
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
end
end

Expand All @@ -69,8 +67,8 @@
action :nothing
end

file "#{path}/#{name}_outputs.conf" do
file "#{new_resource.path}/#{new_resource.name}_outputs.conf" do
action :delete
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
end
end
16 changes: 7 additions & 9 deletions resources/perf_counters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

property :name, String, name_property: true
property :perf_counters, Hash, required: true
property :path, String,
default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
property :path, String, default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
property :service_name, String, default: 'default'
property :reload, kind_of: [TrueClass, FalseClass], default: true

default_action :create

action :create do
directory path do
directory new_resource.path do
recursive true
action :create
end
Expand Down Expand Up @@ -69,23 +67,23 @@
# }

perf_counters_objects = { object: [] }
perf_counters.each do |counter_name, counter_object|
new_resource.perf_counters.each do |counter_name, counter_object|
perf_counter = { 'ObjectName' => counter_name }
perf_counters_objects[:object] << perf_counter.merge(counter_object)
end

win_perf_counters = { win_perf_counters: [] }
win_perf_counters[:win_perf_counters] << perf_counters_objects

file "#{path}/#{name}_perf_counters.conf" do
file "#{new_resource.path}/#{new_resource.name}_perf_counters.conf" do
content TomlRB.dump('inputs' => win_perf_counters)
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
end
end

action :delete do
file "#{path}/#{name}_perf_counters.conf" do
file "#{new_resource.path}/#{new_resource.name}_perf_counters.conf" do
action :delete
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
end
end