Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial setup

  • Loading branch information...
commit c2a175f0a2cf1a2021eafdfef98669398a1ac563 0 parents
Joshua Warchol jwarchol authored
17 .gitignore
... ... @@ -0,0 +1,17 @@
  1 +*.gem
  2 +*.rbc
  3 +.bundle
  4 +.config
  5 +.yardoc
  6 +Gemfile.lock
  7 +InstalledFiles
  8 +_yardoc
  9 +coverage
  10 +doc/
  11 +lib/bundler/man
  12 +pkg
  13 +rdoc
  14 +spec/reports
  15 +test/tmp
  16 +test/version_tmp
  17 +tmp
8 Gemfile
... ... @@ -0,0 +1,8 @@
  1 +source 'http://rubygems.org'
  2 +
  3 +# Specify your gem's dependencies in god-sns-contact.gemspec
  4 +gemspec
  5 +
  6 +group :development do
  7 + gem "rake"
  8 +end
9 Rakefile
... ... @@ -0,0 +1,9 @@
  1 +#!/usr/bin/env rake
  2 +require "bundler/gem_tasks"
  3 +require "rake/testtask"
  4 +
  5 +Rake::TestTask.new do |t|
  6 + t.libs << 'test'
  7 +end
  8 +
  9 +task :default => :test
20 god-sns-contact.gemspec
... ... @@ -0,0 +1,20 @@
  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 +
  14 + gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
  15 + gem.files = `git ls-files`.split("\n")
  16 + gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
  17 + gem.name = "god-sns-contact"
  18 + gem.require_paths = ["lib"]
  19 + gem.version = God::Sns::Contact::VERSION
  20 +end
59 lib/god-sns-contact.rb
... ... @@ -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 +
7 lib/god-sns-contact/version.rb
... ... @@ -0,0 +1,7 @@
  1 +module God
  2 + module Sns
  3 + module Contact
  4 + VERSION = "0.0.1"
  5 + end
  6 + end
  7 +end
3  test/test_helper.rb
... ... @@ -0,0 +1,3 @@
  1 +require 'test/unit'
  2 +require 'god-sns-contact'
  3 +
8 test/test_sns.rb
... ... @@ -0,0 +1,8 @@
  1 +require 'test_helper'
  2 +
  3 +class TestSns < Test::Unit::TestCase
  4 + def test_validation
  5 + God::Contacts::Sns.access_key_id = "DEADBEEF"
  6 + God::Contacts::Sns.secret_access_key = "BADDECADE"
  7 + end
  8 +end

0 comments on commit c2a175f

Please sign in to comment.
Something went wrong with that request. Please try again.