Sha256: 9c0fe6a0e6512bd34215a23ebddaa773c63aa6fd35a876209469c41ea2e26d21

Contents?: true

Size: 1.51 KB

Versions: 5

Compression:

Stored size: 1.51 KB

Contents

# -*- ruby -*-
#encoding: utf-8

require 'loggability'
require 'arborist/monitor'
require 'arborist/mixins'

using Arborist::TimeRefinements

module FPingWrapper
	extend Loggability
	log_to :arborist

	attr_accessor :identifiers

	def exec_arguments( nodes )
		self.log.debug "Building fping arguments 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?

		return self.identifiers.keys
	end

	def handle_results( pid, stdout, stderr )
		# 8.8.8.8 is alive (32.1 ms)
		# 8.8.4.4 is alive (14.9 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

			self.log.debug "  parsing result for %s(%s): %p" % [ identifier, address, remainder ]

			if remainder =~ /is alive \((\d+\.\d+) ms\)/
				hash[ identifier ] = { rtt: Float( $1 ) }
			else
				hash[ identifier ] = { error: remainder.chomp }
			end
		end
	end

end


Arborist::Monitor 'ping check' do
	every 20.seconds
	splay 5.seconds
	match type: 'host'
	exclude tag: :laptop
	use :addresses

	exec 'fping', '-e', '-t', '150'
	exec_callbacks( FPingWrapper )
end

Arborist::Monitor 'transient host pings' do
	every 5.minutes
	match type: 'host', tag: 'laptop'
	use :addresses

	exec 'fping', '-e', '-t', '500'
	exec_callbacks( FPingWrapper )
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arborist-0.6.0 spec/data/monitors/pings.rb
arborist-0.5.0 spec/data/monitors/pings.rb
arborist-0.4.0 spec/data/monitors/pings.rb
arborist-0.3.0 spec/data/monitors/pings.rb
arborist-0.2.0 spec/data/monitors/pings.rb