Created
April 13, 2012 22:04
-
-
Save maguec/2380442 to your computer and use it in GitHub Desktop.
simple agent wrapping a command
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
module MCollective | |
module Agent | |
class Wrapit < RPC::Agent | |
##################################################################################### | |
metadata :name => "My Agent", | |
:description => "Example of how to wrap a command", | |
:author => "Me <[email protected]>", | |
: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