Module: ForemanMonitoring::HostExtensions

Defined in:
app/models/concerns/foreman_monitoring/host_extensions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 3

def self.prepended(base)
  base.class_eval do
    include Orchestration::Monitoring

    after_build :downtime_host_build

    has_many :monitoring_results, :dependent => :destroy, :foreign_key => 'host_id', :inverse_of => :host
  end
end

Instance Method Details

#downtime_host(options) ⇒ Object



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

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



25
26
27
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 25

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

#hostgroup_inherited_attributesObject



43
44
45
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 43

def hostgroup_inherited_attributes
  super + ['monitoring_proxy_id']
end

#monitored?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 39

def monitored?
  monitoring_proxy.present?
end

#monitoring_attributesObject



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

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



13
14
15
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 13

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

#monitoring_status_label(options = {}) ⇒ Object



17
18
19
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 17

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

#refresh_monitoring_statusObject



21
22
23
# File 'app/models/concerns/foreman_monitoring/host_extensions.rb', line 21

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

#smart_proxy_idsObject



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

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