blob: 851ab7fccd7381e75792b64ee170f4dbfb24e54a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# encoding: UTF-8
require 'object_builder'
require 'mauve/notification'
require 'mauve/configuration_builder'
require 'mauve/alert_group'
require 'mauve/notification'
module Mauve
module ConfigurationBuilders
#
# This corresponds to a new "notify" clause an the alert_group config.
#
class Notification < ObjectBuilder
# Sets up the notification
#
# @param [String] who Username or people_list to notify
# @raise [ArgumentError] if a username doesn't exist.
#
# @return [Mauve::Notification] New notification instance.
def builder_setup(who)
who = if who.is_a?(Mauve::Person) or who.is_a?(Mauve::PeopleList)
who
elsif @context.people[who]
@context.people[who]
elsif @context.people_lists[who]
@context.people_lists[who]
else
raise ArgumentError.new("You have not declared who #{who} is")
end
@result = Mauve::Notification.new(who)
end
is_attribute "every"
is_block_attribute "during"
end
# This corresponds to a new alert_group clause
#
class AlertGroup < ObjectBuilder
# Sets up the alert group, and sets the last_alert_group context.
#
# @param [String] name Name of the new alert group
#
# @return [Mauve::AlertGroup] New alert group instance
def builder_setup(name="anonymous_name")
@result = Mauve::AlertGroup.new(name)
end
is_block_attribute "includes"
is_attribute "acknowledgement_time"
is_attribute "level"
is_builder "notify", Mauve::ConfigurationBuilders::Notification
# Method called after the notify clause has been sorted. Adds new
# notification clause to the result.
#
# @param [Mauve::Notification] notification
#
def created_notify(notification)
@result.notifications ||= []
if notification.during.nil? and notification.every.nil?
@result.notifications += notification.person.notifications.collect do |n|
#
# Set up a new notification for each one defined for this person.
#
new_notification = Mauve::Notification.new(notification.person)
new_notification.level = @result.level
new_notification.every = n.every
new_notification.during = n.during
new_notification
end
else
#
# Set the level for this notification
#
notification.level = @result.level
@result.notifications << notification
end
end
end
end
# These constants define the levels available for alert groups.
#
# This should live in AlertGroup but can't due to
# http://briancarper.net/blog/ruby-instance_eval_constant_scoping_broken
#
module AlertGroupConstants
# Urgent level
URGENT = :urgent
# Normal level
NORMAL = :normal
# Low level
LOW = :low
end
class ConfigurationBuilder < ObjectBuilder
include AlertGroupConstants
is_builder "alert_group", ConfigurationBuilders::AlertGroup
# Called after an alert group is created. Checks to make sure that no more than one alert group shares a name.
#
# @param [Mauve::AlertGroup] alert_group The new AlertGroup
# @raise [ArgumentError] if an AlertGroup with the same name already exists.
#
def created_alert_group(alert_group)
name = alert_group.name
raise ArgumentError.new("Duplicate alert_group '#{name}'") unless @result.alert_groups.select { |g| g.name == name }.empty?
@result.alert_groups << alert_group
end
end
end
|