Project

General

Profile

Bug #578 ยป 0043-Fixes-blank-e-mails-due-to-reports-being-saved-after.patch

Eric Shamow, 01/13/2011 06:14 PM

View differences:

app/models/report.rb
r = self.create!(:host => host, :reported_at => report.time.utc, :status => st, :metrics => self.m2h(report.metrics))
# Store all Puppet message logs
r.import_log_messages report
r.inspect_report
return r
rescue Exception => e
logger.warn "Failed to process report for #{report.host} due to:#{e}"
......
end
end
def inspect_report
if error?
# found a report with errors
# notify via email IF enabled is set to true
if host.disabled?
logger.warn "#{host} is disabled - skipping."
return
end
HostMailer.deliver_error_state(self) if SETTINGS[:failed_report_email_notification]
# add here more actions - e.g. snmp alert etc
end
rescue => e
logger.warn "failed to send failure email notification: #{e}"
end
private
# Converts metrics form Puppet report into a hash
......
errors.add_to_base "You do not have permission to #{operation} this report"
false
end
end
app/models/report_observer.rb
class ReportObserver < ActiveRecord::Observer
def after_save report
if report.error?
# found a report with errors
# notify via email IF enabled is set to true
if report.host.disabled?
report.logger.warn "#{report.host} is disabled - skipping."
return
end
HostMailer.deliver_error_state(report) if SETTINGS[:failed_report_email_notification]
# add here more actions - e.g. snmp alert etc
end
rescue => e
report.logger.warn "failed to send failure email notification: #{e}" if report.logger
end
end
    (1-1/1)