The module that contains the default logic for invoking an external program to do the work of a Monitor.
Given one or more nodes
, return an Array of arguments that
should be appended to the external command.
# File lib/arborist/monitor.rb, line 56
def exec_arguments( nodes )
return []
end
Write the specified nodes
as serialized data to the given
io
.
# File lib/arborist/monitor.rb, line 62
def exec_input( nodes, io )
return if io.closed?
nodes.each do |(identifier, data)|
self.log.debug "Serializing node properties for %s" % [ identifier ]
prop_map = data.collect do |key, val|
val = val.join( ',' ) if val.is_a?( Array )
"%s=%s" % [ key, Shellwords.escape(val) ]
end
self.log.debug " writing %d properties to %p" % [ prop_map.size, io ]
io.puts "%s %s" % [ identifier, prop_map.join(' ') ]
self.log.debug " wrote the node to FD %d" % [ io.fileno ]
end
self.log.debug "done writing to FD %d" % [ io.fileno ]
end
Return the results of running the external command
# File lib/arborist/monitor.rb, line 82
def handle_results( pid, out, err )
err.flush
err.close
self.log.debug "Closed child's stderr."
# identifier key1=val1 key2=val2
results = out.each_line.with_object({}) do |line, accum|
identifier, attributes = line.split( ' ', 2 )
attrhash = Shellwords.shellsplit( attributes ).each_with_object({}) do |pair, hash|
key, val = pair.split( '=', 2 )
hash[ key ] = val
end
accum[ identifier ] = attrhash
end
out.close
self.log.debug "Waiting on PID %d" % [ pid ]
Process.waitpid( pid )
return results
end