Class: ForemanAnsible::InsightsNotificationBuilder

Inherits:
UINotifications::RemoteExecutionJobs::BaseJobFinish
  • Object
show all
Defined in:
app/services/foreman_ansible/insights_notification_builder.rb

Overview

A class that builds custom notificaton for REX job if it’s insights remediation feature rubocop:disable LineLength

Instance Method Summary collapse

Instance Method Details

#blueprintObject



22
23
24
25
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 22

def blueprint
  name = 'insights_remediation_successful'
  @blueprint ||= NotificationBlueprint.unscoped.find_by(:name => name)
end

#deliver!Object

rubocop:enable LineLength



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 9

def deliver!
  ::Notification.create!(
    :audience => Notification::AUDIENCE_USER,
    :notification_blueprint => blueprint,
    :initiator => initiator,
    :message => message,
    :subject => subject,
    :actions => {
      :links => links
    }
  )
end

#hosts_countObject



27
28
29
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 27

def hosts_count
  @hosts_count ||= subject.template_invocations_hosts.size
end


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 40

def insights_links
  pattern_template = subject.pattern_template_invocations.first
  plan_id = pattern_template.input_values.
            joins(:template_input).
            where('template_inputs.name' => 'plan_id').
            first.try(:value)
  return [] if plan_id.nil?

  [
    {
      :href => "/redhat_access/insights/planner/#{plan_id}",
      :title => _('Remediation Plan')
    }
  ]
end


56
57
58
59
60
61
62
63
64
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 56

def job_links
  UINotifications::URLResolver.new(
    subject,
    :links => [{
      :path_method => :job_invocation_path,
      :title => _('Job Details')
    }]
  ).actions[:links]
end


36
37
38
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 36

def links
  job_links + insights_links
end

#messageObject



31
32
33
34
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 31

def message
  UINotifications::StringParser.new(blueprint.message,
                                    :hosts_count => hosts_count)
end