lib/arborist/monitor/fping.rb
changeset 5 6cf2c60c80f7
parent 4 1801334b8dc4
child 6 f82534b40e06
equal deleted inserted replaced
4:1801334b8dc4 5:6cf2c60c80f7
    24 module Arborist::Monitor::FPing
    24 module Arborist::Monitor::FPing
    25 	extend Loggability
    25 	extend Loggability
    26 	log_to :arborist
    26 	log_to :arborist
    27 
    27 
    28 	# The version of this library.
    28 	# The version of this library.
    29 	VERSION = '0.1.1'
    29 	VERSION = '0.2.0'
    30 
    30 
    31 	# Always request the node addresses.
    31 	# Always request the node addresses.
    32 	USED_PROPERTIES = [ :addresses ].freeze
    32 	USED_PROPERTIES = [ :addresses ].freeze
    33 
    33 
    34 	### Return the properties used by this monitor.
    34 	### Return the properties used by this monitor.
    36 		return USED_PROPERTIES
    36 		return USED_PROPERTIES
    37 	end
    37 	end
    38 
    38 
    39 	attr_accessor :identifiers
    39 	attr_accessor :identifiers
    40 
    40 
    41 	def exec_arguments( nodes )
    41 	### Arborist::Monitor API: Send addresses to the fping binary, after
    42 		self.log.debug "Building fping arguments for %d nodes" % [ nodes.size ]
    42 	### creating a map to re-associate them back to identifiers.
       
    43 	###
       
    44 	def exec_input( nodes, io )
       
    45 		self.log.debug "Building fping input for %d nodes" % [ nodes.size ]
    43 		self.identifiers = nodes.each_with_object({}) do |(identifier, props), hash|
    46 		self.identifiers = nodes.each_with_object({}) do |(identifier, props), hash|
    44 			next unless props.key?( 'addresses' )
    47 			next unless props.key?( 'addresses' )
    45 			address = props[ 'addresses' ].first
    48 			address = props[ 'addresses' ].first
    46 			hash[ address ] = identifier
    49 			hash[ address ] = identifier
       
    50 			self.log.debug "%s -> %s" % [ identifier, address ]
    47 		end
    51 		end
    48 
    52 
    49 		return {} if self.identifiers.empty?
    53 		return if self.identifiers.empty?
    50 		return self.identifiers.keys
    54 
       
    55 		self.identifiers.keys.each{|ip| io.puts(ip) }
    51 	end
    56 	end
    52 
    57 
       
    58 
       
    59 	### Parse fping output, return a hash of RTT data, along
       
    60 	### with any detected errors.
       
    61 	###
    53 	def handle_results( pid, stdout, stderr )
    62 	def handle_results( pid, stdout, stderr )
    54 		# 8.8.8.8 is alive (32.1 ms)
    63 		# 8.8.8.8 is alive (32.1 ms)
    55 		# 8.8.4.4 is alive (14.9 ms)
    64 		# 8.8.4.4 is alive (14.9 ms)
    56 		# 8.8.0.1 is unreachable
    65 		# 8.8.0.1 is unreachable
    57 
    66