Class: ScoutScout::Server
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- ScoutScout::Server
- Defined in:
- lib/scout_scout/server.rb
Class Method Summary collapse
-
.all(options) ⇒ Array
Search for servers by matching hostname via :host.
-
.create(name, options = {}) ⇒ ScoutScout::Server
Creates a new server.
-
.delete(id) ⇒ true
Delete a server by id.
-
.first(server_id_or_hostname) ⇒ ScoutScout::Server
Search for a server by id or matching hostname.
Instance Method Summary collapse
-
#active_alerts ⇒ Array
Active alerts for this server.
-
#alerts ⇒ Array
Recent alerts for this server.
-
#descriptors ⇒ Array
All descriptors for this server.
-
#initialize(hash) ⇒ Server
constructor
A new instance of Server.
-
#plugin(id) ⇒ ScoutScout::Plugin
Details about a specific plugin.
-
#plugins ⇒ Array
Details about all plugins for this server.
-
#triggers ⇒ Array
Details about all triggers for this server.
Constructor Details
#initialize(hash) ⇒ Server
Returns a new instance of Server.
2 3 4 5 6 7 8 |
# File 'lib/scout_scout/server.rb', line 2 def initialize(hash) if hash['active_alerts'] @alert_hash = hash['active_alerts'] hash.delete('active_alerts') end super(hash) end |
Class Method Details
.all(options) ⇒ Array
Search for servers by matching hostname via :host.
Example: ScoutScout::Server.all(:host => ‘soawesome.org’)
60 61 62 63 64 65 |
# File 'lib/scout_scout/server.rb', line 60 def self.all() hostname = [:host] raise ScoutScout::Error, "Please specify a host via :host" if hostname.nil? response = ScoutScout.get("/#{ScoutScout.account}/clients.xml?host=#{hostname}") response['clients'] ? response['clients'].map { |client| ScoutScout::Server.new(client) } : Array.new end |
.create(name, options = {}) ⇒ ScoutScout::Server
Creates a new server. If an error occurs, a ScoutScout::Error
is raised.
An optional existing server id can be used as a template: ScoutScout::Server.create(‘web server 12’,:id => 99999)
30 31 32 33 34 35 36 37 38 |
# File 'lib/scout_scout/server.rb', line 30 def self.create(name, = {}) id = [:id] response = ScoutScout.post("/#{ScoutScout.account}/clients.xml", :query => {:client => {:name => name, :copy_plugins_from_client_id => id}}) raise ScoutScout::Error, response['errors']['error'] if response['errors'] first(response.headers['id'].first.to_i) end |
.delete(id) ⇒ true
Delete a server by id. If an error occurs, a ScoutScout::Error
is raised.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/scout_scout/server.rb', line 43 def self.delete(id) response = ScoutScout.delete("/#{ScoutScout.account}/clients/#{id}.xml") if response.headers['status'].first.match('404') raise ScoutScout::Error, "Server Not Found" elsif !response.headers['status'].first.match('200') raise ScoutScout::Error, "An error occured" else return true end end |
.first(server_id_or_hostname) ⇒ ScoutScout::Server
Search for a server by id or matching hostname
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/scout_scout/server.rb', line 13 def self.first(server_id_or_hostname) if server_id_or_hostname.is_a?(Fixnum) response = ScoutScout.get("/#{ScoutScout.account}/clients/#{server_id_or_hostname}.xml") ScoutScout::Server.new(response['client']) else response = ScoutScout.get("/#{ScoutScout.account}/clients.xml?host=#{server_id_or_hostname}") raise ScoutScout::Error, 'Not Found' if response['clients'].nil? ScoutScout::Server.new(response['clients'].first) end end |
Instance Method Details
#active_alerts ⇒ Array
Active alerts for this server
70 71 72 |
# File 'lib/scout_scout/server.rb', line 70 def active_alerts @active_alerts ||= @alert_hash.map { |a| decorate_with_server(ScoutScout::Alert.new(a)) } end |
#alerts ⇒ Array
Recent alerts for this server
77 78 79 80 |
# File 'lib/scout_scout/server.rb', line 77 def alerts response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/activities.xml") response['alerts'].map { |alert| decorate_with_server(ScoutScout::Alert.new(alert)) } end |
#descriptors ⇒ Array
All descriptors for this server
101 102 103 |
# File 'lib/scout_scout/server.rb', line 101 def descriptors ScoutScout::Descriptor.all(:host => hostname).map { |d| decorate_with_server(d) } end |
#plugin(id) ⇒ ScoutScout::Plugin
Details about a specific plugin
93 94 95 96 |
# File 'lib/scout_scout/server.rb', line 93 def plugin(id) response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/plugins/#{id}.xml") decorate_with_server(ScoutScout::Plugin.new(response['plugin'])) end |
#plugins ⇒ Array
Details about all plugins for this server
85 86 87 88 |
# File 'lib/scout_scout/server.rb', line 85 def plugins response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/plugins.xml") response['plugins'].map { |plugin| decorate_with_server(ScoutScout::Plugin.new(plugin)) } end |
#triggers ⇒ Array
Details about all triggers for this server
108 109 110 111 |
# File 'lib/scout_scout/server.rb', line 108 def triggers response = ScoutScout.get("/#{ScoutScout.account}/clients/#{self.id}/triggers.xml") response['triggers'].map { |trigger| decorate_with_server(ScoutScout::Trigger.new(trigger)) } end |