module Arborist::Monitor::FPing
Parse Fping output for better batch ICMP checks.
Constants
- USED_PROPERTIES
Always request the node addresses.
- VERSION
The version of this library.
Attributes
identifiers[RW]
Public Class Methods
node_properties()
click to toggle source
Return the properties used by this monitor.
# File lib/arborist/monitor/fping.rb, line 34 def self::node_properties return USED_PROPERTIES end
Public Instance Methods
exec_input( nodes, io )
click to toggle source
Arborist::Monitor
API: Send addresses to the fping binary, after creating a map to re-associate them back to identifiers.
# File lib/arborist/monitor/fping.rb, line 43 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 end return if self.identifiers.empty? self.identifiers.keys.each{|ip| io.puts(ip) } end
handle_results( pid, stdout, stderr )
click to toggle source
Parse fping output, return a hash of RTT data, along with any detected errors.
# File lib/arborist/monitor/fping.rb, line 60 def handle_results( pid, stdout, stderr ) # 8.8.8.8 is alive (32.1 ms) # 8.8.4.4 is alive (14.9 ms) # 1.1.1.1 is alive (236 ms) # 8.8.0.1 is unreachable return stdout.each_line.with_object({}) do |line, hash| address, remainder = line.split( ' ', 2 ) identifier = self.identifiers[ address ] or next if remainder =~ /is alive \((\d+(?:\.\d+)?) ms\)/ hash[ identifier ] = { rtt: Float( $1 ) } else hash[ identifier ] = { error: remainder.chomp } end end end