Project

General

Profile

report.rb.patch

Benoit CATTIE, 11/12/2009 08:40 PM

View differences:

app/models/report.rb 2009-11-12 21:28:49.000000000 +0100
43 43
  def self.import(yaml)
44 44
    report = YAML.load(yaml)
45 45
    raise "Invalid report" unless report.is_a?(Puppet::Transaction::Report)
46
    logger.info "processing report for #{report.name}"
46
    logger.info "processing report for #{report.host}"
47 47
    begin
48 48
      host = Host.find_or_create_by_name report.host
49 49
      report_status = host.puppet_status = report_status(report)
......
57 57

  
58 58
      self.create! :host => host, :reported_at => report.time.utc, :log => report, :status => report_status
59 59
    rescue Exception => e
60
      logger.warn "failed to process report for #{report.name} due to:#{e}"
60
      logger.warn "failed to process report for #{report.host} due to:#{e}"
61 61
    end
62 62
  end
63 63

  
......
101 101
      status = 0
102 102
      raise "Invalid report: can't find metrics information for #{report.host} at #{report.id}" if report.metrics.nil?
103 103
      resources = report.metrics["resources"]
104
      resources_failed = resources.values.find { |v| v[0] == :failed }[2]
105
      resources_skipped = resources.values.find { |v| v[0] == :skipped }[2]
106
      resources_failed_restarts = resources.values.find { |v| v[0] == :failed_restarts }[2]
107
      total_report_changes = report.metrics["changes"].values.find { |v| v[0] == :total }[2]
108

  
104 109
      # check if the report actually contain anything interesting
105
      if resources[:failed] + resources[:skipped] + resources[:failed_restarts] + report.metrics["changes"][:total] > 0
106
        status  = resources[:failed] if resources[:failed] > 0
110
      if resources_failed + resources_skipped + resources_failed_restarts + total_report_changes > 0  
111
       status  = resources_failed if resources_failed > 0
107 112
        # We only capture skipped errors when there are associated log entries.
108 113
        # Sometimes there are skipped entries but no errors in the messages file,
109 114
        # This can happen when having notice, alias messages etc
110
        status |= resources[:skipped] if resources[:skipped] > 0 and report.logs.size >0
115
        status |= resources_skipped if resources_skipped > 0 and report.logs.size >0
111 116

  
112
        status |= resources[:failed_restarts] << 24 if resources[:failed_restarts] > 0
117
        status |= resources_failed_restarts << 24 if resources_failed_restarts > 0
113 118
      end
114 119

  
115 120
      return status
......
119 124

  
120 125
  def validate_meteric (type, name)
121 126
    begin
122
      log.metrics[type][name]
127
      log.metrics[type].values.find { |v| v[0] == name }[2]
123 128
    rescue
124 129
      nil
125 130
    end