whoops 0.2.4 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/stylesheets/whoops.css.scss +17 -0
- data/app/controllers/event_groups_controller.rb +7 -0
- data/app/controllers/notification_rules_controller.rb +29 -0
- data/app/mailers/whoops/notification_mailer.rb +5 -3
- data/app/models/whoops/event_group.rb +4 -3
- data/app/models/whoops/notification_rule.rb +22 -5
- data/app/views/events/index.html.haml +9 -1
- data/app/views/layouts/whoops.html.haml +5 -2
- data/app/views/notification_rules/_form.html.haml +15 -0
- data/app/views/notification_rules/edit.html.haml +8 -0
- data/app/views/notification_rules/index.html.haml +21 -0
- data/config/routes.rb +2 -1
- metadata +8 -5
@@ -146,4 +146,21 @@ ul.detail {
|
|
146
146
|
font-weight:normal;
|
147
147
|
color:$blue;
|
148
148
|
}
|
149
|
+
}
|
150
|
+
|
151
|
+
/* Notification rules! */
|
152
|
+
#new-notification-rule {
|
153
|
+
textarea {
|
154
|
+
height: 100px;
|
155
|
+
width:190px;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
.topbar .documentation {
|
160
|
+
float: right;
|
161
|
+
@extend .brand;
|
162
|
+
}
|
163
|
+
|
164
|
+
header form {
|
165
|
+
float:right;
|
149
166
|
}
|
@@ -5,6 +5,7 @@ class EventGroupsController < ApplicationController
|
|
5
5
|
|
6
6
|
def index
|
7
7
|
query_document = event_group_filter.to_query_document
|
8
|
+
query_document.merge!(:archived => false) unless params[:show_archived]
|
8
9
|
query_document.merge!(:_id.in => Whoops::Event.where(:keywords => /#{params[:query]}/i).distinct(:event_group_id)) unless params[:query].blank?
|
9
10
|
|
10
11
|
@event_groups = Whoops::EventGroup.where(query_document).desc(:last_recorded_at).page(params[:page]).per(30)
|
@@ -30,5 +31,11 @@ class EventGroupsController < ApplicationController
|
|
30
31
|
def event_group_filter=(filter)
|
31
32
|
session[:event_group_filter] = Whoops::Filter.new_from_params(filter)
|
32
33
|
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
@event_group = Whoops::EventGroup.find(params[:id])
|
37
|
+
@event_group.update_attributes(:archived => params[:event_group][:archived] == "true")
|
38
|
+
redirect_to whoops_event_group_events_path(@event_group)
|
39
|
+
end
|
33
40
|
|
34
41
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class NotificationRulesController < ApplicationController
|
2
|
+
layout 'whoops'
|
3
|
+
|
4
|
+
def index
|
5
|
+
@notification_rule = Whoops::NotificationRule.new
|
6
|
+
@notification_rules = Whoops::NotificationRule.asc(:email)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
Whoops::NotificationRule.add_rules(params[:notification_rule])
|
11
|
+
redirect_to whoops_notification_rules_path
|
12
|
+
end
|
13
|
+
|
14
|
+
def edit
|
15
|
+
@notification_rule = Whoops::NotificationRule.find(params[:id])
|
16
|
+
end
|
17
|
+
|
18
|
+
def update
|
19
|
+
@notification_rule = Whoops::NotificationRule.find(params[:id])
|
20
|
+
@notification_rule.update_attributes(params[:notification_rule])
|
21
|
+
notification_rules = Whoops::NotificationRule.asc(:email)
|
22
|
+
redirect_to whoops_notification_rules_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
Whoops::NotificationRule.find(params[:id]).destroy
|
27
|
+
redirect_to whoops_notification_rules_path
|
28
|
+
end
|
29
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class Whoops::NotificationMailer < ActionMailer::Base
|
2
|
-
def event_notification(event_group,
|
2
|
+
def event_notification(event_group, addresses)
|
3
3
|
@event_group = event_group
|
4
4
|
@addresses = addresses
|
5
5
|
mail(
|
6
6
|
:to => addresses.join(", "),
|
7
|
-
:
|
7
|
+
:from => Rails.application.config.whoops_sender,
|
8
|
+
:subject => "Whoops Notification | #{event_group.service}: #{event_group.environment}: #{event_group.message}",
|
9
|
+
:body => "#{event_group.service}: #{event_group.environment}: #{event_group.message}"
|
8
10
|
)
|
9
11
|
end
|
10
|
-
end
|
12
|
+
end
|
@@ -31,6 +31,7 @@ class Whoops::EventGroup
|
|
31
31
|
end
|
32
32
|
|
33
33
|
if event_group.valid?
|
34
|
+
event_group.event_count += 1
|
34
35
|
event_group.send_notifications
|
35
36
|
event_group.save
|
36
37
|
end
|
@@ -62,13 +63,13 @@ class Whoops::EventGroup
|
|
62
63
|
self.notify_on_next_occurrence = true
|
63
64
|
end
|
64
65
|
end
|
66
|
+
true
|
65
67
|
end
|
66
68
|
|
67
|
-
|
68
69
|
def send_notifications
|
69
|
-
return
|
70
|
+
return if !self.notify_on_next_occurrence || !Rails.application.config.whoops_sender
|
70
71
|
matcher = Whoops::NotificationRule::Matcher.new(self)
|
71
|
-
Whoops::NotificationMailer.event_notification(self, matcher.matches).deliver unless matcher.matches.empty?
|
72
|
+
Whoops::NotificationMailer.event_notification(self, matcher.matches.collect(&:email)).deliver unless matcher.matches.empty?
|
72
73
|
self.notify_on_next_occurrence = false
|
73
74
|
end
|
74
75
|
end
|
@@ -4,6 +4,8 @@ class Whoops::NotificationRule
|
|
4
4
|
field :email, :type => String
|
5
5
|
field :matchers, :type => Array
|
6
6
|
|
7
|
+
validates_presence_of :email
|
8
|
+
|
7
9
|
# This might come in handy in the future?
|
8
10
|
# class << self.fields["matchers"]
|
9
11
|
# def set(object)
|
@@ -19,11 +21,26 @@ class Whoops::NotificationRule
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def matchers=(matchers)
|
22
|
-
write_attribute(:matchers, matchers
|
24
|
+
write_attribute(:matchers, split_matchers(matchers).sort)
|
23
25
|
end
|
24
|
-
|
25
|
-
def
|
26
|
-
|
26
|
+
|
27
|
+
def add_matchers(new_matchers)
|
28
|
+
split = split_matchers(new_matchers)
|
29
|
+
write_attribute(:matchers, (self.matchers | split).sort)
|
30
|
+
self.save
|
31
|
+
end
|
32
|
+
|
33
|
+
def split_matchers(new_matchers)
|
34
|
+
new_matchers.split("\n").collect{ |m| m.strip }
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.add_rules(params)
|
38
|
+
params[:email] = params[:email].downcase
|
39
|
+
if rule = first(:conditions => {:email => params[:email]})
|
40
|
+
rule.add_matchers(params[:matchers])
|
41
|
+
else
|
42
|
+
create(params)
|
43
|
+
end
|
27
44
|
end
|
28
45
|
|
29
46
|
class Matcher
|
@@ -42,4 +59,4 @@ class Whoops::NotificationRule
|
|
42
59
|
@matches ||= Whoops::NotificationRule.where(:matchers => /^#{event_group.service}/)
|
43
60
|
end
|
44
61
|
end
|
45
|
-
end
|
62
|
+
end
|
@@ -24,7 +24,15 @@
|
|
24
24
|
|
25
25
|
%article
|
26
26
|
%header
|
27
|
-
|
27
|
+
= form_for :event_group, :url => whoops_event_group_path(@event_group), :method => :put do |f|
|
28
|
+
- if @event_group.archived
|
29
|
+
= f.hidden_field :archived, :value => false
|
30
|
+
= f.submit :class => "btn", :value => "unarchive"
|
31
|
+
- else
|
32
|
+
= f.hidden_field :archived, :value => true
|
33
|
+
= f.submit :class => "btn", :value => "archive"
|
34
|
+
%h3
|
35
|
+
= @event_group.message
|
28
36
|
%table.span8.bordered-table
|
29
37
|
%thead
|
30
38
|
%tr
|
@@ -14,9 +14,12 @@
|
|
14
14
|
.topbar
|
15
15
|
.listfill
|
16
16
|
.container-fluid
|
17
|
-
= link_to "
|
17
|
+
= link_to "Event Groups", whoops_event_groups_path, :class => "brand"
|
18
|
+
= link_to "Notification Rules", whoops_notification_rules_path, :class => "brand"
|
19
|
+
= link_to "Whoops Documentation", "http://www.whoopsapp.com/", :class => "documentation"
|
18
20
|
.container-fluid
|
19
21
|
.sidebar
|
20
22
|
= yield :sidebar
|
21
23
|
.content
|
22
|
-
= yield
|
24
|
+
= yield
|
25
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%h3 New
|
2
|
+
- options = @notification_rule.new_record? ? {:url => whoops_notification_rules_path, :method => :post} : {:url => whoops_notification_rule_path(@notification_rule), :method => :put}
|
3
|
+
= form_for :notification_rule, options do |f|
|
4
|
+
#new-notification-rule
|
5
|
+
%p
|
6
|
+
Email
|
7
|
+
%br
|
8
|
+
=f.text_field :email
|
9
|
+
%p
|
10
|
+
Matchers
|
11
|
+
%br
|
12
|
+
= f.text_area :matchers, :value => @notification_rule.matchers.to_a.join("\n")
|
13
|
+
%p= f.submit(:class => "primary btn", :value => "Save Notification Rule")
|
14
|
+
|
15
|
+
%p= link_to "Back to notification rules", whoops_notification_rules_path
|
@@ -0,0 +1,8 @@
|
|
1
|
+
%h3 Edit Notification Rules for #{@notification_rule.email}
|
2
|
+
|
3
|
+
= render :partial => "form"
|
4
|
+
|
5
|
+
%h4 Delete This Rule
|
6
|
+
|
7
|
+
= form_for :notification_rule, :method => :delete, :url => whoops_notification_rule_path(@notification_rule) do |f|
|
8
|
+
= f.submit :class => "btn", :value => "Delete it Forever! There's no going back!"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
%h3 Notification Rules
|
2
|
+
|
3
|
+
- content_for :sidebar do
|
4
|
+
.space
|
5
|
+
= render :partial => "form"
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
%table
|
10
|
+
%tr
|
11
|
+
%th Email Address
|
12
|
+
%th Services to Monitor
|
13
|
+
%th
|
14
|
+
|
15
|
+
- @notification_rules.each do |nr|
|
16
|
+
%tr
|
17
|
+
%td= nr.email
|
18
|
+
%td= nr.matchers.sort.join(", ")
|
19
|
+
%td= link_to "update", edit_whoops_notification_rule_path(nr)
|
20
|
+
|
21
|
+
|
data/config/routes.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whoops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.2.4
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Daniel Higginbotham
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2012-07-
|
17
|
+
date: 2012-07-04 00:00:00 Z
|
19
18
|
dependencies:
|
20
19
|
- !ruby/object:Gem::Dependency
|
21
20
|
name: rails
|
@@ -186,6 +185,7 @@ files:
|
|
186
185
|
- app/assets/stylesheets/whoops.css.scss
|
187
186
|
- app/controllers/event_groups_controller.rb
|
188
187
|
- app/controllers/events_controller.rb
|
188
|
+
- app/controllers/notification_rules_controller.rb
|
189
189
|
- app/helpers/event_groups_helper.rb
|
190
190
|
- app/helpers/events_helper.rb
|
191
191
|
- app/helpers/notifications_helper.rb
|
@@ -202,6 +202,9 @@ files:
|
|
202
202
|
- app/views/events/_details.html.haml
|
203
203
|
- app/views/events/index.html.haml
|
204
204
|
- app/views/layouts/whoops.html.haml
|
205
|
+
- app/views/notification_rules/_form.html.haml
|
206
|
+
- app/views/notification_rules/edit.html.haml
|
207
|
+
- app/views/notification_rules/index.html.haml
|
205
208
|
- lib/tasks/whoops.rake
|
206
209
|
- lib/whoops/engine.rb
|
207
210
|
- lib/whoops.rb
|