Permalink
Browse files

FC001 Cleanup

This commit updates cookbook with Foodcritic Rule FC001:
Use strings in preference to symbols to access node attributes.
This commit also cleans up some unnecessary whitespace.
  • Loading branch information...
Paul Welch
Paul Welch committed Sep 26, 2012
1 parent 263ec59 commit de88a248002b877235dbe526e9ed8b8f59241e38
Showing with 28 additions and 37 deletions.
  1. +11 −18 attributes/papertrail.rb
  2. +17 −19 recipes/default.rb
View
@@ -1,53 +1,46 @@
# Logger to use. Support loggers include: rsyslog.
-#
-default[:papertrail][:logger] = "rsyslog"
+default['papertrail']['logger'] = "rsyslog"
# Papertrail host to send stats to.
-#
-default[:papertrail][:remote_host] = "logs.papertrailapp.com"
+default['papertrail']['remote_host'] = "logs.papertrailapp.com"
# Port to use. MUST be set
# XXX: should pull from a databag since this is private
-#
-default[:papertrail][:remote_port] = nil
+default['papertrail']['remote_port'] = nil
# Where to store papertrail cert file.
-#
-default[:papertrail][:cert_file] = "/etc/papertrail.crt"
+default['papertrail']['cert_file'] = "/etc/papertrail.crt"
# URL to download certificate from.
-#
-default[:papertrail][:cert_url] = "https://papertrailapp.com/tools/syslog.papertrail.crt"
+default['papertrail']['cert_url'] = "https://papertrailapp.com/tools/syslog.papertrail.crt"
# By default, this recipe will log to Papertrail using the system's
# hostname. If you want to set the hostname that will be used (think
# ephemeral cloud nodes) you can set one of the following. If either is
# set it will use the hostname_name first and the hostname_cmd second.
# Set the logging hostname to this string.
-#
-default[:papertrail][:hostname_name] = ""
+default['papertrail']['hostname_name'] = ""
# Set the logging hostname to the output of this command passed to
# system(). This is useful if the desired hostname comes from a
# dynamic source like EC2 meta-data.
-#
-default[:papertrail][:hostname_cmd] = ""
+default['papertrail']['hostname_cmd'] = ""
# File monitoring is not really a part of papertrail but is included here:
#
-# default[:papertrail][:watch_files] - This is a list of files that will be
+# default['papertrail']['watch_files'] - This is a list of files that will be
# configured to be watched and included in the papertrail logging. This
# is useful for including output from applications that aren't
# configured to use syslog. Each entry in this list is a hash of:
#
-# [:filename] - Full path to the file.
-# [:tag] - What to tag log lines that come from this file. Best to
+# ['filename'] - Full path to the file.
+# ['tag'] - What to tag log lines that come from this file. Best to
# use a short application name.
#
# For example:
#
-# node[:papertrail][:watch_files] =
+# node['papertrail']['watch_files'] =
# [{:filename => "/var/log/myapp.log", :tag => "myapp:"}]
#
View
@@ -17,7 +17,7 @@
# limitations under the License.
##
-return unless node[:papertrail][:logger] == "rsyslog"
+return unless node['papertrail']['logger'] == "rsyslog"
syslogger = "rsyslog"
@@ -30,22 +30,21 @@
not_if {File.exists?("/usr/lib/rsyslog/lmnsd_gtls.so")}
end
-remote_file node[:papertrail][:cert_file] do
- source node[:papertrail][:cert_url]
+remote_file node['papertrail']['cert_file'] do
+ source node['papertrail']['cert_url']
mode "0444"
end
syslogdir = "/etc/rsyslog.d"
-if node[:papertrail][:watch_files] && node[:papertrail][:watch_files].length > 0
-
+if node['papertrail']['watch_files'] && node['papertrail']['watch_files'].length > 0
watch_file_array = []
- if node[:papertrail][:watch_files].respond_to?(:keys)
+ if node['papertrail']['watch_files'].respond_to?(:keys)
require 'digest/sha1'
- node[:papertrail][:watch_files].each do |filename, tag|
+ node['papertrail']['watch_files'].each do |filename, tag|
watch_file_array << {
:filename => filename,
:tag => tag,
@@ -54,16 +53,15 @@
end
# Sort to preserve order of the config
- watch_file_array = watch_file_array.sort { |a,b| a[:filename] <=> b[:filename] }
+ watch_file_array = watch_file_array.sort { |a,b| a['filename'] <=> b['filename'] }
- elsif node[:papertrail][:watch_files].is_a?(Array)
+ elsif node['papertrail']['watch_files'].is_a?(Array)
# Deprecate but retain backwards compatibility
- Chef::Log.info "DEPRECATION WARNING: Please convert this node's [:papertrail][:watch_files] attribute from an Array to a Hash"
+ Chef::Log.info "DEPRECATION WARNING: Please convert this node's ['papertrail']['watch_files'] attribute from an Array to a Hash"
Chef::Log.info " to allow use of override_attribtutes for addition of watch_files"
- watch_file_array = node[:papertrail][:watch_files]
-
+ watch_file_array = node['papertrail']['watch_files']
end
template "#{syslogdir}/60-watch-files.conf" do
@@ -76,11 +74,11 @@
end
end
-hostname_name = node[:papertrail][:hostname_name].to_s
-hostname_cmd = node[:papertrail][:hostname_cmd].to_s
+hostname_name = node['papertrail']['hostname_name'].to_s
+hostname_cmd = node['papertrail']['hostname_cmd'].to_s
unless hostname_name.empty? && hostname_cmd.empty?
- node[:papertrail][:fixhostname] = true
+ node['papertrail']['fixhostname'] = true
if !hostname_name.empty?
name = hostname_name
@@ -103,10 +101,10 @@
owner "root"
group "root"
mode "0644"
- variables({ :cert_file => node[:papertrail][:cert_file],
- :host => node[:papertrail][:remote_host],
- :port => node[:papertrail][:remote_port],
- :fixhostname => node[:papertrail][:fixhostname]
+ variables({ :cert_file => node['papertrail']['cert_file'],
+ :host => node['papertrail']['remote_host'],
+ :port => node['papertrail']['remote_port'],
+ :fixhostname => node['papertrail']['fixhostname']
})
notifies :restart, resources(:service => syslogger)
end

0 comments on commit de88a24

Please sign in to comment.