| 123 |
123 |
|
| 124 |
124 |
# Send the email reports.
|
| 125 |
125 |
def send(reports)
|
| 126 |
|
pid = fork do
|
| 127 |
|
if Puppet[:smtpserver] != "none"
|
| 128 |
|
begin
|
| 129 |
|
Net::SMTP.start(Puppet[:smtpserver]) do |smtp|
|
| 130 |
|
reports.each do |emails, messages|
|
| 131 |
|
Puppet.info "Sending report to %s" % emails.join(", ")
|
| 132 |
|
smtp.open_message_stream(Puppet[:reportfrom], *emails) do |p|
|
| 133 |
|
p.puts "From: #{Puppet[:reportfrom]}"
|
| 134 |
|
p.puts "Subject: Puppet Report for %s" % self.host
|
| 135 |
|
p.puts "To: " + emails.join(", ")
|
| 136 |
|
p.puts "Date: " + Time.now.rfc2822
|
| 137 |
|
p.puts
|
| 138 |
|
p.puts messages
|
|
126 |
sync.synchronize do
|
|
127 |
pid = fork do
|
|
128 |
if Puppet[:smtpserver] != "none"
|
|
129 |
begin
|
|
130 |
Net::SMTP.start(Puppet[:smtpserver]) do |smtp|
|
|
131 |
reports.each do |emails, messages|
|
|
132 |
Puppet.info "Sending report to %s" % emails.join(", ")
|
|
133 |
smtp.open_message_stream(Puppet[:reportfrom], *emails) do |p|
|
|
134 |
p.puts "From: #{Puppet[:reportfrom]}"
|
|
135 |
p.puts "Subject: Puppet Report for %s" % self.host
|
|
136 |
p.puts "To: " + emails.join(", ")
|
|
137 |
p.puts "Date: " + Time.now.rfc2822
|
|
138 |
p.puts
|
|
139 |
p.puts messages
|
|
140 |
end
|
| 139 |
141 |
end
|
| 140 |
142 |
end
|
|
143 |
rescue => detail
|
|
144 |
if Puppet[:debug]
|
|
145 |
puts detail.backtrace
|
|
146 |
end
|
|
147 |
raise Puppet::Error,
|
|
148 |
"Could not send report emails through smtp: %s" % detail
|
| 141 |
149 |
end
|
| 142 |
|
rescue => detail
|
| 143 |
|
if Puppet[:debug]
|
| 144 |
|
puts detail.backtrace
|
| 145 |
|
end
|
| 146 |
|
raise Puppet::Error,
|
| 147 |
|
"Could not send report emails through smtp: %s" % detail
|
| 148 |
|
end
|
| 149 |
|
elsif Puppet[:sendmail] != ""
|
| 150 |
|
begin
|
| 151 |
|
reports.each do |emails, messages|
|
| 152 |
|
Puppet.info "Sending report to %s" % emails.join(", ")
|
| 153 |
|
# We need to open a separate process for every set of email addresses
|
| 154 |
|
sync.synchronize do
|
|
150 |
elsif Puppet[:sendmail] != ""
|
|
151 |
begin
|
|
152 |
reports.each do |emails, messages|
|
|
153 |
Puppet.info "Sending report to %s" % emails.join(", ")
|
|
154 |
# We need to open a separate process for every set of email addresses
|
| 155 |
155 |
IO.popen(Puppet[:sendmail] + " " + emails.join(" "), "w") do |p|
|
| 156 |
156 |
p.puts "From: #{Puppet[:reportfrom]}"
|
| 157 |
157 |
p.puts "Subject: Puppet Report for %s" % self.host
|
| ... | ... | |
| 160 |
160 |
p.puts messages
|
| 161 |
161 |
end
|
| 162 |
162 |
end
|
|
163 |
rescue => detail
|
|
164 |
if Puppet[:debug]
|
|
165 |
puts detail.backtrace
|
|
166 |
end
|
|
167 |
raise Puppet::Error,
|
|
168 |
"Could not send report emails via sendmail: %s" % detail
|
| 163 |
169 |
end
|
| 164 |
|
rescue => detail
|
| 165 |
|
if Puppet[:debug]
|
| 166 |
|
puts detail.backtrace
|
| 167 |
|
end
|
| 168 |
|
raise Puppet::Error,
|
| 169 |
|
"Could not send report emails via sendmail: %s" % detail
|
|
170 |
else
|
|
171 |
raise Puppet::Error, "SMTP server is unset and could not find sendmail"
|
| 170 |
172 |
end
|
| 171 |
|
else
|
| 172 |
|
raise Puppet::Error, "SMTP server is unset and could not find sendmail"
|
| 173 |
173 |
end
|
| 174 |
|
end
|
| 175 |
174 |
|
| 176 |
|
# Don't bother waiting for the pid to return.
|
| 177 |
|
Process.detach(pid)
|
|
175 |
# Don't bother waiting for the pid to return.
|
|
176 |
Process.detach(pid)
|
|
177 |
end
|
| 178 |
178 |
end
|
| 179 |
179 |
|
| 180 |
180 |
def sync
|
| 181 |
|
-
|