Class: ForemanSalt::ReportImporter
- Inherits:
-
Object
- Object
- ForemanSalt::ReportImporter
- Defined in:
- app/services/foreman_salt/report_importer.rb
Instance Attribute Summary collapse
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Class Method Summary collapse
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(host, raw, proxy_id = nil) ⇒ ReportImporter
constructor
A new instance of ReportImporter.
Constructor Details
#initialize(host, raw, proxy_id = nil) ⇒ ReportImporter
Returns a new instance of ReportImporter.
19 20 21 22 23 |
# File 'app/services/foreman_salt/report_importer.rb', line 19 def initialize(host, raw, proxy_id = nil) @host = find_or_create_host(host) @raw = raw @proxy_id = proxy_id end |
Instance Attribute Details
#report ⇒ Object (readonly)
Returns the value of attribute report.
4 5 6 |
# File 'app/services/foreman_salt/report_importer.rb', line 4 def report @report end |
Class Method Details
.import(raw, proxy_id = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/services/foreman_salt/report_importer.rb', line 6 def self.import(raw, proxy_id = nil) raise ::Foreman::Exception, _('Invalid report') unless raw.is_a?(Hash) raw.map do |host, report| importer = ForemanSalt::ReportImporter.new(host, report, proxy_id) importer.import report = importer.report report.origin = 'Salt' report.save! report end end |
Instance Method Details
#import ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/services/foreman_salt/report_importer.rb', line 25 def import logger.info "processing report for #{@host}" logger.debug { "Report: #{@raw.inspect}" } if @host.new_record? && !Setting[:create_new_host_when_report_is_uploaded] logger.info("skipping report for #{@host} as its an unknown host and create_new_host_when_report_is_uploaded setting is disabled") return ConfigReport.new end @host.salt_proxy_id ||= @proxy_id @host.last_report = start_time if [Array, String].member? @raw.class process_failures # If Salt sends us only an array (or string), it's a list of fatal failures else process_normal end @host.save(validate: false) @host.reload @host.refresh_statuses([HostStatus.find_status_by_humanized_name('configuration')]) logger.info("Imported report for #{@host} in #{(Time.zone.now - start_time).round(2)} seconds") end |