Sha256: ce93c94a08e6e4e1405804ffd057f596d4b559414eecb946704468eeae23f62b

Contents?: true

Size: 1.46 KB

Versions: 19

Compression:

Stored size: 1.46 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
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
foreman_rh_cloud-3.0.33 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.32 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.29 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.28 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.26 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-4.0.25.1 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.25 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-4.0.25 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.24.1 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-4.0.24.1 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.24 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-4.0.24 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.23 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-4.0.23 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.22 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-4.0.22 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-4.0.21.1 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.21.1 lib/insights_cloud/async/insights_generate_notifications.rb
foreman_rh_cloud-3.0.21 lib/insights_cloud/async/insights_generate_notifications.rb