Class: ScoutScout::Server

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/scout_scout/server.rb

Class Method Summary collapse

Instance Method Summary collapse

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’)

Returns:

  • (Array)

    An array of ScoutScout::Server objects

Raises:



29
30
31
32
33
34
# File 'lib/scout_scout/server.rb', line 29

def self.all(options)
  hostname = options[:host]
  raise ScoutScout::Error, "Please specify a host via :host" if hostname.nil?
  response = ScoutScout.get("/#{ScoutScout.}/clients.xml?host=#{hostname}")
  response['clients'] ? response['clients'].map { |client| ScoutScout::Server.new(client) } : Array.new
end

.first(server_id_or_hostname) ⇒ ScoutScout::Server

Search for a server by id or matching hostname

Returns:



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.}/clients/#{server_id_or_hostname}.xml")
    ScoutScout::Server.new(response['client'])
  else
    response = ScoutScout.get("/#{ScoutScout.}/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_alertsArray

Active alerts for this server

Returns:

  • (Array)

    An array of ScoutScout::Alert objects



39
40
41
# File 'lib/scout_scout/server.rb', line 39

def active_alerts
  @active_alerts ||= @alert_hash.map { |a| decorate_with_server(ScoutScout::Alert.new(a)) }
end

#alertsArray

Recent alerts for this server

Returns:

  • (Array)

    An array of ScoutScout::Alert objects



46
47
48
49
# File 'lib/scout_scout/server.rb', line 46

def alerts
  response = ScoutScout.get("/#{ScoutScout.}/clients/#{self.id}/activities.xml")
  response['alerts'].map { |alert| decorate_with_server(ScoutScout::Alert.new(alert)) }
end

#descriptorsArray

All descriptors for this server

Returns:

  • (Array)

    An array of ScoutScout::Descriptor objects



70
71
72
# File 'lib/scout_scout/server.rb', line 70

def descriptors
  ScoutScout::Descriptor.all(:host => hostname).map { |d| decorate_with_server(d) }
end

#plugin(id) ⇒ ScoutScout::Plugin

Details about a specific plugin

Returns:



62
63
64
65
# File 'lib/scout_scout/server.rb', line 62

def plugin(id)
  response = ScoutScout.get("/#{ScoutScout.}/clients/#{self.id}/plugins/#{id}.xml")
  decorate_with_server(ScoutScout::Plugin.new(response['plugin']))
end

#pluginsArray

Details about all plugins for this server

Returns:

  • (Array)

    An array of ScoutScout::Plugin objects



54
55
56
57
# File 'lib/scout_scout/server.rb', line 54

def plugins
  response = ScoutScout.get("/#{ScoutScout.}/clients/#{self.id}/plugins.xml")
  response['plugins'].map { |plugin| decorate_with_server(ScoutScout::Plugin.new(plugin)) }
end