aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-06-16 11:10:07 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-06-16 11:10:07 +0100
commitaddb611276f434c261391832616b8e576e9fd84b (patch)
treee51f96ff9a0753c628db2a65dbf87fe3f8d8ce21
parent8da31cd2258c9516c91189595bdb467a93f5aebd (diff)
* More IPv6 tidying.
* Fixed typo in Processor
-rwxr-xr-xbytemark_example_alerts.sh2
-rw-r--r--lib/mauve/processor.rb2
-rw-r--r--lib/mauve/sender.rb39
3 files changed, 27 insertions, 16 deletions
diff --git a/bytemark_example_alerts.sh b/bytemark_example_alerts.sh
index faaa833..7d05583 100755
--- a/bytemark_example_alerts.sh
+++ b/bytemark_example_alerts.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-PRE="ruby -I lib ./bin/mauveclient 127.0.0.1"
+PRE="ruby -I lib ./bin/mauveclient localhost"
$PRE -o supportbot -i 173123 \
-s "My server is not responding" \
diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb
index 86aaaec..9a5c84b 100644
--- a/lib/mauve/processor.rb
+++ b/lib/mauve/processor.rb
@@ -48,7 +48,7 @@ module Mauve
update.parse_from_string(data)
if @transmission_id_cache[update.transmission_id.to_s]
- @logger.debug("Ignoring duplicate transmission id #{data.transmission_id}")
+ @logger.debug("Ignoring duplicate transmission id #{update.transmission_id}")
#
# Continue with next packet.
#
diff --git a/lib/mauve/sender.rb b/lib/mauve/sender.rb
index 6abe44d..0a481d5 100644
--- a/lib/mauve/sender.rb
+++ b/lib/mauve/sender.rb
@@ -70,21 +70,20 @@ module Mauve
list.each do |d,p|
r = []
+ #
+ # Try IPv6 first.
+ #
+ dns.getresources(d, AAAA).map do |a|
+ r << [a.address.to_s, p]
+ end
#
- # Try IPv4 first.
+ # Try IPv4 too.
#
dns.getresources(d, A).each do |a|
r << [a.address.to_s, p]
end
- #
- # Try IPv6 too.
- #
- dns.getresources(d, AAAA).map do |a|
- r << [a.address.to_s, p]
- end
-
results += r unless r.empty?
end
end
@@ -102,7 +101,10 @@ module Mauve
end
end
-
+
+ #
+ # Returns the number of packets sent.
+ #
def send(update, verbose=0)
#
@@ -131,15 +133,24 @@ module Mauve
print "Sending #{update.inspect.chomp} to #{@destinations.join(", ")}\n"
end
+ #
+ # Keep a count of the number of alerts sent.
+ #
+ sent = 0
+
@destinations.each do |ip, port|
begin
- UDPSocket.open(ip.family) do |sock|
- sock.send(data, 0, ip.to_s, port)
- end
- rescue StandardError => ex
- warn "Got #{ex.to_s} whilst trying to send to #{ip} #{port}"
+ UDPSocket.open(ip.family).send(data, 0, ip.to_s, port)
+ sent += 1
+ rescue Errno::ENETUNREACH => ex
+ # Catch and ignore unreachable network errors.
+ warn "Got #{ex.to_s} whilst trying to send to #{ip} #{port}" if verbose > 0
end
end
+
+ raise "Failed to send any packets to any destinations!" unless sent > 0
+
+ sent
end
end
end