Skip to content

Instantly share code, notes, and snippets.

@maguec
Created April 13, 2012 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maguec/2380442 to your computer and use it in GitHub Desktop.
Save maguec/2380442 to your computer and use it in GitHub Desktop.
simple agent wrapping a command
module MCollective
module Agent
class Wrapit < RPC::Agent
#####################################################################################
metadata :name => "My Agent",
:description => "Example of how to wrap a command",
:author => "Me <me@example.com>",
:license => "DWYWI",
:version => "0.1",
:url => "http://blog.mague.com",
:timeout => 10
#####################################################################################
#functions
def run_command(cmd)
cmdrun = IO.popen(cmd)
output = cmdrun.read
cmdrun.close
if $?.to_i > 0
logger.error "MOOVDIAG: #{cmd}: #{output}"
reply.fail! "ERROR: failed with #{output}"
end
output
end
#####################################################################################
#actions
action "ping" do
reply[:info] = run_command("/bin/ping -c 5 #{request[:target]}")
end
#####################################################################################
end #class
end #agent
end #module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment