aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-07-14 14:50:22 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-07-14 14:50:22 +0100
commit494b083408b354f38da9b1fc5e8ffb7238d009b3 (patch)
tree4a9122f13b4f36840a2223616b41e3608ae9ba4f /lib/mauve
parente07cea09e884607d6ad005f5e2822251ca31b9ba (diff)
Fixed mauveclient to obey time multipliers
Fixed logrotate script to rotate the correct script Init script now uses the correct user lib/mauve/history.rb is now installed Further logging cleanups
Diffstat (limited to 'lib/mauve')
-rw-r--r--lib/mauve/alert.rb26
-rw-r--r--lib/mauve/person.rb27
-rw-r--r--lib/mauve/processor.rb10
-rw-r--r--lib/mauve/udp_server.rb5
4 files changed, 34 insertions, 34 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 147c7cb..07aeb55 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -162,9 +162,9 @@ module Mauve
# This allows us to take a copy of the changes before we save.
#
def take_copy_of_changes
- @changes_before_save = Hash.new
+ @attributes_before_save = Hash.new
self.original_attributes.each do |k,v|
- @changes_before_save[k.name] = v
+ @attributes_before_save[k.name] = v
end
end
@@ -175,25 +175,30 @@ module Mauve
#
# Make sure we don't barf
#
- @changes_before_save ||= Hash.new
+ @attributes_before_save ||= Hash.new
- is_a_change = [:subject, :summary].any?{|k| @changes_before_save.keys.include?(k)}
+ is_a_new_alert = @attributes_before_save.values.all?{|a| a.nil?}
+ #
+ # Do not alert about changes, for now.
+ #
+ is_a_change = false # [:subject, :summary].any?{|k| @attributes_before_save.keys.include?(k)}
#
- # We notify if the update type has changed, or if the update type is
+ # We notify if the update type has changed (but not from nil), or if the update type is
# "raised", and the above is_a_change condition is true
#
- if @changes_before_save.has_key?(:update_type) or (self.update_type == "raised" and is_a_change)
+ if (@attributes_before_save.has_key?(:update_type) and !is_a_new_alert) or
+ (self.update_type == "raised" and (is_a_new_alert or is_a_change))
self.notify
h = History.new(:alert_id => self.id, :type => "update")
if self.update_type == "acknowledged"
- h.event = "ACKNOWLEDGED by #{self.acknowledged_by} until #{self.will_unacknowledge_at}"
+ h.event = "ACKNOWLEDGED by #{self.acknowledged_by} until #{self.will_unacknowledge_at}"
elsif is_a_change
h.event = "CHANGED: "
- h.event += @changes_before_save.keys.collect{|k| "#{k.to_s}: #{@changes_before_save[k]} -> #{self.__send__(k)}"}.join(", ")
+ h.event += @attributes_before_save.keys.collect{|k| "#{k.to_s}: #{@attributes_before_save[k]} -> #{self.__send__(k)}"}.join(", ")
else
h.event = self.update_type.upcase
@@ -473,11 +478,6 @@ module Mauve
alert_db.importance = alert.importance if alert.importance != 0
- #
- # This will probably get overwritten below.
- #
- # alert_db.update_type = "changed" unless alert_db.update_type
-
alert_db.updated_at = reception_time
if alert_db.raised?
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb
index cf29ff9..199bc23 100644
--- a/lib/mauve/person.rb
+++ b/lib/mauve/person.rb
@@ -24,11 +24,10 @@ module Mauve
#
class NotificationCaller
- def initialize(person, alert, other_alerts, notification_methods, base_conditions={})
+ def initialize(person, alert, other_alerts, base_conditions={})
@person = person
@alert = alert
@other_alerts = other_alerts
- @notification_methods = notification_methods
@base_conditions = base_conditions
end
@@ -66,7 +65,7 @@ module Mauve
#
# Log the result
- note = "#{@alert.update_type.upcase}: notification " + (res ? "succeeded" : "failed" ) + " for #{@person.username} using notifier '#{name}' to '#{destination}'."
+ note = "#{@alert.update_type.capitalize} #{name} notification to #{@person.username} (#{destination}) " + (res ? "succeeded" : "failed" )
logger.info note
h = History.new(:alert_id => @alert.id, :type => "notification", :event => note)
logger.error "Unable to save history due to #{h.errors.inspect}" if !h.save
@@ -155,6 +154,10 @@ module Mauve
# This just wraps send_alert by sending the job to a queue.
#
def send_alert(level, alert)
+ Server.notification_push([self, level, alert])
+ end
+
+ def do_send_alert(level, alert)
now = MauveTime.now
threshold_breached = @notification_thresholds.any? do |period, previous_alert_times|
@@ -162,15 +165,15 @@ module Mauve
first.is_a?(MauveTime) and (now - first) < period
end
- was_suppressed = self.suppressed?
+ was_suppressed = self.suppressed?
if Server.instance.started_at > alert.updated_at.to_time and (Server.instance.started_at + Server.instance.initial_sleep) > MauveTime.now
logger.info("Alert last updated in prior run of mauve -- ignoring for initial sleep period.")
- return
+ return true
end
if threshold_breached
- logger.info("Suspending notifications to #{username} until further notice.") unless was_suppressed
+ logger.info("Suspending further notifications to #{username} until further notice.") unless was_suppressed
@suppressed = true
else
@@ -183,18 +186,14 @@ module Mauve
# We only suppress notifications if we were suppressed before we started,
# and are still suppressed.
#
- return if was_suppressed and self.suppressed?
-
- Server.notification_push([self, level, alert, was_suppressed])
- end
+ return true if was_suppressed and self.suppressed?
- def do_send_alert(level, alert, was_suppressed)
result = NotificationCaller.new(
self,
alert,
current_alerts,
- Configuration.current.notification_methods,
- :was_suppressed => was_suppressed
+ {:is_suppressed => @suppressed,
+ :was_suppressed => was_suppressed, }
).instance_eval(&__send__(level))
if result
@@ -209,8 +208,10 @@ module Mauve
@notification_thresholds[period].shift
end
true
+
else
false
+
end
end
diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb
index a1c0896..f8416e0 100644
--- a/lib/mauve/processor.rb
+++ b/lib/mauve/processor.rb
@@ -25,10 +25,10 @@ module Mauve
end
def main_loop
- #
- # Only do the loop a maximum of 10 times every @sleep_interval seconds
- #
- 10.times do
+
+ sz = Server.packet_buffer_size
+
+ sz.times do
data, client, received_at = Server.packet_pop
#
@@ -47,7 +47,7 @@ module Mauve
update.parse_from_string(data)
if @transmission_id_cache[update.transmission_id.to_s]
- logger.info("Ignoring duplicate transmission id #{update.transmission_id}")
+ logger.debug("Ignoring duplicate transmission id #{update.transmission_id}")
#
# Continue with next packet.
#
diff --git a/lib/mauve/udp_server.rb b/lib/mauve/udp_server.rb
index 8649efe..049ea09 100644
--- a/lib/mauve/udp_server.rb
+++ b/lib/mauve/udp_server.rb
@@ -50,7 +50,7 @@ module Mauve
@socket.bind(@ip, @port)
- logger.info("Successfully opened UDP socket on #{@ip}:#{@port}")
+ logger.info("Opened socket on #{@ip}:#{@port}")
end
def close_socket
@@ -64,7 +64,7 @@ module Mauve
logger.debug ex.backtrace.join("\n")
end
- logger.info("Successfully closed UDP socket")
+ logger.info("Closed socket")
end
def main_loop
@@ -83,7 +83,6 @@ module Mauve
packet = @socket.recvfrom(65535)
received_at = MauveTime.now
rescue Errno::EAGAIN, Errno::EWOULDBLOCK => ex
- puts "#{i += 1} + #{ex}"
IO.select([@socket])
retry unless self.should_stop?
end