Daniel said:
gem install net-ping
Regards,
Dan
Hi all,
thanks for your input.
Here the script which checks packet loss and sends me an e-mail:
#!/usr/bin/ruby
#
#
#
require "net/ping"
include Net
require 'socket'
include Socket::Constants
require 'daemons'
include Daemonize
require 'action_mailer'
# all for mailing requirementsActionMailer::Base.sendmail_settings = {
:address => 'mailhostXYZ',
ActionMailer::Base.sendmail_settings = { :address => 'mailhostXYZ',
ort
=> 25 }
@RecipientAddress = '(e-mail address removed)'
class SimpleMailer < ActionMailer::Base
def simple_message(recipient)
from '(e-mail address removed)'
recipients recipient
subject 'Packet loss detected'
body $Message
end
end
daemonize()
ip_list = [ '192.168.1.1' , '192.168.1.2' , '192.168.1.3' ,
'192.168.1.4' , '192.168.1.5' , '192.168.1.6' , '192.168.1.7' ,
'192.168.1.8' ]
#total_networks_to_check = ip_list.size
#puts ip_list.size
loop do
begin
amount_of_pings = 10
PingTCP.econnrefused = true
ip_list.each_with_index do |item, index|
counter_positive = 0
counter_negative = 10
10.times do
pe = Net:
ingExternal.new("#{item}")
if pe.ping
#puts "External ping successful"
counter_positive = counter_positive + 1
#puts 'counter_positive ' + counter_positive.to_s
else
counter_negative = counter_negative - 1
#puts 'counter_negative ' + counter_negative.to_s
end
end
#if counter_negative > 0
success_rate = (100 * counter_positive) /
amount_of_pings
#puts 'success_rate = ' + success_rate.to_s
packet_loss = 100 - success_rate
if packet_loss > 0
$Message = packet_loss.to_s + '\% packet loss
for ' + "#{item}"
SimpleMailer.deliver_simple_message(@RecipientAddress)
#puts 'packet_loss = ' + packet_loss.to_s
else
success_rate = 0
end
#end
end
end
sleep 60
end
I had to delete some sensitive data, but this should basically work for
everyone.
bye
Henry