Class: InsightsCloud::Async::InsightsGenerateNotifications

Inherits:
Actions::EntryAction
  • Object
show all
Defined in:
lib/insights_cloud/async/insights_generate_notifications.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.blueprintObject

cache blueprint on class level, so it won’t be reloaded on subsequent calls



7
8
9
# File 'lib/insights_cloud/async/insights_generate_notifications.rb', line 7

def self.blueprint
  @blueprint ||= NotificationBlueprint.find_by(name: 'insights_satellite_hits')
end

Instance Method Details

#add_satellite_notificationsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/insights_cloud/async/insights_generate_notifications.rb', line 15

def add_satellite_notifications
  host = foreman_host

  # Skip if no Foreman host record exists
  unless host
    logger.debug("Skipping Insights notifications: no Foreman host record found")
    blueprint&.notifications&.destroy_all
    return
  end

  hits_count = InsightsHit.where(host_id: host.id).count

  # Remove stale notifications
  blueprint.notifications.destroy_all

  if hits_count > 0
    add_notification(hits_count)
  end
end

#runObject



11
12
13
# File 'lib/insights_cloud/async/insights_generate_notifications.rb', line 11

def run
  add_satellite_notifications
end