Class: ProxyAPI::Monitoring

Inherits:
Resource
  • Object
show all
Defined in:
app/lib/proxy_api/monitoring.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Monitoring

Returns a new instance of Monitoring.



3
4
5
6
# File 'app/lib/proxy_api/monitoring.rb', line 3

def initialize(args)
  @url = args[:url] + '/monitoring'
  super args
end

Instance Method Details

#create_host(host, attributes = {}) ⇒ Object



20
21
22
23
24
# File 'app/lib/proxy_api/monitoring.rb', line 20

def create_host(host, attributes = {})
  parse(put({ :attributes => attributes }, "host/#{host}"))
rescue => e
  raise ProxyException.new(url, e, N_('Unable to create monitoring host object for %s') % host)
end

#create_host_downtime(host, args = {}) ⇒ Object



8
9
10
11
12
# File 'app/lib/proxy_api/monitoring.rb', line 8

def create_host_downtime(host, args = {})
  parse(post(args, "downtime/host/#{host}"))
rescue => e
  raise ProxyException.new(url, e, N_('Unable to set downtime for %s') % host)
end

#delete_host(host) ⇒ Object



32
33
34
35
36
37
38
39
# File 'app/lib/proxy_api/monitoring.rb', line 32

def delete_host(host)
  raise Foreman::Exception, 'Missing hostname.' if host.blank?
  parse(delete("host/#{host}"))
rescue RestClient::ResourceNotFound
  true
rescue => e
  raise ProxyException.new(url, e, N_('Unable to delete monitoring host object for %s') % host)
end

#query_host(host) ⇒ Object



41
42
43
44
45
46
47
# File 'app/lib/proxy_api/monitoring.rb', line 41

def query_host(host)
  parse(get("host/#{host}"))
rescue RestClient::ResourceNotFound
  nil
rescue => e
  raise ProxyException.new(url, e, N_('Unable to query monitoring host object for %{host}: %{message}') % { :host => host, :message => e.try(:response) || e.try(:message) })
end

#remove_host_downtime(host, args = {}) ⇒ Object



14
15
16
17
18
# File 'app/lib/proxy_api/monitoring.rb', line 14

def remove_host_downtime(host, args = {})
  parse(delete("downtime/host/#{host}?#{args.to_query}"))
rescue => e
  raise ProxyException.new(url, e, N_('Unable to remove downtime for %s') % host)
end

#update_host(host, attributes = {}) ⇒ Object



26
27
28
29
30
# File 'app/lib/proxy_api/monitoring.rb', line 26

def update_host(host, attributes = {})
  parse(post({ :attributes => attributes }, "host/#{host}"))
rescue => e
  raise ProxyException.new(url, e, N_('Unable to update monitoring host object for %s') % host)
end