Skip to content

Commit a30a0a4

Browse files
Saurausfishnix
authored andcommitted
Fix Chef-13 warning for namespace collision deprecation (#66)
- NOTE: This change does not break backwards compatibility - Cleanup all foodcritic warnings
1 parent 057bfd6 commit a30a0a4

File tree

7 files changed

+41
-45
lines changed

7 files changed

+41
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.9.2
4+
- PR#xx - Fix Chef-13 warning for https://docs.chef.io/deprecations_namespace_collisions.html
5+
- Cleanup all foodcritic warnings
6+
37
## 0.9.1
48

59
- PR#65 - Chef-13 amazon compatibility fix

metadata.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name 'telegraf'
22
maintainer 'E Camden Fisher'
33
maintainer_email '[email protected]'
4-
license 'apache2'
4+
license 'Apache-2.0'
55
description 'Installs/Configures telegraf'
66
long_description 'Installs/Configures telegraf'
7-
version '0.9.1'
7+
version '0.9.2'
88
source_url 'https://github.com/NorthPage/telegraf-cookbook'
99
issues_url 'https://github.com/NorthPage/telegraf-cookbook/issues'
1010

resources/config.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20-
property :name, String, name_property: true
2120
property :config, Hash, default: {}
2221
property :outputs, Hash, default: {}
2322
property :inputs, Hash, default: {}
@@ -43,9 +42,9 @@
4342
action :nothing
4443
end
4544

46-
file path do
45+
file new_resource.path do
4746
content TomlRB.dump(new_resource.config)
48-
unless node.platform_family? 'windows'
47+
unless platform_family? 'windows'
4948
user 'root'
5049
group 'telegraf'
5150
mode '0644'
@@ -55,7 +54,7 @@
5554

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

58-
telegraf_outputs name do
57+
telegraf_outputs new_resource.name do
5958
path telegraf_d
6059
outputs new_resource.outputs
6160
reload false
@@ -64,7 +63,7 @@
6463
notifies :restart, "service[telegraf_#{new_resource.name}]", :delayed
6564
end
6665

67-
telegraf_inputs name do
66+
telegraf_inputs new_resource.name do
6867
path telegraf_d
6968
inputs new_resource.inputs
7069
reload false
@@ -73,7 +72,7 @@
7372
notifies :restart, "service[telegraf_#{new_resource.name}]", :delayed
7473
end
7574

76-
telegraf_perf_counters name do
75+
telegraf_perf_counters new_resource.name do
7776
path telegraf_d
7877
perf_counters new_resource.perf_counters
7978
reload false

resources/inputs.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20-
property :name, String, name_property: true
2120
property :inputs, Hash, required: true
22-
property :path, String,
23-
default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
21+
property :path, String, default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
2422
property :service_name, String, default: 'default'
2523
property :reload, kind_of: [TrueClass, FalseClass], default: true
2624
property :rootonly, kind_of: [TrueClass, FalseClass], default: false
2725

2826
default_action :create
2927

3028
action :create do
31-
directory path do
29+
directory new_resource.path do
3230
recursive true
3331
action :create
3432
end
@@ -51,19 +49,19 @@
5149

5250
file "#{new_resource.path}/#{new_resource.name}_inputs.conf" do
5351
content TomlRB.dump('inputs' => new_resource.inputs)
54-
unless node.platform_family? 'windows'
52+
unless platform_family? 'windows'
5553
user 'root'
5654
group 'telegraf'
5755
mode new_resource.rootonly ? '0640' : '0644'
5856
end
5957
sensitive new_resource.rootonly
60-
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
58+
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
6159
end
6260
end
6361

6462
action :delete do
6563
file "#{new_resource.path}/#{new_resource.name}_inputs.conf" do
6664
action :delete
67-
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
65+
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
6866
end
6967
end

resources/install.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# limitations under the License.
1919

2020
property :include_repository, [TrueClass, FalseClass], default: true
21-
property :name, String, name_property: true
2221
property :install_version, [String, nil], default: nil
2322
property :install_type, String, default: 'package'
2423

@@ -41,7 +40,7 @@
4140
gpgkey "#{node['telegraf']['package_url']}/influxdb.key"
4241
only_if { new_resource.include_repository }
4342
end
44-
elsif node.platform_family? 'debian'
43+
elsif platform_family? 'debian'
4544
package 'apt-transport-https' do
4645
only_if { new_resource.include_repository }
4746
end
@@ -54,9 +53,9 @@
5453
key "#{node['telegraf']['package_url']}/influxdb.key"
5554
only_if { new_resource.include_repository }
5655
end
57-
elsif node.platform_family? 'windows'
56+
elsif platform_family? 'windows'
5857
include_recipe 'chocolatey'
59-
elsif node.platform_family? 'mac_os_x'
58+
elsif platform_family? 'mac_os_x'
6059
include_recipe 'homebrew'
6160

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

77-
if node.platform_family? 'windows'
76+
if platform_family? 'windows'
7877
chocolatey_package 'telegraf' do
79-
version install_version
78+
version new_resource.install_version
8079
source node['telegraf']['chocolatey_source']
8180
action :install
8281
end
8382
else
8483
package 'telegraf' do
85-
version install_version
84+
version new_resource.install_version
8685
action :install
8786
end
8887
end
8988
when 'tarball'
9089
# TODO: implement me
9190
Chef::Log.warn('Sorry, installing from a tarball is not yet implemented.')
9291
when 'file'
93-
if node.platform_family?('rhel', 'amazon')
92+
if platform_family?('rhel', 'amazon')
9493
file_name = "telegraf-#{new_resource.install_version}.x86_64.rpm"
9594
remote_file "#{Chef::Config[:file_cache_path]}/#{file_name}" do
9695
source "#{node['telegraf']['download_urls']['rhel']}/#{file_name}"
@@ -102,7 +101,7 @@
102101
source "#{Chef::Config[:file_cache_path]}/#{file_name}"
103102
action :install
104103
end
105-
elsif node.platform_family? 'debian'
104+
elsif platform_family? 'debian'
106105
# NOTE: file_name would be influxdb_<version> instead.
107106
file_name = "telegraf_#{new_resource.install_version}_amd64.deb"
108107
remote_file "#{Chef::Config[:file_cache_path]}/#{file_name}" do
@@ -116,7 +115,7 @@
116115
options '--force-confdef --force-confold'
117116
action :install
118117
end
119-
elsif node.platform_family? 'windows'
118+
elsif platform_family? 'windows'
120119

121120
service "telegraf_#{new_resource.name}" do
122121
service_name 'telegraf'
@@ -169,7 +168,7 @@
169168
action [:stop, :disable]
170169
end
171170

172-
if node.platform_family? 'windows'
171+
if platform_family? 'windows'
173172
if new_resource.install_type == 'package'
174173
chocolatey_package 'telegraf' do
175174
action :remove

resources/outputs.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20-
property :name, String, name_property: true
2120
property :outputs, Hash, required: true
22-
property :path, String,
23-
default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
21+
property :path, String, default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
2422
property :service_name, String, default: 'default'
2523
property :reload, kind_of: [TrueClass, FalseClass], default: true
2624
property :rootonly, kind_of: [TrueClass, FalseClass], default: false
2725

2826
default_action :create
2927

3028
action :create do
31-
directory path do
29+
directory new_resource.path do
3230
recursive true
3331
action :create
3432
end
@@ -49,15 +47,15 @@
4947
action :nothing
5048
end
5149

52-
file "#{path}/#{name}_outputs.conf" do
53-
content TomlRB.dump('outputs' => outputs)
54-
unless node.platform_family? 'windows'
50+
file "#{new_resource.path}/#{new_resource.name}_outputs.conf" do
51+
content TomlRB.dump('outputs' => new_resource.outputs)
52+
unless platform_family? 'windows'
5553
user 'root'
5654
group 'telegraf'
5755
mode new_resource.rootonly ? '0640' : '0644'
5856
end
5957
sensitive new_resource.rootonly
60-
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
58+
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
6159
end
6260
end
6361

@@ -69,8 +67,8 @@
6967
action :nothing
7068
end
7169

72-
file "#{path}/#{name}_outputs.conf" do
70+
file "#{new_resource.path}/#{new_resource.name}_outputs.conf" do
7371
action :delete
74-
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
72+
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
7573
end
7674
end

resources/perf_counters.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
1919

20-
property :name, String, name_property: true
2120
property :perf_counters, Hash, required: true
22-
property :path, String,
23-
default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
21+
property :path, String, default: ::File.dirname(node['telegraf']['config_file_path']) + '/telegraf.d'
2422
property :service_name, String, default: 'default'
2523
property :reload, kind_of: [TrueClass, FalseClass], default: true
2624

2725
default_action :create
2826

2927
action :create do
30-
directory path do
28+
directory new_resource.path do
3129
recursive true
3230
action :create
3331
end
@@ -69,23 +67,23 @@
6967
# }
7068

7169
perf_counters_objects = { object: [] }
72-
perf_counters.each do |counter_name, counter_object|
70+
new_resource.perf_counters.each do |counter_name, counter_object|
7371
perf_counter = { 'ObjectName' => counter_name }
7472
perf_counters_objects[:object] << perf_counter.merge(counter_object)
7573
end
7674

7775
win_perf_counters = { win_perf_counters: [] }
7876
win_perf_counters[:win_perf_counters] << perf_counters_objects
7977

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

8684
action :delete do
87-
file "#{path}/#{name}_perf_counters.conf" do
85+
file "#{new_resource.path}/#{new_resource.name}_perf_counters.conf" do
8886
action :delete
89-
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if reload
87+
notifies :restart, "service[telegraf_#{new_resource.service_name}]", :delayed if new_resource.reload
9088
end
9189
end

0 commit comments

Comments
 (0)