# HG changeset patch # User Mahlon E. Smith # Date 1522186051 25200 # Node ID 6cf2c60c80f77396bd4fc8cfebc216d5d33d141e # Parent 1801334b8dc4e478fb895fd321973e96cd9b10a5 Provide fping addresses via pipe, instead of an argument list. #exec_arguments defaults to a no-op, but #exec_input does not. This means that exec_callbacks modules that do no use #exec_input need to define a no-op themselves, as the default will still try to write data to stdin. (This may be addressed in the monitor at some point, it is a bit of a gotcha.) Rather than define an empty #exec_input method, make a functional one, and remove #exec_arguments. This will fare better if the input list is excessively long anyway, and it fixes Error::EPIPE. diff -r 1801334b8dc4 -r 6cf2c60c80f7 lib/arborist/monitor/fping.rb --- a/lib/arborist/monitor/fping.rb Thu Mar 22 13:52:07 2018 -0700 +++ b/lib/arborist/monitor/fping.rb Tue Mar 27 14:27:31 2018 -0700 @@ -26,7 +26,7 @@ log_to :arborist # The version of this library. - VERSION = '0.1.1' + VERSION = '0.2.0' # Always request the node addresses. USED_PROPERTIES = [ :addresses ].freeze @@ -38,18 +38,27 @@ attr_accessor :identifiers - def exec_arguments( nodes ) - self.log.debug "Building fping arguments for %d nodes" % [ nodes.size ] + ### Arborist::Monitor API: Send addresses to the fping binary, after + ### creating a map to re-associate them back to identifiers. + ### + def exec_input( nodes, io ) + self.log.debug "Building fping input for %d nodes" % [ nodes.size ] self.identifiers = nodes.each_with_object({}) do |(identifier, props), hash| next unless props.key?( 'addresses' ) address = props[ 'addresses' ].first hash[ address ] = identifier + self.log.debug "%s -> %s" % [ identifier, address ] end - return {} if self.identifiers.empty? - return self.identifiers.keys + return if self.identifiers.empty? + + self.identifiers.keys.each{|ip| io.puts(ip) } end + + ### Parse fping output, return a hash of RTT data, along + ### with any detected errors. + ### def handle_results( pid, stdout, stderr ) # 8.8.8.8 is alive (32.1 ms) # 8.8.4.4 is alive (14.9 ms)