Class: Monitoring

Inherits:
Object
  • Object
show all
Defined in:
app/services/monitoring.rb

Constant Summary collapse

CREATE_ACTIONS =
{
  'none' => _('None'),
  'create' => _('Create Host Object')
}.freeze
DELETE_ACTIONS =
{
  'none' => _('None'),
  'delete' => _('Delete Host Object'),
  'downtime' => _('Set Downtime for Host')
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Monitoring

Returns a new instance of Monitoring.



24
25
26
27
# File 'app/services/monitoring.rb', line 24

def initialize(opts)
  @proxy = opts.fetch(:monitoring_proxy)
  @proxy_api = ProxyAPI::Monitoring.new(:url => proxy.url)
end

Instance Attribute Details

#proxyObject (readonly)

Returns the value of attribute proxy.



14
15
16
# File 'app/services/monitoring.rb', line 14

def proxy
  @proxy
end

#proxy_apiObject (readonly)

Returns the value of attribute proxy_api.



14
15
16
# File 'app/services/monitoring.rb', line 14

def proxy_api
  @proxy_api
end

Class Method Details

.create_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'app/services/monitoring.rb', line 16

def self.create_action?(action)
  Setting[:monitoring_create_action] == action.to_s
end

.delete_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/services/monitoring.rb', line 20

def self.delete_action?(action)
  Setting[:monitoring_delete_action] == action.to_s
end

Instance Method Details

#create_host(host) ⇒ Object



37
38
39
# File 'app/services/monitoring.rb', line 37

def create_host(host)
  proxy_api.create_host(host.name, host.monitoring_attributes)
end

#del_downtime_host(host, options = {}) ⇒ Object



33
34
35
# File 'app/services/monitoring.rb', line 33

def del_downtime_host(host, options = {})
  proxy_api.remove_host_downtime(host.name, default_downtime_options.merge(options))
end

#delete_host(host) ⇒ Object



45
46
47
# File 'app/services/monitoring.rb', line 45

def delete_host(host)
  proxy_api.delete_host(host.name)
end

#query_host(host) ⇒ Object



49
50
51
52
53
54
55
# File 'app/services/monitoring.rb', line 49

def query_host(host)
  result = proxy_api.query_host(host.name)
  return {} unless result
  {
    :attrs => result
  }
end

#set_downtime_host(host, options = {}) ⇒ Object



29
30
31
# File 'app/services/monitoring.rb', line 29

def set_downtime_host(host, options = {})
  proxy_api.create_host_downtime(host.name, default_downtime_options.merge(options))
end

#update_host(host) ⇒ Object



41
42
43
# File 'app/services/monitoring.rb', line 41

def update_host(host)
  proxy_api.update_host(host.name, host.monitoring_attributes)
end