Skip to content
This repository was archived by the owner on Dec 31, 2021. It is now read-only.

Foodcritic fixes #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
inherit_from: .rubocop_todo.yml

HashSyntax:
EnforcedStyle: hash_rockets

LineLength:
Enabled: false
16 changes: 16 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 6 additions & 6 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
34 changes: 16 additions & 18 deletions definitions/collectd_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
12 changes: 6 additions & 6 deletions libraries/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,16 +18,16 @@
#

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)
return option if option.instance_of?(Fixnum) || option == true || option == false
"\"#{option}\""
end

def collectd_settings(options, level=0)
def collectd_settings(options, level = 0)
indent = ' ' * level
output = []
options.each_pair do |key, value|
Expand All @@ -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}</#{key}>"
output << "#{indent}<#{key} \"#{name}\">\n#{collectd_settings(suboptions, level + 1)}\n#{indent}</#{key}>"
end
else
output << "#{indent}#{collectd_key(key)} #{collectd_option(value)}"
Expand Down
16 changes: 9 additions & 7 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name "collectd"
maintainer "Noan Kantrowitz"
maintainer_email "[email protected]"
license "Apache 2.0"
description "Install and configure the collectd monitoring daemon"
name 'collectd'
maintainer 'Noan Kantrowitz'
maintainer_email '[email protected]'
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'
20 changes: 12 additions & 8 deletions recipes/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@
# 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.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "collectd"
include_recipe 'collectd'

servers = []
search(:node, 'recipes:collectd\\:\\:server') do |n|
servers << n['fqdn']
if Chef::Config[:solo]
servers << node['collectd']['master']['ip']
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
32 changes: 16 additions & 16 deletions recipes/collectd_web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@
# 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.
# See the License for the specific language governing permissions and
# 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
Expand All @@ -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'
48 changes: 15 additions & 33 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -84,6 +66,6 @@
end
end

service "collectd" do
service 'collectd' do
action [:enable, :start]
end
10 changes: 5 additions & 5 deletions recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
# 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.
# See the License for the specific language governing permissions and
# 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