aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-08-02 17:33:42 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-08-02 17:33:42 +0100
commit10141ed04af966ee280dcea1d733e0b036127afc (patch)
tree21dd6e4f4ece87288424fce7fdb866378c0edc5b /lib
parent25b32914b72a5f709eca773f3511cc89c2e710c2 (diff)
parentf07c5705d4ec82f4ba851409d4a92a9f66820df8 (diff)
merge
Diffstat (limited to 'lib')
-rw-r--r--lib/mauve/alert.rb18
-rw-r--r--lib/mauve/configuration_builders/logger.rb3
-rw-r--r--lib/mauve/mauve_time.rb2
-rw-r--r--lib/mauve/processor.rb6
-rw-r--r--lib/mauve/sender.rb2
-rw-r--r--lib/mauve/timer.rb2
-rw-r--r--lib/mauve/web_interface.rb6
7 files changed, 24 insertions, 15 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 6bde73a..027cc8c 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -91,7 +91,10 @@ module Mauve
end
alias to_s inspect
-
+
+ #
+ # This is to stop datamapper inserting duff dates into the database.
+ #
def check_dates
bad_dates = self.attributes.find_all do |key, value|
value.is_a?(DateTime) and not (DateTime.new(2000,1,1,0,0,0)..DateTime.new(2020,1,1,0,0,0)).include?(value)
@@ -225,8 +228,6 @@ module Mauve
end
end
- logger.info "#{self.inspect} updated." unless @attributes_before_save.empty?
-
true
end
@@ -296,6 +297,7 @@ module Mauve
raise! if (will_unacknowledge_at and will_unacknowledge_at.to_time <= MauveTime.now) or
(will_raise_at and will_raise_at.to_time <= MauveTime.now)
clear! if will_clear_at && will_clear_at.to_time <= MauveTime.now
+ logger.info("Polled #{self.inspect}")
end
@@ -388,13 +390,13 @@ module Mauve
#
# Receive an AlertUpdate buffer from the wire.
#
- def receive_update(update, reception_time = MauveTime.now)
+ def receive_update(update, reception_time = MauveTime.now, ip_source="network")
update = Proto::AlertUpdate.parse_from_string(update) unless update.kind_of?(Proto::AlertUpdate)
alerts_updated = []
- logger.debug("Alert update received from wire: #{update.inspect.split("\n").join(" ")}")
+ # logger.debug("Alert update received from wire: #{update.inspect.split("\n").join(" ")}")
#
# Transmission time helps us determine any time offset
@@ -508,6 +510,12 @@ module Mauve
else
alert_db.clear!
end
+
+ #
+ # Record the fact we received an update.
+ #
+ logger.info("Received update from #{ip_source} for #{alert_db.inspect}")
+
end
# If this is a complete replacement update, find the other alerts
diff --git a/lib/mauve/configuration_builders/logger.rb b/lib/mauve/configuration_builders/logger.rb
index a1d0388..3f60dfe 100644
--- a/lib/mauve/configuration_builders/logger.rb
+++ b/lib/mauve/configuration_builders/logger.rb
@@ -48,7 +48,7 @@ module Mauve
is_builder "outputter", LoggerOutputter
def builder_setup
- @result = Log4r::Logger.new('Mauve')
+ @result = Log4r::Logger['Mauve'] || Log4r::Logger.new('Mauve')
@default_format = nil
@default_level = Log4r::RootLogger.instance.level
end
@@ -92,6 +92,7 @@ module Mauve
end
result.outputters << outputter
+# result.outputter.write("Created logger")
end
end
end
diff --git a/lib/mauve/mauve_time.rb b/lib/mauve/mauve_time.rb
index 79fa4f3..812b0e2 100644
--- a/lib/mauve/mauve_time.rb
+++ b/lib/mauve/mauve_time.rb
@@ -21,7 +21,7 @@ class DateTime
end
def in_x_hours(*args)
- self.to_s_human(*args)
+ self.to_time.in_x_hours(*args)
end
end
diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb
index f5e8fac..059ca15 100644
--- a/lib/mauve/processor.rb
+++ b/lib/mauve/processor.rb
@@ -43,9 +43,9 @@ module Mauve
Timer.instance.freeze if Timer.instance.alive? and !Timer.instance.frozen?
- logger.debug("Got #{data.inspect} from #{client.inspect}")
+ # logger.debug("Got #{data.inspect} from #{client.inspect}")
- ip_source = "#{client[3]}:#{client[1]}"
+ ip_source = "#{client[3]}"
update = Proto::AlertUpdate.new
begin
@@ -62,7 +62,7 @@ module Mauve
logger.debug "Update #{update.transmission_id} sent at #{update.transmission_time} from "+
"'#{update.source}'@#{ip_source} alerts #{update.alert.length}"
- Alert.receive_update(update, received_at)
+ Alert.receive_update(update, received_at, ip_source)
rescue Protobuf::InvalidWireType,
NotImplementedError,
diff --git a/lib/mauve/sender.rb b/lib/mauve/sender.rb
index 8194180..ef06d0f 100644
--- a/lib/mauve/sender.rb
+++ b/lib/mauve/sender.rb
@@ -108,7 +108,7 @@ module Mauve
#
# Must have a source, so default to hostname if user doesn't care
- update.source ||= `hostname -f`.chomp
+ update.source ||= Socket.gethostname
#
# Make sure all alerts default to "-r now"
diff --git a/lib/mauve/timer.rb b/lib/mauve/timer.rb
index 8533451..1c8c37c 100644
--- a/lib/mauve/timer.rb
+++ b/lib/mauve/timer.rb
@@ -49,7 +49,7 @@ module Mauve
#
# La la la nothing to do.
#
- logger.info("Next to notify: #{next_to_notify} -- snoozing until #{next_to_notify.due_at}")
+ logger.info("Next to notify: #{next_to_notify} #{next_to_notify.is_a?(AlertChanged) ? "(reminder)" : "(heartbeat)"} -- snoozing until #{next_to_notify.due_at.iso8601}")
sleep_loops = ((next_to_notify.due_at - MauveTime.now).to_f / 0.1).round.to_i
end
diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb
index 4bb9517..9369ee3 100644
--- a/lib/mauve/web_interface.rb
+++ b/lib/mauve/web_interface.rb
@@ -103,11 +103,12 @@ EOF
# Uh-oh.. Intruder alert!
#
ok_urls = %w(/ /login /logout)
+ no_redirect_urls = %w(/ajax)
unless ok_urls.include?(request.path_info)
flash['error'] = "You must be logged in to access that page."
status 403
- redirect "/login?next_page=#{request.path_info}"
+ redirect "/login?next_page=#{request.path_info}" unless no_redirect_urls.any?{|u| /^#{u}/ =~ request.path_info }
end
end
end
@@ -230,7 +231,7 @@ EOF
end
end
- flash["errors"] = "Failed to acknowledge #{failed.length} alerts." if failed.length > 0
+ flash["error"] = "Failed to acknowledge #{failed.length} alerts." if failed.length > 0
flash["notice"] = "Successfully acknowledged #{succeeded.length} alerts" if succeeded.length > 0
redirect "/alerts/raised"
@@ -267,7 +268,6 @@ EOF
get '/ajax/time_to_s_human/:seconds' do
content_type :text
-
secs = params[:seconds].to_i
Time.at(secs).to_s_human
end