Created
October 11, 2010 18:54
-
-
Save abarringer/621026 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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', '[email protected]', '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