comsat 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -36,6 +36,7 @@ Messages are datum's that contain three pieces of information:
36
36
  * message
37
37
  * source
38
38
  * message_id
39
+ * message_type
39
40
 
40
41
  The 'source' is where this message originates, for example, "nagios". The
41
42
  'message_id' should be a unique identifier for this message, and for certain
@@ -78,6 +79,20 @@ client.notify("notify_on_exception", {
78
79
  })
79
80
  ```
80
81
 
82
+ Or you can specify routes without an 'event_type', instead specifying it in
83
+ the payload:
84
+
85
+ ```ruby
86
+ client = Comsat::Client.new
87
+ client.create_route("notify_on_exception", ["campfire://<api_key>:X@blossom.campfirenow.com/Test%20Room"])
88
+ client.notify("notify_on_exception", {
89
+ :message => "Exception reached in #function",
90
+ :source => "my_app",
91
+ :message_id => "exception-#{rand(1_000)}",
92
+ :message_type => "notice"
93
+ })
94
+ ```
95
+
81
96
  You can also instrument Comsat with your favorite logger (which should be
82
97
  Scrolls by now :)):
83
98
 
data/lib/comsat/client.rb CHANGED
@@ -10,7 +10,7 @@ module Comsat
10
10
  @@routes
11
11
  end
12
12
 
13
- def create_route(route, event_type, services)
13
+ def create_route(route, event_type=nil, services)
14
14
  start = Time.now
15
15
  Comsat.log(:fn => :create_route, :route => "#{route}", :at => :start)
16
16
  unless routes.detect {|r| r.name == route }
@@ -19,41 +19,24 @@ module Comsat
19
19
  Comsat.log(:fn => :create_route, :route => "#{route}", :at => :finish, :elapsed => Time.now - start)
20
20
  end
21
21
 
22
- def notify(route, message={})
22
+ def notify(route, msg={})
23
+ message = msg.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
24
+ if notify_route.event_type
25
+ event = notify_route
26
+ elsif message[:message_type]
27
+ event = message[:message_type]
28
+ else
29
+ event = "notice"
30
+ end
31
+
23
32
  start = Time.now
24
33
  Comsat.log(:fn => :notify, :route => "#{route}", :at => :start)
25
34
  notify_route = @@routes.detect {|r| r.name == route } if message
26
- event = notify_route.event_type
27
35
  notify_route.services.each do |svc|
28
36
  Comsat.log(:fn => :notify, :service => "#{svc.class.to_s.downcase}", :event => event)
29
37
  svc.send("send_#{event}".to_sym, message)
30
38
  end
31
39
  Comsat.log(:fn => :notify, :route => "#{route}", :at => :finish, :elapsed => Time.now - start)
32
40
  end
33
-
34
- def send_notice(data)
35
- send_event(:notice, data)
36
- end
37
-
38
- def send_alert(data)
39
- send_event(:alert, data)
40
- end
41
-
42
- def send_resolve(data)
43
- send_event(:resolve, data)
44
- end
45
-
46
- private
47
-
48
- def send_event(event_type, data)
49
- @urls.each do |url|
50
- service = ServiceFactory.create(url)
51
- if service.respond_to?("send_#{event_type}")
52
- service.send("send_#{event_type}".to_sym, data)
53
- else
54
- next
55
- end
56
- end
57
- end
58
41
  end
59
42
  end
data/lib/comsat/route.rb CHANGED
@@ -2,16 +2,23 @@ module Comsat
2
2
  class Route
3
3
  attr_accessor :name, :services, :event_type
4
4
 
5
- def initialize(route, et, urls)
5
+ def initialize(route, et=nil, urls)
6
6
  @name = route
7
- @event_type = et if %w(alert notice resolve).include?(et)
8
- @services = []
7
+ @event_type = et
8
+
9
+ @services = {
10
+ "notice" => [],
11
+ "alert" => [],
12
+ "resolve" => [],
13
+ "all" => []
14
+ }
15
+
9
16
  urls.each do |url|
10
17
  svc = ServiceFactory.create(url)
11
18
  if svc.respond_to?("send_#{@event_type}")
12
- @services << svc
19
+ @services[@event_type] << svc
13
20
  else
14
- next
21
+ @services["all"] << svc
15
22
  end
16
23
  end
17
24
  end
@@ -10,6 +10,15 @@ module Comsat
10
10
  def to_s
11
11
  "#<#{self.class} @host='#{@credentials.host}', @scope='#{@credentials.scope}'>"
12
12
  end
13
+
14
+ def http_post
15
+ end
16
+
17
+ def http_get
18
+ end
19
+
20
+ def http_put
21
+ end
13
22
  end
14
23
  end
15
24
 
@@ -17,7 +17,7 @@ module Comsat
17
17
  source = data[:source]
18
18
  message = "[#{source}] #{message}"
19
19
 
20
- pagerduty_url = "https://#{@credentials.host}/#{@credentials.scope}"
20
+ pagerduty_url = "https://#{@credentials.host}/generic/2010-04-15/create_event.json"
21
21
  data = {
22
22
  :service_key => @credentials.api_key,
23
23
  :incident_key => id,
@@ -1,3 +1,3 @@
1
1
  module Comsat
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -12,28 +12,49 @@ describe Comsat::Client do
12
12
  end
13
13
 
14
14
  describe "#create_route" do
15
- before do
16
- subject.create_route("test_route", "notice", [undefined_svc, defined_svc])
17
- end
18
15
 
19
- it "should register a route with base class" do
20
- subject.routes.should_not be_empty
21
- end
16
+ describe "specify event_types" do
17
+ before do
18
+ subject.create_route("test_route", "notice", [undefined_svc, defined_svc])
19
+ end
22
20
 
23
- it "should create a route" do
24
- subject.routes.first.name.should == "test_route"
25
- end
21
+ it "should register a route with base class" do
22
+ subject.routes.should_not be_empty
23
+ end
26
24
 
27
- it "should have one service initiated" do
28
- subject.routes.first.services.length.should == 1
29
- end
25
+ it "should create a route" do
26
+ subject.routes.first.name.should == "test_route"
27
+ end
28
+
29
+ it "should have one service initiated on the event_type 'notice'" do
30
+ subject.routes.first.services["notice"].length.should == 1
31
+ end
30
32
 
31
- it "should have a campfire service initiated" do
32
- subject.routes.first.services.first.class.should == Comsat::Campfire
33
+ it "should have a campfire service initiated" do
34
+ subject.routes.first.services["notice"].first.class.should == Comsat::Campfire
35
+ end
36
+
37
+ it "should provide an event type" do
38
+ subject.routes.first.event_type == "notice"
39
+ end
33
40
  end
34
41
 
35
- it "should provide an event type" do
36
- subject.routes.first.event_type == "notice"
42
+ describe "no event_type specified" do
43
+ before do
44
+ subject.create_route("test_route2", [defined_svc])
45
+ end
46
+
47
+ it "should register a route with base class" do
48
+ subject.routes.should_not be_empty
49
+ end
50
+
51
+ it "should create a route" do
52
+ subject.routes.first.name.should == "test_route2"
53
+ end
54
+
55
+ it "should have one service initiated on all event_types" do
56
+ subject.routes.first.services["all"].length.should == 1
57
+ end
37
58
  end
38
59
  end
39
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comsat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-13 00:00:00.000000000 Z
13
+ date: 2012-04-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
17
- requirement: &70218924303220 !ruby/object:Gem::Requirement
17
+ requirement: &70239639975100 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70218924303220
25
+ version_requirements: *70239639975100
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: scrolls
28
- requirement: &70218924301180 !ruby/object:Gem::Requirement
28
+ requirement: &70239639974440 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70218924301180
36
+ version_requirements: *70239639974440
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rake
39
- requirement: &70218924300220 !ruby/object:Gem::Requirement
39
+ requirement: &70239639972620 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70218924300220
47
+ version_requirements: *70239639972620
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &70218924299080 !ruby/object:Gem::Requirement
50
+ requirement: &70239639971220 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70218924299080
58
+ version_requirements: *70239639971220
59
59
  description: Notifications as a Gem
60
60
  email:
61
61
  - ops@heroku.com