Sha256: 7f2b504cb9a0ca652a9f47472584d4481cadf3396c2c3c188c418152abd5160f
Contents?: true
Size: 1.54 KB
Versions: 53
Compression:
Stored size: 1.54 KB
Contents
require 'rest-client' module InsightsCloud module Async class InsightsGenerateNotifications < ::Actions::EntryAction # cache blueprint on class level, so it won't be reloaded on subsequent calls def self.blueprint @blueprint ||= NotificationBlueprint.find_by(name: 'insights_satellite_hits') end def run add_satellite_notifications end 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 private def logger action_logger end def foreman_host ForemanRhCloud.foreman_host end def blueprint self.class.blueprint end 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 def rescue_strategy_for_self Dynflow::Action::Rescue::Fail end end end end
Version data entries
53 entries across 53 versions & 1 rubygems