diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..07017ac --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,7 @@ +inherit_from: .rubocop_todo.yml + +HashSyntax: + EnforcedStyle: hash_rockets + +LineLength: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..7eaea59 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,16 @@ +# This configuration was generated by `rubocop --auto-gen-config` +# on 2014-07-24 07:25:56 -0700 using RuboCop version 0.24.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: CountComments. +Style/MethodLength: + Max: 16 + +# Offense count: 2 +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/Next: + Enabled: false diff --git a/attributes/default.rb b/attributes/default.rb index 0c81e17..fc4d0c5 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -17,12 +17,12 @@ # limitations under the License. # -default[:collectd][:base_dir] = "/var/lib/collectd" -default[:collectd][:plugin_dir] = "/usr/lib/collectd" -default[:collectd][:types_db] = ["/usr/share/collectd/types.db"] +default[:collectd][:base_dir] = '/var/lib/collectd' +default[:collectd][:plugin_dir] = '/usr/lib/collectd' +default[:collectd][:types_db] = ['/usr/share/collectd/types.db'] default[:collectd][:interval] = 10 default[:collectd][:read_threads] = 5 -default[:collectd][:pkg_name] = "collectd-core" +default[:collectd][:pkg_name] = 'collectd-core' -default[:collectd][:collectd_web][:path] = "/srv/collectd_web" -default[:collectd][:collectd_web][:hostname] = "collectd" +default[:collectd][:collectd_web][:path] = '/srv/collectd_web' +default[:collectd][:collectd_web][:hostname] = 'collectd' diff --git a/definitions/collectd_plugin.rb b/definitions/collectd_plugin.rb index 75c665f..22571e1 100644 --- a/definitions/collectd_plugin.rb +++ b/definitions/collectd_plugin.rb @@ -7,9 +7,9 @@ # 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, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,34 +19,32 @@ define :collectd_plugin, :options => {}, :template => nil, :cookbook => nil do template "/etc/collectd/plugins/#{params[:name]}.conf" do - owner "root" - group "root" - mode "644" + owner 'root' + group 'root' + mode '644' if params[:template].nil? - source "plugin.conf.erb" - cookbook params[:cookbook] || "collectd" + source 'plugin.conf.erb' + cookbook params[:cookbook] || 'collectd' else source params[:template] cookbook params[:cookbook] end - variables :name=>params[:name], :options=>params[:options] - notifies :restart, resources(:service => "collectd") + variables :name => params[:name], :options => params[:options] + notifies :restart, 'service[collectd]' end end define :collectd_python_plugin, :options => {}, :module => nil, :path => nil do begin - t = resources(:template => "/etc/collectd/plugins/python.conf") - rescue ArgumentError,Chef::Exceptions::ResourceNotFound - collectd_plugin "python" do - options :paths=>[node[:collectd][:plugin_dir]], :modules=>{} - template "python_plugin.conf.erb" - cookbook "collectd" + t = resources(:template => '/etc/collectd/plugins/python.conf') + rescue ArgumentError, Chef::Exceptions::ResourceNotFound + collectd_plugin 'python' do + options :paths => [node[:collectd][:plugin_dir]], :modules => {} + template 'python_plugin.conf.erb' + cookbook 'collectd' end retry end - if not params[:path].nil? - t.variables[:options][:paths] << params[:path] - end + t.variables[:options][:paths] << params[:path] unless params[:path].nil? t.variables[:options][:modules][params[:module] || params[:name]] = params[:options] end diff --git a/libraries/default.rb b/libraries/default.rb index 1f3e92b..fb5d0d9 100644 --- a/libraries/default.rb +++ b/libraries/default.rb @@ -7,9 +7,9 @@ # 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, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,8 +18,8 @@ # def collectd_key(option) - return option.to_s.split('_').map{|x| x.capitalize}.join() if option.instance_of?(Symbol) - "#{option}" + return option.to_s.split('_').map { |x| x.capitalize }.join if option.instance_of?(Symbol) + option end def collectd_option(option) @@ -27,7 +27,7 @@ def collectd_option(option) "\"#{option}\"" end -def collectd_settings(options, level=0) +def collectd_settings(options, level = 0) indent = ' ' * level output = [] options.each_pair do |key, value| @@ -37,7 +37,7 @@ def collectd_settings(options, level=0) end elsif value.is_a? Hash value.each_pair do |name, suboptions| - output << "#{indent}<#{key} \"#{name}\">\n#{collectd_settings(suboptions, level+1)}\n#{indent}" + output << "#{indent}<#{key} \"#{name}\">\n#{collectd_settings(suboptions, level + 1)}\n#{indent}" end else output << "#{indent}#{collectd_key(key)} #{collectd_option(value)}" diff --git a/metadata.rb b/metadata.rb index 3a0d763..d1fde31 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,8 +1,10 @@ -name "collectd" -maintainer "Noan Kantrowitz" -maintainer_email "noah@coderanger.net" -license "Apache 2.0" -description "Install and configure the collectd monitoring daemon" +name 'collectd' +maintainer 'Noan Kantrowitz' +maintainer_email 'noah@coderanger.net' +license 'Apache 2.0' +description 'Install and configure the collectd monitoring daemon' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "1.0.0" -supports "ubuntu" +version '1.1.0' +supports 'ubuntu' + +suggests 'apache' diff --git a/recipes/client.rb b/recipes/client.rb index 2e149a0..f2ff3cb 100644 --- a/recipes/client.rb +++ b/recipes/client.rb @@ -7,9 +7,9 @@ # 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, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,7 @@ # limitations under the License. # -include_recipe "collectd" +include_recipe 'collectd' servers = [] if Chef::Config[:solo] @@ -25,12 +25,13 @@ else search(:node, 'recipes:"collectd::server"') do |n| servers << n['fqdn'] + end end if servers.empty? - raise "No servers found. Please configure at least one node with collectd::server." + fail 'No servers found. Please configure at least one node with collectd::server.' end -collectd_plugin "network" do - options :server=>servers +collectd_plugin 'network' do + options :server => servers end diff --git a/recipes/collectd_web.rb b/recipes/collectd_web.rb index f0fd1a0..d3a3503 100644 --- a/recipes/collectd_web.rb +++ b/recipes/collectd_web.rb @@ -7,9 +7,9 @@ # 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, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,24 +17,24 @@ # limitations under the License. # -include_recipe "collectd" -include_recipe "apache2" +include_recipe 'collectd' +include_recipe 'apache2' %w(libhtml-parser-perl liburi-perl librrds-perl libjson-perl).each do |name| package name end directory node[:collectd][:collectd_web][:path] do - owner "root" - group "root" - mode "755" + owner 'root' + group 'root' + mode '755' end -bash "install_collectd_web" do - user "root" +bash 'install_collectd_web' do + user 'root' cwd node[:collectd][:collectd_web][:path] not_if do - File.exists?(File.join(node[:collectd][:collectd_web][:path], "index.html")) + File.exist?(File.join(node[:collectd][:collectd_web][:path], 'index.html')) end code <<-EOH wget --no-check-certificate -O collectd-web.tar.gz https://github.com/httpdss/collectd-web/tarball/master @@ -43,11 +43,11 @@ EOH end -template "/etc/apache2/sites-available/collectd_web.conf" do - source "collectd_web.conf.erb" - owner "root" - group "root" - mode "644" +template '/etc/apache2/sites-available/collectd_web.conf' do + source 'collectd_web.conf.erb' + owner 'root' + group 'root' + mode '644' end -apache_site "collectd_web.conf" +apache_site 'collectd_web.conf' diff --git a/recipes/default.rb b/recipes/default.rb index a34d2a8..bb3a960 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -17,56 +17,38 @@ # limitations under the License. # -package "collectd" do +package 'collectd' do package_name node[:collectd][:pkg_name] end -service "collectd" do +service 'collectd' do supports :restart => true, :status => true end -directory "/etc/collectd" do - owner "root" - group "root" - mode "755" -end - -directory "/etc/collectd/plugins" do - owner "root" - group "root" - mode "755" -end - -directory node[:collectd][:base_dir] do - owner "root" - group "root" - mode "755" - recursive true -end - -directory node[:collectd][:plugin_dir] do - owner "root" - group "root" - mode "755" - recursive true +%W(/etc/collectd /etc/collectd/plugins #{node[:collectd][:base_dir]} #{node[:collectd][:plugin_dir]}).each do |dir| + directory dir do + owner 'root' + group 'root' + mode '755' + end end %w(collectd collection thresholds).each do |file| template "/etc/collectd/#{file}.conf" do source "#{file}.conf.erb" - owner "root" - group "root" - mode "644" - notifies :restart, resources(:service => "collectd") + owner 'root' + group 'root' + mode '644' + notifies :restart, 'service[collectd]' end end -ruby_block "delete_old_plugins" do +ruby_block 'delete_old_plugins' do block do Dir['/etc/collectd/plugins/*.conf'].each do |path| autogen = false File.open(path).each_line do |line| - if line.start_with?('#') and line.include?('autogenerated') + if line.start_with?('#') && line.include?('autogenerated') autogen = true break end @@ -84,6 +66,6 @@ end end -service "collectd" do +service 'collectd' do action [:enable, :start] end diff --git a/recipes/server.rb b/recipes/server.rb index 08b6320..2175b3b 100644 --- a/recipes/server.rb +++ b/recipes/server.rb @@ -7,9 +7,9 @@ # 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, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,8 +17,8 @@ # limitations under the License. # -include_recipe "collectd" +include_recipe 'collectd' -collectd_plugin "network" do - options :listen=>'0.0.0.0' +collectd_plugin 'network' do + options :listen => '0.0.0.0' end