aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/heartbeat.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-07-20 16:16:14 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-07-20 16:16:14 +0100
commit3185e5d746abda1b7f42ecdbd74ec14359fda3bc (patch)
treee74ee3a587d62fdf68f79093af2202188aed3bc5 /lib/mauve/heartbeat.rb
parent4ffe222986d4e3565a1f189325d77b33f90dfa15 (diff)
parentd3a3cfef9650b08f62db62bd7e86b673f9d77d0b (diff)
merge
Diffstat (limited to 'lib/mauve/heartbeat.rb')
-rw-r--r--lib/mauve/heartbeat.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/mauve/heartbeat.rb b/lib/mauve/heartbeat.rb
new file mode 100644
index 0000000..0f51f80
--- /dev/null
+++ b/lib/mauve/heartbeat.rb
@@ -0,0 +1,64 @@
+require 'mauve/sender'
+require 'mauve/proto'
+require 'mauve/mauve_thread'
+require 'log4r'
+
+#
+# This class is responsible for sending a heartbeat to another mauve instance elsewhere.
+#
+module Mauve
+
+ class Heartbeat < MauveThread
+
+ include Singleton
+
+ attr_accessor :destination, :summary, :detail
+ attr_reader :sleep_interval, :raise_at
+
+ def initialize
+ super
+
+ @destination = nil
+ @summary = "Mauve alert server down."
+ @detail = "The Mauve server at #{Server.instance.hostname} has failed to send a heartbeat."
+ self.raise_at = 600
+ end
+
+ def raise_at=(i)
+ @raise_at = i
+ @sleep_interval = ((i.to_f)/2.5).round.to_i
+ end
+
+ def logger
+ @logger ||= Log4r::Logger.new(self.class.to_s)
+ end
+
+ def main_loop
+ #
+ # Don't send if no destination set.
+ #
+ return if @destination.nil?
+
+ update = Mauve::Proto::AlertUpdate.new
+ update.replace = false
+ update.alert = []
+ update.source = Server.instance.hostname
+ update.transmission_id = rand(2**63)
+
+ message = Mauve::Proto::Alert.new
+ message.id = "mauve-heartbeat"
+ message.summary = self.summary
+ message.detail = self.detail
+ message.raise_time = (MauveTime.now.to_f+self.raise_at).to_i
+ message.clear_time = MauveTime.now.to_i
+
+ update.alert << message
+
+ Mauve::Sender.new(self.destination).send(update)
+ end
+
+ end
+
+end
+
+