agent_filter(*args)
click to toggle source
def agent_filter(*args)
@agent.agent_filter(*args)
print_filter
end
class_filter(*args)
click to toggle source
def class_filter(*args)
@agent.class_filter(*args)
print_filter
end
consolize() { || ... }
click to toggle source
def consolize &block
yield
IRB.setup(nil)
irb = IRB::Irb.new
IRB.conf[:MAIN_CONTEXT] = irb.context
irb.context.evaluate("require 'irb/completion'", 0)
begin
require 'bond'
Bond.start
Bond.complete(:method => "rpc") do |e|
begin
if e.argument == 1
if e.arguments.last == "?"
puts "\n\nActions for #{@agent_name}:\n"
@agent.ddl.actions.each do |action|
puts "%20s - %s" % [ ":#{action}", @agent.ddl.action_interface(action)[:description] ]
end
print "\n" + e.line
end
@agent.ddl.actions
elsif e.argument > 1
action = eval(e.arguments[0]).to_s
ddl = @agent.ddl.action_interface(action)
if e.arguments.last == "?"
puts "\n\nArguments for #{action}:\n"
ddl[:input].keys.each do |input|
puts "%20s - %s" % [ ":#{input}", ddl[:input][input][:description] ]
end
print "\n" + e.line
end
[ddl[:input].keys, :verbose].flatten
end
rescue Exception
[]
end
end
rescue Exception
end
trap("SIGINT") do
irb.signal_handle
end
catch(:IRB_EXIT) do
irb.eval_input
end
end
discover()
click to toggle source
def discover
@agent.discover
end
fact_filter(*args)
click to toggle source
def fact_filter(*args)
@agent.fact_filter(*args)
print_filter
end
identity_filter(*args)
click to toggle source
def identity_filter(*args)
@agent.identity_filter(*args)
print_filter
end
instance_variable_defined?(meth)
click to toggle source
def instance_variable_defined?(meth)
instance_variables.include?(meth)
end
mc?()
click to toggle source
def mc?
puts " Available Commands:
rpc - Performs an RPC request
reset - Resets the discovered knowledge
discover - Performs a new discovery showing
hosts that was found
newagent - Switches to a new agent
mchelp - The DDL created help for the agent
Filter Commands:
Filter arguments should be enclosed in "your.host.com" if they are strings
else use /your.host/ to match Regular expressions
identity_filter [identity] - Sets an identity filter
fact_filter [factname], [factvalue] - Sets a fact filter
class_filter [classname] - Sets a class filter
agent_filter [agentname] - Sets an agent filter
reset_filter - Resets to the filter to blank
print_filter - Displays current filter
Available Variables:
@agent_name - The name of the active agent
@agent - The active RPC client
Completions:
While doing an RPC request, press ?<tab> for a list of actions or
arguments, do simple :<tab> to get completion on action names and
arguments without description of each
"
true
end
mchelp()
click to toggle source
def mchelp
system("mc-rpc --agent-help #{@agent_name}|less")
true
end
newagent(agent)
click to toggle source
def newagent(agent)
@agent_name = agent
@options[:filter]["agent"] = []
@agent = rpcclient(@agent_name, :options => @options)
discover
@agent.progress = true
print_filter
end
print_filter()
click to toggle source
def print_filter
puts "Active Filter matched #{discover.size} hosts:"
puts "\tIdentity: #{@agent.filter['identity'].pretty_inspect}"
puts "\t Classes: #{@agent.filter['cf_class'].pretty_inspect}"
puts "\t Facts: #{@agent.filter['fact'].pretty_inspect}"
puts "\t Agents: #{@agent.filter['agent'].pretty_inspect}"
discover.size > 0 ? true : false
end
reset()
click to toggle source
def reset
@agent.reset
print_filter
end
reset_filter()
click to toggle source
def reset_filter
@agent.reset_filter
print_filter
end
rpc(method_name, *args) { |resp| ... }
click to toggle source
def rpc(method_name, *args, &block)
unless block_given?
if args.size > 0
args = args.first
else
args = {}
end
if args[:verbose]
args.delete(:verbose)
printrpc(@agent.send(method_name, args), :verbose => true)
printrpcstats
else
printrpc @agent.send(method_name, args)
printrpcstats
end
else
@agent.send(method_name, args.first).each do |resp|
yield resp
end
printrpcstats
end
true
rescue MCollective::DDLValidationError => e
puts "Request did not pass DDL validation: #{e}"
end
showhelp()
click to toggle source
def showhelp
puts("List of commands:")
puts("\n\t- subscribe /(topic|queue)/foo subscribes to topic of queue 'foo'")
puts("\t- /(topic|queue|/foo bar sends msg 'bar' to topic of queue 'foo'")
puts("\t- quit|exit|q|^d exit")
puts("\t- detail show/dont show time and topic a msg was received on")
puts("\t- help show this help")
end