Class: ProxyAPI::Monitoring
- Inherits:
-
Resource
- Object
- Resource
- ProxyAPI::Monitoring
- Defined in:
- app/lib/proxy_api/monitoring.rb
Instance Method Summary collapse
- #create_host(host, attributes = {}) ⇒ Object
- #create_host_downtime(host, args = {}) ⇒ Object
- #delete_host(host) ⇒ Object
-
#initialize(args) ⇒ Monitoring
constructor
A new instance of Monitoring.
- #query_host(host) ⇒ Object
- #remove_host_downtime(host, args = {}) ⇒ Object
- #update_host(host, attributes = {}) ⇒ Object
Constructor Details
#initialize(args) ⇒ Monitoring
Returns a new instance of Monitoring.
5 6 7 8 |
# File 'app/lib/proxy_api/monitoring.rb', line 5 def initialize(args) @url = "#{args[:url]}/monitoring" super args end |
Instance Method Details
#create_host(host, attributes = {}) ⇒ Object
22 23 24 25 26 |
# File 'app/lib/proxy_api/monitoring.rb', line 22 def create_host(host, attributes = {}) parse(put({ :attributes => attributes }, "host/#{host}")) rescue StandardError => e raise ProxyException.new(url, e, N_('Unable to create monitoring host object for %s') % host) end |
#create_host_downtime(host, args = {}) ⇒ Object
10 11 12 13 14 |
# File 'app/lib/proxy_api/monitoring.rb', line 10 def create_host_downtime(host, args = {}) parse(post(args, "downtime/host/#{host}")) rescue StandardError => e raise ProxyException.new(url, e, N_('Unable to set downtime for %s') % host) end |
#delete_host(host) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/lib/proxy_api/monitoring.rb', line 34 def delete_host(host) raise Foreman::Exception, 'Missing hostname.' if host.blank? parse(delete("host/#{host}")) rescue RestClient::ResourceNotFound true rescue StandardError => e raise ProxyException.new(url, e, N_('Unable to delete monitoring host object for %s') % host) end |
#query_host(host) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/lib/proxy_api/monitoring.rb', line 44 def query_host(host) parse(get("host/#{host}")) rescue RestClient::ResourceNotFound nil rescue StandardError => 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
16 17 18 19 20 |
# File 'app/lib/proxy_api/monitoring.rb', line 16 def remove_host_downtime(host, args = {}) parse(delete("downtime/host/#{host}?#{args.to_query}")) rescue StandardError => e raise ProxyException.new(url, e, N_('Unable to remove downtime for %s') % host) end |
#update_host(host, attributes = {}) ⇒ Object
28 29 30 31 32 |
# File 'app/lib/proxy_api/monitoring.rb', line 28 def update_host(host, attributes = {}) parse(post({ :attributes => attributes }, "host/#{host}")) rescue StandardError => e raise ProxyException.new(url, e, N_('Unable to update monitoring host object for %s') % host) end |