3 # Simple IRB shell for mcollective
6 # Determining the amount of hosts matching filter for 2 seconds .... 47
7 # >> rpc :runcommand, :command => "check_disks"
9 # * [ ============================================================> ] 47 / 47
12 # dev1.your.net Request Aborted
14 # Output: DISK CRITICAL - free space: / 176 MB (4% inode=86%);
16 # Performance Data: /=3959MB;3706;3924;0;4361 /boot=26MB;83;88;0;98 /dev/shm=0MB;217;230;0;256
20 # <shows the DDL based help for the chosen agent>
22 # >> rpc(:runcommand, :command => "check_disks") do |resp|
23 # ?> puts resp[:sender] + ": " + resp[:data][:output]
26 # * [ ============================================================> ] 47 / 47
28 # dev1.your.net: DISK OK
33 # You can access the agent variable via @agent from where you can do the usual manipulation of filters etc,
34 # if you wish to switch to a different agent mid run just do newagent("some_other_agent")
36 # If you install the Bond gem you'll get some DDL assisted completion in the rpc method
45 IRB.conf[:MAIN_CONTEXT] = irb.context
46 irb.context.evaluate("require 'irb/completion'", 0)
52 Bond.complete(:method => "rpc") do |e|
55 if e.arguments.last == "?"
56 puts "\n\nActions for #{@agent_name}:\n"
58 @agent.ddl.actions.each do |action|
59 puts "%20s - %s" % [ ":#{action}", @agent.ddl.action_interface(action)[:description] ]
68 action = eval(e.arguments[0]).to_s
69 ddl = @agent.ddl.action_interface(action)
71 if e.arguments.last == "?"
72 puts "\n\nArguments for #{action}:\n"
73 ddl[:input].keys.each do |input|
74 puts "%20s - %s" % [ ":#{input}", ddl[:input][input][:description] ]
80 [ddl[:input].keys, :verbose].flatten
98 system("mc-rpc --agent-help #{@agent_name}|less")
102 def rpc(method_name, *args, &block)
111 args.delete(:verbose)
113 printrpc(@agent.send(method_name, args), :verbose => true)
116 printrpc @agent.send(method_name, args)
121 @agent.send(method_name, args.first).each do |resp|
129 rescue MCollective::DDLValidationError => e
130 puts "Request did not pass DDL validation: #{e}"
134 puts "Active Filter matched #{discover.size} hosts:"
135 puts "\tIdentity: #{@agent.filter['identity'].pretty_inspect}"
136 puts "\t Classes: #{@agent.filter['cf_class'].pretty_inspect}"
137 puts "\t Facts: #{@agent.filter['fact'].pretty_inspect}"
138 puts "\t Agents: #{@agent.filter['agent'].pretty_inspect}"
140 discover.size > 0 ? true : false
146 @options[:filter]["agent"] = []
147 @agent = rpcclient(@agent_name, :options => @options)
151 @agent.progress = true
156 def identity_filter(*args)
157 @agent.identity_filter(*args)
162 def fact_filter(*args)
163 @agent.fact_filter(*args)
168 def agent_filter(*args)
169 @agent.agent_filter(*args)
174 def class_filter(*args)
175 @agent.class_filter(*args)
200 rpc - Performs an RPC request
201 reset - Resets the discovered knowledge
202 discover - Performs a new discovery showing
204 newagent - Switches to a new agent
205 mchelp - The DDL created help for the agent
208 Filter arguments should be enclosed in "your.host.com" if they are strings
209 else use /your.host/ to match Regular expressions
211 identity_filter [identity] - Sets an identity filter
212 fact_filter [factname], [factvalue] - Sets a fact filter
213 class_filter [classname] - Sets a class filter
214 agent_filter [agentname] - Sets an agent filter
215 reset_filter - Resets to the filter to blank
216 print_filter - Displays current filter
220 @agent_name - The name of the active agent
221 @agent - The active RPC client
225 While doing an RPC request, press ?<tab> for a list of actions or
226 arguments, do simple :<tab> to get completion on action names and
227 arguments without description of each
234 require 'mcollective'
237 include MCollective::RPC
239 @options = rpcoptions
241 unless ARGV.size == 1
242 puts "Please specify an agent name on the command line"
246 puts "The Marionette Collective Interactive Ruby Shell version #{MCollective.version}"
251 puts "Use mc? to get help on using this shell"