god-sns-contact 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/README.md +37 -0
- data/Rakefile +9 -0
- data/god-sns-contact.gemspec +21 -0
- data/lib/god-sns-contact.rb +59 -0
- data/lib/god-sns-contact/version.rb +7 -0
- data/test/helper.rb +14 -0
- data/test/test_sns.rb +17 -0
- metadata +90 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Fanzter Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
God + Amazon SNS
|
2
|
+
=================================
|
3
|
+
|
4
|
+
This library adds a God::Contacts class for Amazon's Simple Notification Service (SNS).
|
5
|
+
|
6
|
+
* http://god.rubyforge.org/
|
7
|
+
* http://aws.amazon.com/sns/
|
8
|
+
|
9
|
+
As of November, 2011 this project is experimental and we eagerly welcome
|
10
|
+
feedback and contributions.
|
11
|
+
|
12
|
+
Usage
|
13
|
+
============
|
14
|
+
|
15
|
+
After creating your SNS Topic and adding a subscription or two, copy its ARN and then
|
16
|
+
add something like this to your god config. Make sure the gem is installed, of course.
|
17
|
+
|
18
|
+
|
19
|
+
require 'god-sns-contact'
|
20
|
+
CONTACT_LOAD_SUCCESS[:sns] = true
|
21
|
+
|
22
|
+
God.contact(:sns) do |c|
|
23
|
+
c.name = 'sns'
|
24
|
+
c.access_key_id = "your access_key id"
|
25
|
+
c.secret_access_key = "your secret access key"
|
26
|
+
c.arn = 'arn:aws:sns:us-east-1:12345677890:god' # Get your ARN from SNS
|
27
|
+
end
|
28
|
+
|
29
|
+
It's usually best to create IAM creds specific to this task so you're not leaving
|
30
|
+
keys with lots of access sitting around on your filesystem.
|
31
|
+
|
32
|
+
Attribution
|
33
|
+
===========
|
34
|
+
|
35
|
+
© 2011 Fanzter Inc. Fanzter is a privately held software development company based
|
36
|
+
in Charleston, South Carolina, United States. Find us at [Fanzter.com](http://fanzter.com/)
|
37
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/god-sns-contact/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Joshua Warchol"]
|
6
|
+
gem.email = ["joshua@fanzter.com"]
|
7
|
+
gem.description = %q{A God::Contacts class for Amazon's Simple Notification Service (SNS)}
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.homepage = "http://github.com/fanzter/god-sns-contact"
|
10
|
+
|
11
|
+
gem.add_dependency "god"
|
12
|
+
gem.add_dependency "aws-sdk"
|
13
|
+
gem.add_development_dependency "mocha"
|
14
|
+
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
gem.files = `git ls-files`.split("\n")
|
17
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
gem.name = "god-sns-contact"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.version = God::Sns::Contact::VERSION
|
21
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Send a notice via Amazon's Simple Notification Service (SNS)
|
2
|
+
#
|
3
|
+
# access_key_id - The String AWS access key id (defaults to God's
|
4
|
+
# existing access key id).
|
5
|
+
# secret_access_key - The String AWS secret access key(defaults to God's
|
6
|
+
# existing secret access key).
|
7
|
+
# arn - The Amazon Resorce Name of your SNS topic
|
8
|
+
|
9
|
+
require "god"
|
10
|
+
|
11
|
+
CONTACT_DEPS[:twitter] = ['aws-sdk']
|
12
|
+
CONTACT_DEPS[:twitter].each do |d|
|
13
|
+
require d
|
14
|
+
end
|
15
|
+
|
16
|
+
module God
|
17
|
+
module Contacts
|
18
|
+
class Sns < Contact
|
19
|
+
class << self
|
20
|
+
attr_accessor :access_key_id, :secret_access_key, :arn, :format
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
self.format = lambda do |message, time, priority, category, host|
|
25
|
+
<<-EOF
|
26
|
+
Message: #{message}
|
27
|
+
Host: #{host}
|
28
|
+
Priority: #{priority}
|
29
|
+
Category: #{category}
|
30
|
+
Date: #{time.httpdate}
|
31
|
+
EOF
|
32
|
+
end
|
33
|
+
|
34
|
+
def valid?
|
35
|
+
valid = true
|
36
|
+
valid &= complain("Attribute 'access_key_id' must be specified", self) unless arg(:access_key_id)
|
37
|
+
valid &= complain("Attribute 'secret_access_key' must be specified", self) unless arg(:secret_access_key)
|
38
|
+
valid &= complain("Attribute 'arn' must be specified", self) unless arg(:arn)
|
39
|
+
valid
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_accessor :access_key_id, :secret_access_key, :arn
|
43
|
+
|
44
|
+
def notify(message, time, priority, category, host)
|
45
|
+
|
46
|
+
AWS.config(:access_key_id => access_key_id, :secret_access_key => secret_access_key)
|
47
|
+
topic = AWS::SNS::Topic.new(arn)
|
48
|
+
|
49
|
+
topic.publish(Sns.format.call(message, time, priority, category, host), :subject => "God Alert")
|
50
|
+
|
51
|
+
self.info = "sent sns update"
|
52
|
+
rescue => e
|
53
|
+
applog(nil, :info, "failed to send sns update: #{e.message}")
|
54
|
+
applog(nil, :debug, e.backtrace.join("\n"))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/test/helper.rb
ADDED
data/test/test_sns.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/helper'
|
3
|
+
|
4
|
+
class TestSns < Test::Unit::TestCase
|
5
|
+
def test_live_notify
|
6
|
+
sns = God::Contacts::Sns.new
|
7
|
+
sns.name = "sns"
|
8
|
+
sns.access_key_id = 'put_your_access_key_id_here'
|
9
|
+
sns.secret_access_key = 'put_your_secret_access_key_here'
|
10
|
+
sns.arn = 'arn:testing:whatever:cool'
|
11
|
+
|
12
|
+
AWS::SNS::Topic.any_instance.expects(:publish).returns("not-a-real-id-but-ok")
|
13
|
+
|
14
|
+
sns.notify("Test", Time.now, "Test", "Test", "")
|
15
|
+
assert_equal "sent sns update", sns.info
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: god-sns-contact
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joshua Warchol
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: god
|
16
|
+
requirement: &70344749752100 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70344749752100
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: aws-sdk
|
27
|
+
requirement: &70344749751680 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70344749751680
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mocha
|
38
|
+
requirement: &70344749751260 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70344749751260
|
47
|
+
description: A God::Contacts class for Amazon's Simple Notification Service (SNS)
|
48
|
+
email:
|
49
|
+
- joshua@fanzter.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- god-sns-contact.gemspec
|
60
|
+
- lib/god-sns-contact.rb
|
61
|
+
- lib/god-sns-contact/version.rb
|
62
|
+
- test/helper.rb
|
63
|
+
- test/test_sns.rb
|
64
|
+
homepage: http://github.com/fanzter/god-sns-contact
|
65
|
+
licenses: []
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.10
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: A God::Contacts class for Amazon's Simple Notification Service (SNS)
|
88
|
+
test_files:
|
89
|
+
- test/helper.rb
|
90
|
+
- test/test_sns.rb
|