Sha256: 5e88ad7cf5d2bc3b5d580a1e64fb40c2f0c1e06752913eb6d17e2ae6368fe452

Contents?: true

Size: 1.17 KB

Versions: 10

Compression:

Stored size: 1.17 KB

Contents

#!/usr/bin/env ruby

require 'mcollective'
require 'pp'

oparser = MCollective::Optionparser.new({:verbose => true}, "filter")

options = oparser.parse{|parser, options|
  parser.define_head "Call an agent parsing an argument to it"
  parser.banner = "Usage: mc-call-agent [options] --agent agent --argument arg"

  parser.on('-a', '--agent AGENT', 'Agent to call') do |v|
    options[:agent] = v
  end

  parser.on('--arg', '--argument ARGUMENT', 'Argument to pass to agent') do |v|
    options[:argument] = v
  end
}

if options[:agent] == nil || options[:argument] == nil
  puts("Please use either --agent or --argument")
  exit 1
end

begin
  options[:filter]["agent"] << options[:agent]

  client = MCollective::Client.new(options[:config])
  client.options = options

  c = 0

  stats = client.discovered_req(options[:argument], options[:agent]) do |resp|
    next if resp == nil

    c += 1

    if options[:verbose]
      puts("#{resp[:senderid]}>")
      pp resp[:body]
    else
      puts if c % 4 == 1
      printf("%-30s", resp[:senderid])
    end
  end

  client.disconnect
rescue Exception => e
  STDERR.puts "Could not call remote agent: #{e}"
  exit 1
end

client.display_stats(stats)

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mcollective-client-2.5.0 bin/mc-call-agent
mcollective-client-2.5.0.rc1 bin/mc-call-agent
mcollective-client-2.4.1 bin/mc-call-agent
mcollective-client-2.4.0 bin/mc-call-agent
mcollective-client-2.2.4 bin/mc-call-agent
mcollective-client-2.2.3 bin/mc-call-agent
mcollective-client-2.2.2 bin/mc-call-agent
mcollective-client-2.2.1 bin/mc-call-agent
mcollective-client-2.2.0 bin/mc-call-agent
mcollective-client-2.0.0 bin/mc-call-agent