Sha256: 4969c778055e4f3f857228c4c29ddb687f72cc32590e099f3b39e094a9fb9c30

Contents?: true

Size: 1.73 KB

Versions: 7

Compression:

Stored size: 1.73 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 'ping check downed hosts' do
	every 40.seconds
	splay 15.seconds
	match type: 'host', status: 'down'
	include_down true
	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

7 entries across 7 versions & 1 rubygems

Version Path
arborist-0.2.0.pre20170519125456 spec/data/monitors/pings.rb
arborist-0.1.0 spec/data/monitors/pings.rb
arborist-0.0.1.pre20161005182540 spec/data/monitors/pings.rb
arborist-0.0.1.pre20161005112841 spec/data/monitors/pings.rb
arborist-0.0.1.pre20160829140603 spec/data/monitors/pings.rb
arborist-0.0.1.pre20160606141735 spec/data/monitors/pings.rb
arborist-0.0.1.pre20160128152542 spec/data/monitors/pings.rb