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



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

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



31
32
33
34
35
36
37
38
39
40
# 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_attributesObject



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

def hostgroup_inherited_attributes
  super + ['monitoring_proxy_id']
end

#monitored?Boolean

Returns:

  • (Boolean)


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

def monitored?
  monitoring_proxy.present?
end

#monitoring_attributesObject



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

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

  attributes[:environment] = environment.try(:to_s) if defined?(ForemanPuppet)

  attributes
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_idsObject



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

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