Skip to content

Instantly share code, notes, and snippets.

@abarringer
Created October 11, 2010 18:54
Show Gist options
  • Save abarringer/621026 to your computer and use it in GitHub Desktop.
Save abarringer/621026 to your computer and use it in GitHub Desktop.
#I wanted to do stuff like myserver.plugins.overview.cpu_last_minute this lets me do that.
#Haven't tested the refresh to make sure it works.
#Example
# @server = ScoutServer.new("MyServer")
# puts @server.plugins.overview.disk_capacity
# puts @server.plugins.overview.mem_used
# puts @server.plugins.overview.cpu_last_five_minutes
require 'scout_scout'
class Hash
def method_missing(symbol)
self[symbol]
end
end
class ScoutServer
@@scout ||= ScoutScout.new('bsecure', 'your@email.com', 'your_password')
def initialize(host)
init_host(host)
set_plugins
end
attr_reader :server, :plugins
def refresh_stats
set_plugins
end
private
def init_host(hostname)
if hostname.class == String
@server = ScoutScout::Server.first(hostname)
else
@server = hostname
end
raise "Invalid Host #{@server.class}" unless @server.class == ScoutScout::Server
end
def set_plugins
@plugins ||= Hash.new
@server.plugins.each{|myplugin|
next unless myplugin.enabled
@plugins[myplugin.code_class.downcase.to_sym] = {}
myplugin.descriptors.each{|my_d|
@plugins[myplugin.code_class.downcase.to_sym].merge!({my_d.name.to_sym => my_d.value})
}
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment