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

Instance Method Summary collapse

Instance Method Details

#blueprintObject



20
21
22
23
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 20

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

#deliver!Object



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

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

#hosts_countObject



25
26
27
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 25

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


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

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


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

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


34
35
36
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 34

def links
  job_links + insights_links
end

#messageObject



29
30
31
32
# File 'app/services/foreman_ansible/insights_notification_builder.rb', line 29

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