Class: VolumeSweeper::Utils::NotificationFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/volume_sweeper/utils/notification_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(provider_base_url, run_mode) ⇒ NotificationFormatter

Returns a new instance of NotificationFormatter.



8
9
10
11
# File 'lib/volume_sweeper/utils/notification_formatter.rb', line 8

def initialize provider_base_url, run_mode
  @provider_base_url = provider_base_url
  @run_mode = run_mode || :audit
end

Instance Method Details

#formlate_meessage(volumes, active_count: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/volume_sweeper/utils/notification_formatter.rb', line 13

def formlate_meessage volumes, active_count: nil
  active_list = volumes[:active_ids]
  unused_list = volumes[:unused_ids]
  active_count = active_count || volumes[:active_ids] || 0

  if unused_list.blank? || unused_list.none?
    <<~EOD
      The environment is scanned and no unused block volumes found.<br>
      * Active volumes: #{active_count}<br>
      * Unused volumes: #{unused_list&.count || 0}<br>
    EOD
  else
    notice = @run_mode == :delete ? "scheduled for deletion" : "eligibile for deletion"
    ERB.new(
      <<~HTML
        The environment is scanned.<br>
        * Active volumes: #{active_count}<br>
        * Unused volumes: #{unused_list&.count || 0}<br><br>

        Found the following volumes without instance bound or K8S PV relation.<br>
        <u>(#{notice}).</u> <br>
        <ul style="color: #400707">
          <% unused_list.each do |vol| %>
          <li><a href="#{@provider_base_url}/<%= vol %>"><%= vol %></a>.</li>
          <% end %>
        </ul>
      HTML
    ).result(binding)
  end
end