aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-04-27 10:58:36 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-04-27 10:58:36 +0100
commit5ad5aea6512f43a06e720d0b8e0fbf405d532dca (patch)
tree12d91d81962bf32972ddd6097c815e2ccdad9cd3
parent050d56934033c1cb1c2a6e613c706e3415acbd53 (diff)
Added default configuration options for a person.
-rw-r--r--lib/mauve/configuration_builders/person.rb23
-rw-r--r--lib/mauve/person.rb29
-rw-r--r--test/tc_mauve_configuration_builders_person.rb24
3 files changed, 63 insertions, 13 deletions
diff --git a/lib/mauve/configuration_builders/person.rb b/lib/mauve/configuration_builders/person.rb
index 7a20491..afb967b 100644
--- a/lib/mauve/configuration_builders/person.rb
+++ b/lib/mauve/configuration_builders/person.rb
@@ -72,10 +72,31 @@ module Mauve
def created_person(person)
name = person.username
raise ArgumentError.new("Duplicate person '#{name}'") if @result.people[name]
+
#
# Add a default notification threshold
#
- person.notification_thresholds[60] = Array.new(10) if person.notification_thresholds.empty?
+ person.notification_thresholds[600] = Array.new(5) if person.notification_thresholds.empty?
+
+ #
+ # Add a default notify clause
+ #
+ if person.notifications.empty?
+ default_notification = Notification.new(person)
+ default_notification.every = 30.minutes
+ default_notification.during = lambda { working_hours? }
+ person.notifications << default_notification
+ end
+
+ #
+ # Set up some default notify levels.
+ #
+ if person.urgent.nil? and person.normal.nil? and person.low.nil?
+ person.urgent = lambda { sms ; xmpp ; email }
+ person.normal = lambda { xmpp ; email }
+ person.low = lambda { email }
+ end
+
@result.people[person.username] = person
end
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb
index 929f511..9ea36f7 100644
--- a/lib/mauve/person.rb
+++ b/lib/mauve/person.rb
@@ -22,10 +22,8 @@ module Mauve
@username = username
@password = nil
- @urgent = lambda { false }
- @normal = lambda { false }
- @low = lambda { false }
- @email = @sms = @xmpp = nil
+ @urgent = @normal = @low = nil
+ @email = @sms = @xmpp = nil
@notify_when_on_holiday = @notify_when_off_sick = false
end
@@ -240,14 +238,21 @@ module Mauve
return true
end
- result = NotificationCaller.new(
- self,
- alert,
- [],
- # current_alerts,
- {:will_suppress => will_suppress,
- :was_suppressed => was_suppressed, }
- ).instance_eval(&__send__(level))
+ result = false
+
+ #
+ # Make sure the level we want has been defined as a Proc.
+ #
+ if __send__(level).is_a?(Proc)
+ result = NotificationCaller.new(
+ self,
+ alert,
+ [],
+ # current_alerts,
+ {:will_suppress => will_suppress,
+ :was_suppressed => was_suppressed, }
+ ).instance_eval(&__send__(level))
+ end
if [result].flatten.any?
#
diff --git a/test/tc_mauve_configuration_builders_person.rb b/test/tc_mauve_configuration_builders_person.rb
index d889a03..6ee3d13 100644
--- a/test/tc_mauve_configuration_builders_person.rb
+++ b/test/tc_mauve_configuration_builders_person.rb
@@ -39,4 +39,28 @@ EOF
end
+ def test_default_settings
+ config=<<EOF
+person("test")
+EOF
+ x = nil
+ assert_nothing_raised { x = Mauve::ConfigurationBuilder.parse(config) }
+ person = x.people["test"]
+
+ assert_equal(nil, person.sms)
+ assert_equal(nil, person.email)
+ assert_equal(nil, person.xmpp)
+
+ assert_kind_of(Proc, person.low)
+ assert_kind_of(Proc, person.normal)
+ assert_kind_of(Proc, person.urgent)
+
+ assert_kind_of(Hash, person.notification_thresholds)
+ assert_equal(1,person.notification_thresholds.keys.length)
+ assert(person.notification_thresholds.all?{|k,v| k.is_a?(Integer) and v.is_a?(Array)})
+
+ assert_kind_of(Array, person.notifications)
+ assert_equal(1, person.notifications.length)
+ end
+
end