summaryrefslogtreecommitdiffstats
path: root/lib/puppet/reports
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/reports
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'lib/puppet/reports')
-rw-r--r--lib/puppet/reports/http.rb28
-rw-r--r--lib/puppet/reports/log.rb14
-rw-r--r--lib/puppet/reports/rrdgraph.rb212
-rw-r--r--lib/puppet/reports/store.rb92
-rw-r--r--lib/puppet/reports/tagmail.rb298
5 files changed, 322 insertions, 322 deletions
diff --git a/lib/puppet/reports/http.rb b/lib/puppet/reports/http.rb
index d74782cf8..f1a74195d 100644
--- a/lib/puppet/reports/http.rb
+++ b/lib/puppet/reports/http.rb
@@ -4,19 +4,19 @@ require 'uri'
Puppet::Reports.register_report(:http) do
- desc <<-DESC
- Send report information via HTTP to the ``reporturl``. Each host sends
- its report as a YAML dump and this sends this YAML to a client via HTTP POST.
- The YAML is the `report` parameter of the request."
- DESC
+ desc <<-DESC
+ Send report information via HTTP to the ``reporturl``. Each host sends
+ its report as a YAML dump and this sends this YAML to a client via HTTP POST.
+ The YAML is the `report` parameter of the request."
+ DESC
- def process
- url = URI.parse(Puppet[:reporturl])
- req = Net::HTTP::Post.new(url.path)
- req.body = self.to_yaml
- req.content_type = "application/x-yaml"
- Net::HTTP.new(url.host, url.port).start {|http|
- http.request(req)
- }
- end
+ def process
+ url = URI.parse(Puppet[:reporturl])
+ req = Net::HTTP::Post.new(url.path)
+ req.body = self.to_yaml
+ req.content_type = "application/x-yaml"
+ Net::HTTP.new(url.host, url.port).start {|http|
+ http.request(req)
+ }
+ end
end
diff --git a/lib/puppet/reports/log.rb b/lib/puppet/reports/log.rb
index 827572c2c..1fc6876a6 100644
--- a/lib/puppet/reports/log.rb
+++ b/lib/puppet/reports/log.rb
@@ -1,14 +1,14 @@
require 'puppet/reports'
Puppet::Reports.register_report(:log) do
- desc "Send all received logs to the local log destinations. Usually
- the log destination is syslog."
+ desc "Send all received logs to the local log destinations. Usually
+ the log destination is syslog."
- def process
- self.logs.each do |log|
- log.source = "//#{self.host}/#{log.source}"
- Puppet::Util::Log.newmessage(log)
- end
+ def process
+ self.logs.each do |log|
+ log.source = "//#{self.host}/#{log.source}"
+ Puppet::Util::Log.newmessage(log)
end
+ end
end
diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb
index 2f27f63af..9fbeb60e8 100644
--- a/lib/puppet/reports/rrdgraph.rb
+++ b/lib/puppet/reports/rrdgraph.rb
@@ -1,129 +1,129 @@
Puppet::Reports.register_report(:rrdgraph) do
- desc "Graph all available data about hosts using the RRD library. You
- must have the Ruby RRDtool library installed to use this report, which
- you can get from `the RubyRRDTool RubyForge page`_. This package may also
- be available as ``ruby-rrd`` or ``rrdtool-ruby`` in your distribution's package
- management system. The library and/or package will both require the binary
- ``rrdtool`` package from your distribution to be installed.
-
- .. _the RubyRRDTool RubyForge page: http://rubyforge.org/projects/rubyrrdtool/
-
- This report will create, manage, and graph RRD database files for each
- of the metrics generated during transactions, and it will create a
- few simple html files to display the reporting host's graphs. At this
- point, it will not create a common index file to display links to
- all hosts.
-
- All RRD files and graphs get created in the ``rrddir`` directory. If
- you want to serve these publicly, you should be able to just alias that
- directory in a web server.
-
- If you really know what you're doing, you can tune the ``rrdinterval``,
- which defaults to the ``runinterval``."
-
- def hostdir
- @hostdir ||= File.join(Puppet[:rrddir], self.host)
- end
-
- def htmlfile(type, graphs, field)
- file = File.join(hostdir, "#{type}.html")
- File.open(file, "w") do |of|
- of.puts "<html><head><title>#{type.capitalize} graphs for #{host}</title></head><body>"
-
- graphs.each do |graph|
- if field == :first
- name = graph.sub(/-\w+.png/, '').capitalize
- else
- name = graph.sub(/\w+-/, '').sub(".png", '').capitalize
- end
- of.puts "<img src=#{graph}><br>"
- end
- of.puts "</body></html>"
+ desc "Graph all available data about hosts using the RRD library. You
+ must have the Ruby RRDtool library installed to use this report, which
+ you can get from `the RubyRRDTool RubyForge page`_. This package may also
+ be available as ``ruby-rrd`` or ``rrdtool-ruby`` in your distribution's package
+ management system. The library and/or package will both require the binary
+ ``rrdtool`` package from your distribution to be installed.
+
+ .. _the RubyRRDTool RubyForge page: http://rubyforge.org/projects/rubyrrdtool/
+
+ This report will create, manage, and graph RRD database files for each
+ of the metrics generated during transactions, and it will create a
+ few simple html files to display the reporting host's graphs. At this
+ point, it will not create a common index file to display links to
+ all hosts.
+
+ All RRD files and graphs get created in the ``rrddir`` directory. If
+ you want to serve these publicly, you should be able to just alias that
+ directory in a web server.
+
+ If you really know what you're doing, you can tune the ``rrdinterval``,
+ which defaults to the ``runinterval``."
+
+ def hostdir
+ @hostdir ||= File.join(Puppet[:rrddir], self.host)
+ end
+
+ def htmlfile(type, graphs, field)
+ file = File.join(hostdir, "#{type}.html")
+ File.open(file, "w") do |of|
+ of.puts "<html><head><title>#{type.capitalize} graphs for #{host}</title></head><body>"
+
+ graphs.each do |graph|
+ if field == :first
+ name = graph.sub(/-\w+.png/, '').capitalize
+ else
+ name = graph.sub(/\w+-/, '').sub(".png", '').capitalize
end
-
- file
+ of.puts "<img src=#{graph}><br>"
+ end
+ of.puts "</body></html>"
end
- def mkhtml
- images = Dir.entries(hostdir).find_all { |d| d =~ /\.png/ }
+ file
+ end
- periodorder = %w{daily weekly monthly yearly}
+ def mkhtml
+ images = Dir.entries(hostdir).find_all { |d| d =~ /\.png/ }
- periods = {}
- types = {}
- images.each do |n|
- type, period = n.sub(".png", '').split("-")
- periods[period] ||= []
- types[type] ||= []
- periods[period] << n
- types[type] << n
- end
+ periodorder = %w{daily weekly monthly yearly}
- files = []
- # Make the period html files
- periodorder.each do |period|
- unless ary = periods[period]
- raise Puppet::Error, "Could not find graphs for #{period}"
- end
- files << htmlfile(period, ary, :first)
- end
+ periods = {}
+ types = {}
+ images.each do |n|
+ type, period = n.sub(".png", '').split("-")
+ periods[period] ||= []
+ types[type] ||= []
+ periods[period] << n
+ types[type] << n
+ end
- # make the type html files
- types.sort { |a,b| a[0] <=> b[0] }.each do |type, ary|
- newary = []
- periodorder.each do |period|
- if graph = ary.find { |g| g.include?("-#{period}.png") }
- newary << graph
- else
- raise "Could not find #{type}-#{period} graph"
- end
- end
-
- files << htmlfile(type, newary, :second)
- end
+ files = []
+ # Make the period html files
+ periodorder.each do |period|
+ unless ary = periods[period]
+ raise Puppet::Error, "Could not find graphs for #{period}"
+ end
+ files << htmlfile(period, ary, :first)
+ end
- File.open(File.join(hostdir, "index.html"), "w") do |of|
- of.puts "<html><head><title>Report graphs for #{host}</title></head><body>"
- files.each do |file|
- of.puts "<a href='#{File.basename(file)}'>#{File.basename(file).sub(".html",'').capitalize}</a><br/>"
- end
- of.puts "</body></html>"
+ # make the type html files
+ types.sort { |a,b| a[0] <=> b[0] }.each do |type, ary|
+ newary = []
+ periodorder.each do |period|
+ if graph = ary.find { |g| g.include?("-#{period}.png") }
+ newary << graph
+ else
+ raise "Could not find #{type}-#{period} graph"
end
+ end
+
+ files << htmlfile(type, newary, :second)
end
- def process(time = nil)
- time ||= Time.now.to_i
+ File.open(File.join(hostdir, "index.html"), "w") do |of|
+ of.puts "<html><head><title>Report graphs for #{host}</title></head><body>"
+ files.each do |file|
+ of.puts "<a href='#{File.basename(file)}'>#{File.basename(file).sub(".html",'').capitalize}</a><br/>"
+ end
+ of.puts "</body></html>"
+ end
+ end
- unless File.directory?(hostdir) and FileTest.writable?(hostdir)
- # Some hackishness to create the dir with all of the right modes and ownership
- config = Puppet::Util::Settings.new
- config.setdefaults(:reports, :hostdir => {:default => hostdir, :owner => 'service', :mode => 0755, :group => 'service', :desc => "eh"})
+ def process(time = nil)
+ time ||= Time.now.to_i
- # This creates the dir.
- config.use(:reports)
- end
+ unless File.directory?(hostdir) and FileTest.writable?(hostdir)
+ # Some hackishness to create the dir with all of the right modes and ownership
+ config = Puppet::Util::Settings.new
+ config.setdefaults(:reports, :hostdir => {:default => hostdir, :owner => 'service', :mode => 0755, :group => 'service', :desc => "eh"})
- self.metrics.each do |name, metric|
- metric.basedir = hostdir
+ # This creates the dir.
+ config.use(:reports)
+ end
- if name == "time"
- timeclean(metric)
- end
+ self.metrics.each do |name, metric|
+ metric.basedir = hostdir
- metric.store(time)
+ if name == "time"
+ timeclean(metric)
+ end
- metric.graph
- end
+ metric.store(time)
- mkhtml unless FileTest.exists?(File.join(hostdir, "index.html"))
+ metric.graph
end
- # Unfortunately, RRD does not deal well with changing lists of values,
- # so we have to pick a list of values and stick with it. In this case,
- # that means we record the total time, the config time, and that's about
- # it. We should probably send each type's time as a separate metric.
- def timeclean(metric)
- metric.values = metric.values.find_all { |name, label, value| [:total, :config_retrieval].include?(name) }
- end
+ mkhtml unless FileTest.exists?(File.join(hostdir, "index.html"))
+ end
+
+ # Unfortunately, RRD does not deal well with changing lists of values,
+ # so we have to pick a list of values and stick with it. In this case,
+ # that means we record the total time, the config time, and that's about
+ # it. We should probably send each type's time as a separate metric.
+ def timeclean(metric)
+ metric.values = metric.values.find_all { |name, label, value| [:total, :config_retrieval].include?(name) }
+ end
end
diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb
index 384f0eb0a..65159fc07 100644
--- a/lib/puppet/reports/store.rb
+++ b/lib/puppet/reports/store.rb
@@ -1,60 +1,60 @@
require 'puppet'
Puppet::Reports.register_report(:store) do
- desc "Store the yaml report on disk. Each host sends its report as a YAML dump
- and this just stores the file on disk, in the ``reportdir`` directory.
-
- These files collect quickly -- one every half hour -- so it is a good idea
- to perform some maintenance on them if you use this report (it's the only
- default report)."
-
- def mkclientdir(client, dir)
- config = Puppet::Util::Settings.new
-
- config.setdefaults(
- "reportclient-#{client}".to_sym,
- "client-#{client}-dir" => { :default => dir,
- :mode => 0750,
- :desc => "Client dir for #{client}",
- :owner => 'service',
- :group => 'service'
- },
+ desc "Store the yaml report on disk. Each host sends its report as a YAML dump
+ and this just stores the file on disk, in the ``reportdir`` directory.
+
+ These files collect quickly -- one every half hour -- so it is a good idea
+ to perform some maintenance on them if you use this report (it's the only
+ default report)."
+
+ def mkclientdir(client, dir)
+ config = Puppet::Util::Settings.new
+
+ config.setdefaults(
+ "reportclient-#{client}".to_sym,
+ "client-#{client}-dir" => { :default => dir,
+ :mode => 0750,
+ :desc => "Client dir for #{client}",
+ :owner => 'service',
+ :group => 'service'
+ },
- :noop => [false, "Used by settings internally."]
- )
+ :noop => [false, "Used by settings internally."]
+ )
- config.use("reportclient-#{client}".to_sym)
- end
-
- def process
- # We don't want any tracking back in the fs. Unlikely, but there
- # you go.
- client = self.host.gsub("..",".")
+ config.use("reportclient-#{client}".to_sym)
+ end
- dir = File.join(Puppet[:reportdir], client)
+ def process
+ # We don't want any tracking back in the fs. Unlikely, but there
+ # you go.
+ client = self.host.gsub("..",".")
- mkclientdir(client, dir) unless FileTest.exists?(dir)
+ dir = File.join(Puppet[:reportdir], client)
- # Now store the report.
- now = Time.now.gmtime
- name = %w{year month day hour min}.collect do |method|
- # Make sure we're at least two digits everywhere
- "%02d" % now.send(method).to_s
- end.join("") + ".yaml"
+ mkclientdir(client, dir) unless FileTest.exists?(dir)
- file = File.join(dir, name)
+ # Now store the report.
+ now = Time.now.gmtime
+ name = %w{year month day hour min}.collect do |method|
+ # Make sure we're at least two digits everywhere
+ "%02d" % now.send(method).to_s
+ end.join("") + ".yaml"
- begin
- File.open(file, "w", 0640) do |f|
- f.print to_yaml
- end
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.warning "Could not write report for #{client} at #{file}: #{detail}"
- end
+ file = File.join(dir, name)
- # Only testing cares about the return value
- file
+ begin
+ File.open(file, "w", 0640) do |f|
+ f.print to_yaml
+ end
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.warning "Could not write report for #{client} at #{file}: #{detail}"
end
+
+ # Only testing cares about the return value
+ file
+ end
end
diff --git a/lib/puppet/reports/tagmail.rb b/lib/puppet/reports/tagmail.rb
index f77d3c9fb..652104096 100644
--- a/lib/puppet/reports/tagmail.rb
+++ b/lib/puppet/reports/tagmail.rb
@@ -5,165 +5,165 @@ require 'net/smtp'
require 'time'
Puppet::Reports.register_report(:tagmail) do
- desc "This report sends specific log messages to specific email addresses
- based on the tags in the log messages. See the
- `UsingTags tag documentation`:trac: for more information
- on tags.
-
- To use this report, you must create a ``tagmail.conf`` (in the location
- specified by ``tagmap``). This is a simple file that maps tags to
- email addresses: Any log messages in the report that match the specified
- tags will be sent to the specified email addresses.
-
- Tags must be comma-separated, and they can be negated so that messages
- only match when they do not have that tag. The tags are separated from
- the email addresses by a colon, and the email addresses should also
- be comma-separated.
-
- Lastly, there is an ``all`` tag that will always match all log messages.
-
- Here is an example tagmail.conf::
-
- all: me@domain.com
- webserver, !mailserver: httpadmins@domain.com
-
- This will send all messages to ``me@domain.com``, and all messages from
- webservers that are not also from mailservers to ``httpadmins@domain.com``.
-
- If you are using anti-spam controls, such as grey-listing, on your mail
- server you should whitelist the sending email (controlled by ``reportform`` configuration option) to ensure your email is not discarded as spam.
- "
-
-
- # Find all matching messages.
- def match(taglists)
- matching_logs = []
- taglists.each do |emails, pos, neg|
- # First find all of the messages matched by our positive tags
- messages = nil
- if pos.include?("all")
- messages = self.logs
- else
- # Find all of the messages that are tagged with any of our
- # tags.
- messages = self.logs.find_all do |log|
- pos.detect { |tag| log.tagged?(tag) }
- end
- end
-
- # Now go through and remove any messages that match our negative tags
- messages = messages.reject do |log|
- true if neg.detect do |tag| log.tagged?(tag) end
- end
-
- if messages.empty?
- Puppet.info "No messages to report to #{emails.join(",")}"
- next
- else
- matching_logs << [emails, messages.collect { |m| m.to_report }.join("\n")]
- end
+ desc "This report sends specific log messages to specific email addresses
+ based on the tags in the log messages. See the
+ `UsingTags tag documentation`:trac: for more information
+ on tags.
+
+ To use this report, you must create a ``tagmail.conf`` (in the location
+ specified by ``tagmap``). This is a simple file that maps tags to
+ email addresses: Any log messages in the report that match the specified
+ tags will be sent to the specified email addresses.
+
+ Tags must be comma-separated, and they can be negated so that messages
+ only match when they do not have that tag. The tags are separated from
+ the email addresses by a colon, and the email addresses should also
+ be comma-separated.
+
+ Lastly, there is an ``all`` tag that will always match all log messages.
+
+ Here is an example tagmail.conf::
+
+ all: me@domain.com
+ webserver, !mailserver: httpadmins@domain.com
+
+ This will send all messages to ``me@domain.com``, and all messages from
+ webservers that are not also from mailservers to ``httpadmins@domain.com``.
+
+ If you are using anti-spam controls, such as grey-listing, on your mail
+ server you should whitelist the sending email (controlled by ``reportform`` configuration option) to ensure your email is not discarded as spam.
+ "
+
+
+ # Find all matching messages.
+ def match(taglists)
+ matching_logs = []
+ taglists.each do |emails, pos, neg|
+ # First find all of the messages matched by our positive tags
+ messages = nil
+ if pos.include?("all")
+ messages = self.logs
+ else
+ # Find all of the messages that are tagged with any of our
+ # tags.
+ messages = self.logs.find_all do |log|
+ pos.detect { |tag| log.tagged?(tag) }
end
-
- matching_logs
+ end
+
+ # Now go through and remove any messages that match our negative tags
+ messages = messages.reject do |log|
+ true if neg.detect do |tag| log.tagged?(tag) end
+ end
+
+ if messages.empty?
+ Puppet.info "No messages to report to #{emails.join(",")}"
+ next
+ else
+ matching_logs << [emails, messages.collect { |m| m.to_report }.join("\n")]
+ end
end
- # Load the config file
- def parse(text)
- taglists = []
- text.split("\n").each do |line|
- taglist = emails = nil
- case line.chomp
- when /^\s*#/; next
- when /^\s*$/; next
- when /^\s*(.+)\s*:\s*(.+)\s*$/
- taglist = $1
- emails = $2.sub(/#.*$/,'')
- else
- raise ArgumentError, "Invalid tagmail config file"
- end
-
- pos = []
- neg = []
- taglist.sub(/\s+$/,'').split(/\s*,\s*/).each do |tag|
- unless tag =~ /^!?[-\w]+$/
- raise ArgumentError, "Invalid tag #{tag.inspect}"
- end
- case tag
- when /^\w+/; pos << tag
- when /^!\w+/; neg << tag.sub("!", '')
- else
- raise Puppet::Error, "Invalid tag '#{tag}'"
- end
- end
-
- # Now split the emails
- emails = emails.sub(/\s+$/,'').split(/\s*,\s*/)
- taglists << [emails, pos, neg]
+ matching_logs
+ end
+
+ # Load the config file
+ def parse(text)
+ taglists = []
+ text.split("\n").each do |line|
+ taglist = emails = nil
+ case line.chomp
+ when /^\s*#/; next
+ when /^\s*$/; next
+ when /^\s*(.+)\s*:\s*(.+)\s*$/
+ taglist = $1
+ emails = $2.sub(/#.*$/,'')
+ else
+ raise ArgumentError, "Invalid tagmail config file"
+ end
+
+ pos = []
+ neg = []
+ taglist.sub(/\s+$/,'').split(/\s*,\s*/).each do |tag|
+ unless tag =~ /^!?[-\w]+$/
+ raise ArgumentError, "Invalid tag #{tag.inspect}"
end
- taglists
- end
-
- # Process the report. This just calls the other associated messages.
- def process
- unless FileTest.exists?(Puppet[:tagmap])
- Puppet.notice "Cannot send tagmail report; no tagmap file #{Puppet[:tagmap]}"
- return
+ case tag
+ when /^\w+/; pos << tag
+ when /^!\w+/; neg << tag.sub("!", '')
+ else
+ raise Puppet::Error, "Invalid tag '#{tag}'"
end
+ end
- taglists = parse(File.read(Puppet[:tagmap]))
-
- # Now find any appropriately tagged messages.
- reports = match(taglists)
-
- send(reports)
+ # Now split the emails
+ emails = emails.sub(/\s+$/,'').split(/\s*,\s*/)
+ taglists << [emails, pos, neg]
+ end
+ taglists
+ end
+
+ # Process the report. This just calls the other associated messages.
+ def process
+ unless FileTest.exists?(Puppet[:tagmap])
+ Puppet.notice "Cannot send tagmail report; no tagmap file #{Puppet[:tagmap]}"
+ return
end
- # Send the email reports.
- def send(reports)
- pid = fork do
- if Puppet[:smtpserver] != "none"
- begin
- Net::SMTP.start(Puppet[:smtpserver]) do |smtp|
- reports.each do |emails, messages|
- smtp.open_message_stream(Puppet[:reportfrom], *emails) do |p|
- p.puts "From: #{Puppet[:reportfrom]}"
- p.puts "Subject: Puppet Report for #{self.host}"
- p.puts "To: " + emails.join(", ")
- p.puts "Date: #{Time.now.rfc2822}"
- p.puts
- p.puts messages
- end
- end
- end
- rescue => detail
- puts detail.backtrace if Puppet[:debug]
- raise Puppet::Error,
- "Could not send report emails through smtp: #{detail}"
- end
- elsif Puppet[:sendmail] != ""
- begin
- reports.each do |emails, messages|
- # We need to open a separate process for every set of email addresses
- IO.popen(Puppet[:sendmail] + " " + emails.join(" "), "w") do |p|
- p.puts "From: #{Puppet[:reportfrom]}"
- p.puts "Subject: Puppet Report for #{self.host}"
- p.puts "To: " + emails.join(", ")
-
- p.puts messages
- end
- end
- rescue => detail
- puts detail.backtrace if Puppet[:debug]
- raise Puppet::Error,
- "Could not send report emails via sendmail: #{detail}"
- end
- else
- raise Puppet::Error, "SMTP server is unset and could not find sendmail"
+ taglists = parse(File.read(Puppet[:tagmap]))
+
+ # Now find any appropriately tagged messages.
+ reports = match(taglists)
+
+ send(reports)
+ end
+
+ # Send the email reports.
+ def send(reports)
+ pid = fork do
+ if Puppet[:smtpserver] != "none"
+ begin
+ Net::SMTP.start(Puppet[:smtpserver]) do |smtp|
+ reports.each do |emails, messages|
+ smtp.open_message_stream(Puppet[:reportfrom], *emails) do |p|
+ p.puts "From: #{Puppet[:reportfrom]}"
+ p.puts "Subject: Puppet Report for #{self.host}"
+ p.puts "To: " + emails.join(", ")
+ p.puts "Date: #{Time.now.rfc2822}"
+ p.puts
+ p.puts messages
+ end
end
+ end
+ rescue => detail
+ puts detail.backtrace if Puppet[:debug]
+ raise Puppet::Error,
+ "Could not send report emails through smtp: #{detail}"
end
-
- # Don't bother waiting for the pid to return.
- Process.detach(pid)
+ elsif Puppet[:sendmail] != ""
+ begin
+ reports.each do |emails, messages|
+ # We need to open a separate process for every set of email addresses
+ IO.popen(Puppet[:sendmail] + " " + emails.join(" "), "w") do |p|
+ p.puts "From: #{Puppet[:reportfrom]}"
+ p.puts "Subject: Puppet Report for #{self.host}"
+ p.puts "To: " + emails.join(", ")
+
+ p.puts messages
+ end
+ end
+ rescue => detail
+ puts detail.backtrace if Puppet[:debug]
+ raise Puppet::Error,
+ "Could not send report emails via sendmail: #{detail}"
+ end
+ else
+ raise Puppet::Error, "SMTP server is unset and could not find sendmail"
+ end
end
+
+ # Don't bother waiting for the pid to return.
+ Process.detach(pid)
+ end
end