comsat 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +69 -0
- data/Rakefile +2 -0
- data/comsat.gemspec +20 -0
- data/lib/comsat/version.rb +3 -0
- data/lib/comsat.rb +107 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Comsat
|
2
|
+
|
3
|
+
Notifications gem
|
4
|
+
|
5
|
+
This is the first iteration for making notifications easy to use from all
|
6
|
+
services. This is only a stop gap with a centralized service planned to manage
|
7
|
+
credentials and to keep from duplicating efforts.
|
8
|
+
|
9
|
+
Credentials are passed in a URL structure, for example, here is what a scheme
|
10
|
+
for Campfire might look like:
|
11
|
+
|
12
|
+
campfire://<api_key>:X@blossom.campfirenow.com/Test%20Room
|
13
|
+
|
14
|
+
The schema name maps to the service name, the rest we pass to the service to
|
15
|
+
deal with.
|
16
|
+
|
17
|
+
## Messages
|
18
|
+
|
19
|
+
Messages should be one of three types, 'notice', 'alert', 'resolve'.
|
20
|
+
|
21
|
+
Messages are datum's that contain three pieces of information:
|
22
|
+
|
23
|
+
* message
|
24
|
+
* source
|
25
|
+
* message_id
|
26
|
+
|
27
|
+
The 'source' is where this message originates, for example, "nagios". The
|
28
|
+
'message_id' should be a unique identifier for this message, and for certain
|
29
|
+
services should be used on alert/resolve messages to easily resolve them (i.e.
|
30
|
+
PagerDuty).
|
31
|
+
|
32
|
+
## Services
|
33
|
+
|
34
|
+
Each service should define three methods, one for each type of message:
|
35
|
+
|
36
|
+
* send_notice
|
37
|
+
* send_alert
|
38
|
+
* send_resolve
|
39
|
+
|
40
|
+
These provide the common interface between all of the services.
|
41
|
+
|
42
|
+
## Installation
|
43
|
+
|
44
|
+
Add this line to your application's Gemfile:
|
45
|
+
|
46
|
+
gem 'comsat'
|
47
|
+
|
48
|
+
And then execute:
|
49
|
+
|
50
|
+
$ bundle
|
51
|
+
|
52
|
+
Or install it yourself as:
|
53
|
+
|
54
|
+
$ gem install comsat
|
55
|
+
|
56
|
+
## Usage
|
57
|
+
|
58
|
+
```
|
59
|
+
client = Comsat::Client.new(["campfire://<api_key>:X@blossom.campfirenow.com/Test%20Room"])
|
60
|
+
client.send_notice({:message => "message here", :source => "nagios", :message_id => "unique_id"})
|
61
|
+
```
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/comsat.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/comsat/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["curt@heroku.com", "gorsuch@heroku.com"]
|
6
|
+
gem.email = ["ops@heroku.com"]
|
7
|
+
gem.description = "Early notification gem"
|
8
|
+
gem.summary = "Early notification gem"
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "comsat"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Comsat::VERSION
|
17
|
+
|
18
|
+
gem.add_runtime_dependency('rest-client')
|
19
|
+
gem.add_runtime_dependency('tinder')
|
20
|
+
end
|
data/lib/comsat.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
require "cgi"
|
2
|
+
require "comsat/version"
|
3
|
+
require "json"
|
4
|
+
require "rest_client"
|
5
|
+
require "securerandom"
|
6
|
+
require "tinder"
|
7
|
+
|
8
|
+
module Comsat
|
9
|
+
class Client
|
10
|
+
def initialize(urls)
|
11
|
+
@urls = urls
|
12
|
+
end
|
13
|
+
|
14
|
+
def send_notice(data)
|
15
|
+
@urls.each do |url|
|
16
|
+
ServiceFactory.create(url).send_notice(data)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_alert(data)
|
21
|
+
@urls.each do |url|
|
22
|
+
ServiceFactory.create(url).send_alert(data)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def send_resolve(data)
|
27
|
+
@urls.each do |url|
|
28
|
+
ServiceFactory.create(url).send_resolve(data)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class ServiceFactory
|
34
|
+
def self.create(url)
|
35
|
+
uri = URI.parse(url)
|
36
|
+
case uri.scheme
|
37
|
+
when 'campfire'
|
38
|
+
Campfire.new(uri)
|
39
|
+
when 'pagerduty'
|
40
|
+
PagerDuty.new(uri)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class Campfire
|
46
|
+
def initialize(uri)
|
47
|
+
@acct = uri.host.split('.')[0]
|
48
|
+
@api_key = uri.user
|
49
|
+
@room = CGI.unescape(uri.path.gsub(/\A\//, ''))
|
50
|
+
end
|
51
|
+
|
52
|
+
def send_notice(data)
|
53
|
+
# {:messages, :source, :message_id}
|
54
|
+
messages = []
|
55
|
+
messages << "[#{data[:source]}] #{data[:message]}"
|
56
|
+
send_message(messages)
|
57
|
+
end
|
58
|
+
alias :send_alert :send_notice
|
59
|
+
alias :send_resolve :send_notice
|
60
|
+
|
61
|
+
def send_message(msgs)
|
62
|
+
unless room = find_room
|
63
|
+
raise "Unable to find room"
|
64
|
+
end
|
65
|
+
Array(msgs).each {|line| room.speak line }
|
66
|
+
end
|
67
|
+
|
68
|
+
def campfire
|
69
|
+
@campfire = ::Tinder::Campfire.new(
|
70
|
+
@acct,
|
71
|
+
:ssl => true,
|
72
|
+
:token => @api_key
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def find_room
|
77
|
+
campfire.find_room_by_name(@room)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
class PagerDuty
|
82
|
+
ENDPOINT = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json'
|
83
|
+
|
84
|
+
def initialize(uri)
|
85
|
+
@api_key = uri.user
|
86
|
+
end
|
87
|
+
|
88
|
+
def contact_pagerduty(event_type, data)
|
89
|
+
id = data[:message_id] || SecureRandom.uuid
|
90
|
+
message = data[:message]
|
91
|
+
source = data[:source]
|
92
|
+
message = "#{source}: #{message}"
|
93
|
+
|
94
|
+
data = { :service_key => @api_key, :incident_key => id, :event_type => event_type, :description => message }
|
95
|
+
RestClient.post ENDPOINT, data.to_json, :content_type => :json
|
96
|
+
end
|
97
|
+
|
98
|
+
def send_notice(data)
|
99
|
+
contact_pagerduty(:trigger, data)
|
100
|
+
end
|
101
|
+
alias :send_alert :send_notice
|
102
|
+
|
103
|
+
def send_resolve(data)
|
104
|
+
contact_pagerduty(:resolve, data)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: comsat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- curt@heroku.com
|
9
|
+
- gorsuch@heroku.com
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-04-10 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rest-client
|
17
|
+
requirement: &70113286660760 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70113286660760
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: tinder
|
28
|
+
requirement: &70113286659660 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70113286659660
|
37
|
+
description: Early notification gem
|
38
|
+
email:
|
39
|
+
- ops@heroku.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- comsat.gemspec
|
50
|
+
- lib/comsat.rb
|
51
|
+
- lib/comsat/version.rb
|
52
|
+
homepage: ''
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.11
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Early notification gem
|
76
|
+
test_files: []
|