Module: ForemanMonitoring::HostsControllerExtensions

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb

Instance Method Summary collapse

Instance Method Details

#downtimeObject



18
19
20
21
22
23
24
# File 'app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb', line 18

def downtime
  unless @host.downtime_host(downtime_options)
    process_error(:redirect => host_path, :error_msg => @host.errors.full_messages.to_sentence)
    return false
  end
  process_success :success_msg => _('Created downtime for %s') % @host, :success_redirect => :back
end

#select_multiple_downtimeObject



26
# File 'app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb', line 26

def select_multiple_downtime; end

#select_multiple_monitoring_proxyObject



62
# File 'app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb', line 62

def select_multiple_monitoring_proxy; end

#update_multiple_downtimeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb', line 28

def update_multiple_downtime
  failed_hosts = {}

  @hosts.each do |host|
    unless host.monitored?
      failed_hosts[host.name] = _('is not monitored')
      next
    end
    begin
      unless host.downtime_host(downtime_options)
        error_message = host.errors.full_messages.to_sentence
        failed_hosts[host.name] = error_message
        logger.error "Failed to set a host downtime for #{host}: #{error_message}"
      end
    rescue => error
      failed_hosts[host.name] = error
      Foreman::Logging.exception(_('Failed to set a host downtime for %s.') % host, error)
    end
  end

  if failed_hosts.empty?
    notice _('A downtime was set for the selected hosts.')
  else
    error n_('A downtime clould not be set for host: %s.',
             'A downtime could not be set for hosts: %s.',
             failed_hosts.count) % failed_hosts.map { |h, err| "#{h} (#{err})" }.to_sentence
  end
  redirect_back_or_to hosts_path
end

#update_multiple_monitoring_proxyObject



64
65
66
# File 'app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb', line 64

def update_multiple_monitoring_proxy
  update_multiple_proxy(_('Monitoring'), :monitoring_proxy=)
end

#update_multiple_power_state_with_monitoringObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb', line 68

def update_multiple_power_state_with_monitoring
  options = {
    :comment => 'Power state changed in Foreman',
    :author => "Foreman User #{User.current}",
    :start_time => Time.current.to_i,
    :end_time => Time.current.advance(:minutes => 30).to_i
  }
  set_downtime = Foreman::Cast.to_bool(params[:power][:set_downtime])
  if set_downtime && User.current.allowed_to?(:controller => :hosts, :action => :select_multiple_downtime)
    @hosts.each do |host|
      unless host.monitored?
        logger.debug "Not setting a downtime for #{host} as it is not monitored."
        next
      end
      if host.downtime_host(options)
        logger.debug "Set a host downtime for #{host}."
      else
        logger.error "Failed to set a host downtime for #{host}: #{host.errors.full_messages.to_sentence}"
      end
    end
  end
  update_multiple_power_state_without_monitoring
end

#validate_multiple_monitoring_proxyObject



58
59
60
# File 'app/controllers/concerns/foreman_monitoring/hosts_controller_extensions.rb', line 58

def validate_multiple_monitoring_proxy
  validate_multiple_proxy(select_multiple_monitoring_proxy_hosts_path)
end