class InsightsCloud::Async::InsightsGenerateNotifications

Public Class Methods

blueprint() click to toggle source

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

# File lib/insights_cloud/async/insights_generate_notifications.rb, line 7
def self.blueprint
  @blueprint ||= NotificationBlueprint.find_by(name: 'insights_satellite_hits')
end

Public Instance Methods

add_satellite_notifications() click to toggle source
# File lib/insights_cloud/async/insights_generate_notifications.rb, line 15
def add_satellite_notifications
  hits_count = InsightsHit.where(host_id: foreman_host.id).count

  # Remove stale notifications
  blueprint.notifications.destroy_all

  if hits_count > 0
    add_notification(hits_count)
  end
end
run() click to toggle source
# File lib/insights_cloud/async/insights_generate_notifications.rb, line 11
def run
  add_satellite_notifications
end

Private Instance Methods

add_notification(hits_count) click to toggle source
# File lib/insights_cloud/async/insights_generate_notifications.rb, line 40
def add_notification(hits_count)
  Notification.create!(
    initiator: User.anonymous_admin,
    audience: ::Notification::AUDIENCE_ADMIN,
    message: UINotifications::StringParser.new(blueprint.message, {hits_count: hits_count}).to_s,
    notification_blueprint: blueprint,
    actions: {
      links: [
        {
          href: Rails.application.routes.url_helpers.foreman_rh_cloud_insights_cloud_path(search: "hostname=#{foreman_host.name}"),
          title: _('Fix host'),
        },
      ],
    }
  )
end
blueprint() click to toggle source
# File lib/insights_cloud/async/insights_generate_notifications.rb, line 36
def blueprint
  self.class.blueprint
end
foreman_host() click to toggle source
# File lib/insights_cloud/async/insights_generate_notifications.rb, line 32
def foreman_host
  ForemanRhCloud.foreman_host
end
logger() click to toggle source
# File lib/insights_cloud/async/insights_generate_notifications.rb, line 28
def logger
  action_logger
end