aws-alert-monitor 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/.rvmrc +1 -0
- data/CHANGELOG +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +7 -0
- data/aws-alert-monitor.gemspec +24 -0
- data/bin/aws-alert-monitor +6 -0
- data/lib/aws-alert-monitor.rb +9 -0
- data/lib/aws-alert-monitor/alert.rb +71 -0
- data/lib/aws-alert-monitor/aws.rb +8 -0
- data/lib/aws-alert-monitor/aws/ses.rb +18 -0
- data/lib/aws-alert-monitor/aws/sqs.rb +20 -0
- data/lib/aws-alert-monitor/cli.rb +31 -0
- data/lib/aws-alert-monitor/config.rb +26 -0
- data/lib/aws-alert-monitor/logger.rb +34 -0
- data/lib/aws-alert-monitor/parser.rb +47 -0
- data/lib/aws-alert-monitor/version.rb +3 -0
- data/spec/alert_spec.rb +29 -0
- data/spec/aws/ses_spec.rb +19 -0
- data/spec/aws/sqs_spec.rb +25 -0
- data/spec/config_spec.rb +16 -0
- data/spec/parser_spec.rb +43 -0
- data/spec/spec_helper.rb +8 -0
- metadata +116 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-p327@aws-alert-monitor --create
|
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Brett Weaver
|
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,44 @@
|
|
1
|
+
# Aws::Alert::Monitor
|
2
|
+
|
3
|
+
AWS Alert Monitor listenting to an SQS queue for alarms and sends email via SES based on rules applied in ~/.aws-alert-monitor.yml to those alerts.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install aws-alert-monitor
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Add ~/.aws-alert-monitor.yml with the following syntax:
|
12
|
+
|
13
|
+
```
|
14
|
+
app1:
|
15
|
+
access_key: Key
|
16
|
+
secret_key: Secret
|
17
|
+
sqs_endpoint: https://sqs.us-west-1.amazonaws.com/123456789012/app1
|
18
|
+
events:
|
19
|
+
'autoscaling:EC2_INSTANCE_LAUNCH':
|
20
|
+
email:
|
21
|
+
source: admin@example.com
|
22
|
+
destination: user@escalation.com
|
23
|
+
'autoscaling:EC2_INSTANCE_TERMINATE':
|
24
|
+
email:
|
25
|
+
source: admin@example.com
|
26
|
+
destination: problem@escalation.com
|
27
|
+
app2:
|
28
|
+
access_key: Key
|
29
|
+
secret_key: Secret
|
30
|
+
sqs_endpoint: https://sqs.us-west-1.amazonaws.com/123456789012/app2
|
31
|
+
events:
|
32
|
+
'autoscaling:EC2_INSTANCE_FAILED_LAUNCH':
|
33
|
+
email:
|
34
|
+
source: admin@example.com
|
35
|
+
destination: user@escalation.com
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aws-alert-monitor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "aws-alert-monitor"
|
8
|
+
gem.version = AwsAlertMonitor::VERSION
|
9
|
+
gem.authors = ["Brett Weaver"]
|
10
|
+
gem.email = ["brett@weav.net"]
|
11
|
+
gem.description = %q{I watch an SQS queue and escalate alert messages.}
|
12
|
+
gem.summary = %q{I watch an SQS queue and escalate alert messages.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 2.11.0'
|
22
|
+
|
23
|
+
gem.add_runtime_dependency 'aws-sdk', '~> 1.7.1'
|
24
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module AwsAlertMonitor
|
4
|
+
class Alert
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
@config = args[:config]
|
8
|
+
@logger = @config.logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def process(args)
|
12
|
+
@name = args[:name]
|
13
|
+
@events = args[:events]
|
14
|
+
@message = args[:message]
|
15
|
+
|
16
|
+
unless process_message @message
|
17
|
+
@logger.error "Unable to process message."
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
|
21
|
+
@events.each_pair do |event, policy|
|
22
|
+
@logger.info "Evaluating '#{@message_event}' against '#{event}'"
|
23
|
+
send_alert(policy) if event == @message_event
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def send_alert(policy)
|
30
|
+
message_source = policy['email']['source']
|
31
|
+
message_destination = policy['email']['destination']
|
32
|
+
|
33
|
+
@logger.info "Sending alert to #{message_destination}."
|
34
|
+
|
35
|
+
options = { :source => message_source,
|
36
|
+
:destination => { :to_addresses => [ message_destination ] },
|
37
|
+
:message => { :subject => {
|
38
|
+
:data => "Alert: #{@name}"
|
39
|
+
},
|
40
|
+
:body => {
|
41
|
+
:text => {
|
42
|
+
:data => @message_data
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
ses.send_email options
|
48
|
+
end
|
49
|
+
|
50
|
+
def process_message(message)
|
51
|
+
begin
|
52
|
+
message_body = JSON.parse message
|
53
|
+
message = JSON.parse message_body['Message']
|
54
|
+
rescue JSON::ParserError => e
|
55
|
+
@logger.error e.message
|
56
|
+
return false
|
57
|
+
end
|
58
|
+
|
59
|
+
@message_cause = message['Cause']
|
60
|
+
@message_event = message['Event']
|
61
|
+
@message_description = message['Description']
|
62
|
+
@message_data = "#{@message_description} \n\n #{@message_cause}"
|
63
|
+
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
def ses
|
68
|
+
@ses ||= AwsAlertMonitor::AWS::SES.new
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AwsAlertMonitor
|
2
|
+
module AWS
|
3
|
+
class SES
|
4
|
+
|
5
|
+
def send_email(args)
|
6
|
+
ses.send_email :source => args[:source],
|
7
|
+
:destination => args[:destination],
|
8
|
+
:message => args[:message]
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def ses
|
14
|
+
::AWS::SimpleEmailService::Client.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module AwsAlertMonitor
|
2
|
+
module AWS
|
3
|
+
class SQS
|
4
|
+
|
5
|
+
def receive_message(url)
|
6
|
+
queue(url).receive_message
|
7
|
+
end
|
8
|
+
|
9
|
+
def approximate_number_of_messages(url)
|
10
|
+
queue(url).approximate_number_of_messages
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def queue(url)
|
16
|
+
::AWS::SQS::Queue.new url
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module AwsAlertMonitor
|
4
|
+
class CLI
|
5
|
+
def initialize
|
6
|
+
@options = parse_options
|
7
|
+
end
|
8
|
+
|
9
|
+
def start
|
10
|
+
parser = AwsAlertMonitor::Parser.new :log_level => @options[:log_level]
|
11
|
+
parser.run
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def parse_options
|
17
|
+
options = {}
|
18
|
+
|
19
|
+
OptionParser.new do |opts|
|
20
|
+
|
21
|
+
opts.banner = "Usage: aws-alert-monitor.rb [options]"
|
22
|
+
|
23
|
+
opts.on("-l", "--log-level [LOG_LEVEL]", "Log Level") do |l|
|
24
|
+
options[:log_level] = l
|
25
|
+
end
|
26
|
+
end.parse!
|
27
|
+
|
28
|
+
options
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module AwsAlertMonitor
|
2
|
+
class Config
|
3
|
+
|
4
|
+
attr_accessor :logger, :file
|
5
|
+
|
6
|
+
def initialize(args={})
|
7
|
+
@opts = args[:opts] ||= Hash.new
|
8
|
+
log_level = args[:log_level]
|
9
|
+
self.logger = AwsAlertMonitor::Logger.new :log_level => log_level
|
10
|
+
self.file = load_config_file
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def load_config_file
|
16
|
+
config_file = "#{ENV['HOME']}/.aws-alert-monitor.yml"
|
17
|
+
|
18
|
+
if File.exists? config_file
|
19
|
+
YAML::load File.open config_file
|
20
|
+
else
|
21
|
+
{ }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module AwsAlertMonitor
|
4
|
+
class Logger
|
5
|
+
|
6
|
+
require 'forwardable'
|
7
|
+
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators :@logger, :debug, :error, :info, :warn
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
@log_level = args[:log_level] ||= 'info'
|
14
|
+
@logger = args[:logger] ||= new_logger(args)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def new_logger(args)
|
20
|
+
::Logger.new(STDOUT).tap do |l|
|
21
|
+
l.datetime_format = '%Y-%m-%dT%H:%M:%S%z'
|
22
|
+
l.formatter = proc do |severity, datetime, progname, msg|
|
23
|
+
"#{datetime} #{severity} : #{msg}\n"
|
24
|
+
end
|
25
|
+
l.level = logger_level
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def logger_level
|
30
|
+
::Logger.const_get @log_level.upcase
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module AwsAlertMonitor
|
2
|
+
class Parser
|
3
|
+
|
4
|
+
def initialize(args)
|
5
|
+
log_level = args[:log_level]
|
6
|
+
@config = AwsAlertMonitor::Config.new :log_level => log_level
|
7
|
+
@config_file = @config.file
|
8
|
+
@logger = @config.logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
@config_file.each_pair do |name, data|
|
13
|
+
sqs_endpoint = data['sqs_endpoint']
|
14
|
+
access_key = data['access_key']
|
15
|
+
secret_key = data['secret_key']
|
16
|
+
events = data['events']
|
17
|
+
|
18
|
+
::AWS.config :access_key_id => access_key,
|
19
|
+
:secret_access_key => secret_key
|
20
|
+
|
21
|
+
@logger.info "Processing #{name}."
|
22
|
+
@logger.debug "Receiving messages from #{sqs_endpoint}"
|
23
|
+
|
24
|
+
count = sqs.approximate_number_of_messages sqs_endpoint
|
25
|
+
@logger.info "Approximatley #{count} messages available."
|
26
|
+
|
27
|
+
while message = sqs.receive_message(sqs_endpoint)
|
28
|
+
alert.process :name => name,
|
29
|
+
:message => message.body,
|
30
|
+
:events => events
|
31
|
+
@logger.info "Deleting message from queue."
|
32
|
+
message.delete
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def alert
|
40
|
+
@alert ||= AwsAlertMonitor::Alert.new :config => @config
|
41
|
+
end
|
42
|
+
|
43
|
+
def sqs
|
44
|
+
@sqs ||= AwsAlertMonitor::AWS::SQS.new
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/alert_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AwsAlertMonitor::Alert do
|
4
|
+
before do
|
5
|
+
@message = "{\n \"Type\" : \"Notification\",\n \"MessageId\" : \"3c784ce1-22ec-5eec-9040-05d0b0c63fb8\",\n \"TopicArn\" : \"arn:aws:sns:us-west-1:187130254137:lc-pod-2-qa-1-app-1-SnsTopic-A2LI3FXD37V1\",\n \"Subject\" : \"Auto Scaling: launch for group \\\"lc-pod-2-qa-1-app-1-Instances-XCYGCEQC0H02\\\"\",\n \"Message\" : \"{\\\"StatusCode\\\":\\\"InProgress\\\",\\\"Service\\\":\\\"AWS Auto Scaling\\\",\\\"AutoScalingGroupName\\\":\\\"lc-pod-2-qa-1-app-1-Instances-XCYGCEQC0H02\\\",\\\"Description\\\":\\\"Launching a new EC2 instance: i-d6a2cb8f\\\",\\\"ActivityId\\\":\\\"840ac52b-36a7-419f-8378-f29bc8d477e8\\\",\\\"Event\\\":\\\"autoscaling:EC2_INSTANCE_LAUNCH\\\",\\\"Details\\\":{},\\\"AutoScalingGroupARN\\\":\\\"arn:aws:autoscaling:us-west-1:187130254137:autoScalingGroup:c96912e4-0633-4e9b-8060-f0a92b1f4fb1:autoScalingGroupName/lc-pod-2-qa-1-app-1-Instances-XCYGCEQC0H02\\\",\\\"Progress\\\":50,\\\"Time\\\":\\\"2012-11-29T16:40:10.204Z\\\",\\\"AccountId\\\":\\\"187130254137\\\",\\\"RequestId\\\":\\\"840ac52b-36a7-419f-8378-f29bc8d477e8\\\",\\\"StatusMessage\\\":\\\"\\\",\\\"EndTime\\\":\\\"2012-11-29T16:40:10.204Z\\\",\\\"EC2InstanceId\\\":\\\"i-d6a2cb8f\\\",\\\"StartTime\\\":\\\"2012-11-29T16:39:05.602Z\\\",\\\"Cause\\\":\\\"At 2012-11-29T16:39:05Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1.\\\"}\",\n \"Timestamp\" : \"2012-11-29T16:40:10.246Z\",\n \"SignatureVersion\" : \"1\",\n \"Signature\" : \"vVWFMUbWyfBSfo8vPCBDdrdXB1ocGZz+n4cO4FEIoczOTHgrcNY8tqYLojlTQuQZCdk7f5qPI1XJxfGS1NIs2LmsBq6oEow2qXrBQlvUXxUDMIvoWoqj6a+yjM4ICbmStdlcFVREW/0u/YO7l/se5q6KUqol4q6Vb+c+xohwR78=\",\n \"SigningCertURL\" : \"https://sns.us-west-1.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem\",\n \"UnsubscribeURL\" : \"https://sns.us-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-1:187130254137:lc-pod-2-qa-1-app-1-SnsTopic-A2LI3FXD37V1:1e723d7a-abf4-46a7-b73e-d6d3d3a90959\"\n}"
|
6
|
+
@options = {:name => 'test app', :message=>@message, :events=>{"autoscaling:EC2_INSTANCE_LAUNCH"=>{"email"=>{"source"=>"brett_weaver@intuit.com", "destination"=>"brett_weaver@intuit.com"}}}}
|
7
|
+
@logger_stub = stub 'logger', :debug => true,
|
8
|
+
:info => true,
|
9
|
+
:error => true
|
10
|
+
@config_stub = stub 'config', :logger => @logger_stub
|
11
|
+
@ses_mock = mock 'ses'
|
12
|
+
AwsAlertMonitor::AWS::SES.stub :new => @ses_mock
|
13
|
+
AwsAlertMonitor::Config.stub :new => @config_stub
|
14
|
+
@alert = AwsAlertMonitor::Alert.new :config => @config_stub
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should process the given message against known events" do
|
18
|
+
@ses_mock.should_receive(:send_email)
|
19
|
+
.with({:source=>"brett_weaver@intuit.com", :destination=>{:to_addresses=>["brett_weaver@intuit.com"]}, :message=>{:subject=>{:data=>"Alert: test app"}, :body=>{:text=>{:data=>"Launching a new EC2 instance: i-d6a2cb8f \n\n At 2012-11-29T16:39:05Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1."}}}})
|
20
|
+
@alert.process @options
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return false if the given message is invalid JSON" do
|
24
|
+
@ses_mock.should_receive(:send_email).never
|
25
|
+
@options[:message] = 'invalid stuff'
|
26
|
+
@alert.process(@options).should be_false
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AwsAlertMonitor::AWS::SES do
|
4
|
+
before do
|
5
|
+
@ses_mock = mock 'ses'
|
6
|
+
@ses = AwsAlertMonitor::AWS::SES.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should call send_email with the given args" do
|
10
|
+
AWS::SimpleEmailService::Client.stub :new => @ses_mock
|
11
|
+
@ses_mock.should_receive(:send_email).
|
12
|
+
with :source => 'src',
|
13
|
+
:destination => 'dest',
|
14
|
+
:message => 'msg'
|
15
|
+
@ses.send_email :source => 'src',
|
16
|
+
:destination => 'dest',
|
17
|
+
:message => 'msg'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AwsAlertMonitor::AWS::SQS do
|
4
|
+
before do
|
5
|
+
@queue_mock = mock 'queue'
|
6
|
+
@sqs = AwsAlertMonitor::AWS::SQS.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should call receive_message on the given queue url" do
|
10
|
+
AWS::SQS::Queue.should_receive(:new).
|
11
|
+
with('http://sqs_url').
|
12
|
+
and_return @queue_mock
|
13
|
+
@queue_mock.stub :receive_message => 'da-message'
|
14
|
+
@sqs.receive_message('http://sqs_url').should == 'da-message'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should call approximate_number_of_messages on the given queue url" do
|
18
|
+
AWS::SQS::Queue.should_receive(:new).
|
19
|
+
with('http://sqs_url').
|
20
|
+
and_return @queue_mock
|
21
|
+
@queue_mock.stub :approximate_number_of_messages => 2
|
22
|
+
@sqs.approximate_number_of_messages('http://sqs_url').
|
23
|
+
should == 2
|
24
|
+
end
|
25
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe AwsAlertMonitor::Config do
|
5
|
+
before do
|
6
|
+
@data = "app:\n access_key: key \n secret_key: secret\n region: us-west-1\n sqs_endpoint: https://sqs.us-west-1.amazonaws.com/123456789012/app\n events: \n 'autoscaling:EC2_INSTANCE_LAUNCH':\n email:\n source: brett_weaver@intuit.com\n destination: brett_weaver@intuit.com\n"
|
7
|
+
File.should_receive(:open).
|
8
|
+
with("#{ENV['HOME']}/.aws-alert-monitor.yml").
|
9
|
+
and_return @data
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should load the configuration from ~/.aws-alert-monitor.yml" do
|
13
|
+
@config = AwsAlertMonitor::Config.new
|
14
|
+
@config.file.should == YAML.load(@data)
|
15
|
+
end
|
16
|
+
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AwsAlertMonitor::Parser do
|
4
|
+
|
5
|
+
before do
|
6
|
+
data = "app:\n access_key: key \n secret_key: secret\n region: us-west-1\n sqs_endpoint: https://sqs.us-west-1.amazonaws.com/123456789012/app\n events: \n 'autoscaling:EC2_INSTANCE_LAUNCH':\n email:\n source: brett_weaver@intuit.com\n destination: brett_weaver@intuit.com\n"
|
7
|
+
@logger_stub = stub 'logger', :debug => true,
|
8
|
+
:info => true
|
9
|
+
@config_stub = stub 'config', :logger => @logger_stub,
|
10
|
+
:file => YAML.load(data)
|
11
|
+
AwsAlertMonitor::Config.stub :new => @config_stub
|
12
|
+
@parser = AwsAlertMonitor::Parser.new :log_level => 'debug'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should run the parser against the given config" do
|
16
|
+
@alert_mock = mock 'alert'
|
17
|
+
@sqs_mock = mock 'sqs'
|
18
|
+
@message_mock = mock 'message'
|
19
|
+
::AWS.should_receive(:config).with :access_key_id => 'key',
|
20
|
+
:secret_access_key => 'secret'
|
21
|
+
AwsAlertMonitor::Alert.should_receive(:new).
|
22
|
+
with(:config => @config_stub).
|
23
|
+
and_return @alert_mock
|
24
|
+
AwsAlertMonitor::AWS::SQS.stub :new => @sqs_mock
|
25
|
+
@sqs_mock.should_receive(:approximate_number_of_messages).
|
26
|
+
with('https://sqs.us-west-1.amazonaws.com/123456789012/app').
|
27
|
+
and_return 1
|
28
|
+
@sqs_mock.should_receive(:receive_message).
|
29
|
+
with('https://sqs.us-west-1.amazonaws.com/123456789012/app').
|
30
|
+
exactly(2).times.
|
31
|
+
and_return @message_mock
|
32
|
+
@sqs_mock.should_receive(:receive_message).
|
33
|
+
with('https://sqs.us-west-1.amazonaws.com/123456789012/app').
|
34
|
+
and_return false
|
35
|
+
@message_mock.stub :body => 'body'
|
36
|
+
@alert_mock.should_receive(:process).
|
37
|
+
with({:name => "app", :message=>"body", :events=>{"autoscaling:EC2_INSTANCE_LAUNCH"=>{"email"=>{"source"=>"brett_weaver@intuit.com", "destination"=>"brett_weaver@intuit.com"}}}}).
|
38
|
+
exactly(2).times
|
39
|
+
@message_mock.should_receive(:delete).exactly(2).times
|
40
|
+
@parser.run
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-alert-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brett Weaver
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70301913625820 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70301913625820
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70301913624940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.11.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70301913624940
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: aws-sdk
|
38
|
+
requirement: &70301913624420 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.7.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70301913624420
|
47
|
+
description: I watch an SQS queue and escalate alert messages.
|
48
|
+
email:
|
49
|
+
- brett@weav.net
|
50
|
+
executables:
|
51
|
+
- aws-alert-monitor
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rvmrc
|
57
|
+
- CHANGELOG
|
58
|
+
- Gemfile
|
59
|
+
- LICENSE.txt
|
60
|
+
- README.md
|
61
|
+
- Rakefile
|
62
|
+
- aws-alert-monitor.gemspec
|
63
|
+
- bin/aws-alert-monitor
|
64
|
+
- lib/aws-alert-monitor.rb
|
65
|
+
- lib/aws-alert-monitor/alert.rb
|
66
|
+
- lib/aws-alert-monitor/aws.rb
|
67
|
+
- lib/aws-alert-monitor/aws/ses.rb
|
68
|
+
- lib/aws-alert-monitor/aws/sqs.rb
|
69
|
+
- lib/aws-alert-monitor/cli.rb
|
70
|
+
- lib/aws-alert-monitor/config.rb
|
71
|
+
- lib/aws-alert-monitor/logger.rb
|
72
|
+
- lib/aws-alert-monitor/parser.rb
|
73
|
+
- lib/aws-alert-monitor/version.rb
|
74
|
+
- spec/alert_spec.rb
|
75
|
+
- spec/aws/ses_spec.rb
|
76
|
+
- spec/aws/sqs_spec.rb
|
77
|
+
- spec/config_spec.rb
|
78
|
+
- spec/parser_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: ''
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
hash: 2186495264378659725
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: 2186495264378659725
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.16
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: I watch an SQS queue and escalate alert messages.
|
110
|
+
test_files:
|
111
|
+
- spec/alert_spec.rb
|
112
|
+
- spec/aws/ses_spec.rb
|
113
|
+
- spec/aws/sqs_spec.rb
|
114
|
+
- spec/config_spec.rb
|
115
|
+
- spec/parser_spec.rb
|
116
|
+
- spec/spec_helper.rb
|