Module: ForemanMonitoring::HostExtensions

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/foreman_monitoring/host_extensions.rb

Instance Method Summary collapse

Instance Method Details

#downtime_host(options) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 31

def downtime_host(options)
  return unless monitored?
  begin
    monitoring.set_downtime_host(self, options)
  rescue ProxyAPI::ProxyException => e
    errors.add(:base, _("Error setting downtime: '%s'") % e.message)
  end
  errors.empty?
end

#downtime_host_buildObject



27
28
29
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 27

def downtime_host_build
  downtime_host(:comment => _('Host rebuilt in Foreman'))
end

#hostgroup_inherited_attributes_with_monitoringObject



45
46
47
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 45

def hostgroup_inherited_attributes_with_monitoring
  hostgroup_inherited_attributes_without_monitoring + ['monitoring_proxy_id']
end

#monitored?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 41

def monitored?
  monitoring_proxy.present?
end

#monitoring_attributesObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 57

def monitoring_attributes
  {
    :ip => ip,
    :ip6 => ip6,
    :architecture => architecture.try(:name),
    :os => operatingsystem.try(:to_label),
    :osfamily => operatingsystem.try(:family),
    :virtual => provider != 'BareMetal',
    :provider => provider,
    :compute_resource => compute_resource.try(:to_label),
    :hostgroup => hostgroup.try(:to_label),
    :organization => organization.try(:name),
    :location => organization.try(:name),
    :comment => comment,
    :environment => environment.try(:to_s),
    :owner_name => owner.try(:name)
  }
end

#monitoring_status(options = {}) ⇒ Object



15
16
17
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 15

def monitoring_status(options = {})
  @monitoring_status ||= get_status(HostStatus::MonitoringStatus).to_status(options)
end

#monitoring_status_label(options = {}) ⇒ Object



19
20
21
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 19

def monitoring_status_label(options = {})
  @monitoring_status_label ||= get_status(HostStatus::MonitoringStatus).to_label(options)
end

#refresh_monitoring_statusObject



23
24
25
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 23

def refresh_monitoring_status
  get_status(HostStatus::MonitoringStatus).refresh
end

#smart_proxy_ids_with_monitoring_proxyObject



49
50
51
52
53
54
55
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 49

def smart_proxy_ids_with_monitoring_proxy
  ids = smart_proxy_ids_without_monitoring_proxy
  [monitoring_proxy, hostgroup.try(:monitoring_proxy)].compact.each do |proxy|
    ids << proxy.id
  end
  ids
end