Bug #78 ยป report.rb.patch
app/models/report.rb 2009-11-12 21:28:49.000000000 +0100 | ||
---|---|---|
def self.import(yaml)
|
||
report = YAML.load(yaml)
|
||
raise "Invalid report" unless report.is_a?(Puppet::Transaction::Report)
|
||
logger.info "processing report for #{report.name}"
|
||
logger.info "processing report for #{report.host}"
|
||
begin
|
||
host = Host.find_or_create_by_name report.host
|
||
report_status = host.puppet_status = report_status(report)
|
||
... | ... | |
self.create! :host => host, :reported_at => report.time.utc, :log => report, :status => report_status
|
||
rescue Exception => e
|
||
logger.warn "failed to process report for #{report.name} due to:#{e}"
|
||
logger.warn "failed to process report for #{report.host} due to:#{e}"
|
||
end
|
||
end
|
||
... | ... | |
status = 0
|
||
raise "Invalid report: can't find metrics information for #{report.host} at #{report.id}" if report.metrics.nil?
|
||
resources = report.metrics["resources"]
|
||
resources_failed = resources.values.find { |v| v[0] == :failed }[2]
|
||
resources_skipped = resources.values.find { |v| v[0] == :skipped }[2]
|
||
resources_failed_restarts = resources.values.find { |v| v[0] == :failed_restarts }[2]
|
||
total_report_changes = report.metrics["changes"].values.find { |v| v[0] == :total }[2]
|
||
# check if the report actually contain anything interesting
|
||
if resources[:failed] + resources[:skipped] + resources[:failed_restarts] + report.metrics["changes"][:total] > 0
|
||
status = resources[:failed] if resources[:failed] > 0
|
||
if resources_failed + resources_skipped + resources_failed_restarts + total_report_changes > 0
|
||
status = resources_failed if resources_failed > 0
|
||
# We only capture skipped errors when there are associated log entries.
|
||
# Sometimes there are skipped entries but no errors in the messages file,
|
||
# This can happen when having notice, alias messages etc
|
||
status |= resources[:skipped] if resources[:skipped] > 0 and report.logs.size >0
|
||
status |= resources_skipped if resources_skipped > 0 and report.logs.size >0
|
||
status |= resources[:failed_restarts] << 24 if resources[:failed_restarts] > 0
|
||
status |= resources_failed_restarts << 24 if resources_failed_restarts > 0
|
||
end
|
||
return status
|
||
... | ... | |
def validate_meteric (type, name)
|
||
begin
|
||
log.metrics[type][name]
|
||
log.metrics[type].values.find { |v| v[0] == name }[2]
|
||
rescue
|
||
nil
|
||
end
|