MovableInkAWS 0.2.8 → 0.3.0
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/movable_ink/aws/sns.rb +54 -4
- data/lib/movable_ink/version.rb +1 -1
- data/spec/sns_spec.rb +19 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d362679456a51366b015bb76f2c7f8e578acc5d6f6d21d8e05bc2f4794842205
|
4
|
+
data.tar.gz: 879834f53d480a7e9fe5ca0f11daff419828525a78fb98bb7a6c1de8a744078d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05d9112da634b7ddec10dfaae68d70875f3832f4768dfa6bb279e315d63b50ff34b3f1bcd15643cff04eaca097b2c28da4c9a4321add29dccee00b90dd73572d
|
7
|
+
data.tar.gz: 3393a133714eb6bce8dce30195a0e6fdf20128129a32bf0bc1c67d9477e911f06eabe61765a8cea269bcea20e985957e46d8048ce2b80f7335f37b85e77e25a5
|
data/Gemfile.lock
CHANGED
data/lib/movable_ink/aws/sns.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'json'
|
3
|
+
|
1
4
|
module MovableInk
|
2
5
|
class AWS
|
3
6
|
module SNS
|
@@ -16,6 +19,16 @@ module MovableInk
|
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
22
|
+
def sns_pagerduty_topic_arn
|
23
|
+
run_with_backoff do
|
24
|
+
sns.list_topics.each do |resp|
|
25
|
+
resp.topics.each do |topic|
|
26
|
+
return topic.topic_arn if topic.topic_arn.include? "pagerduty-custom-alerts"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
19
32
|
def notify_and_sleep(seconds, error_class)
|
20
33
|
message = "Throttled by AWS. Sleeping #{seconds} seconds, (#{error_class})"
|
21
34
|
notify_slack(subject: 'API Throttled',
|
@@ -26,15 +39,52 @@ module MovableInk
|
|
26
39
|
|
27
40
|
def notify_nsq_can_not_be_drained
|
28
41
|
notify_slack(subject: 'NSQ not drained',
|
29
|
-
message:
|
42
|
+
message: "Unable to drain NSQ for instance <https://#{my_region}.console.aws.amazon.com/ec2/v2/home?region=#{my_region}#Instances:search=#{instance_id};sort=instanceId|#{instance_id}>")
|
43
|
+
notify_pagerduty(region: my_region, instance_id: instance_id)
|
30
44
|
end
|
31
45
|
|
32
|
-
def
|
46
|
+
def notify_pagerduty(region:, instance_id:)
|
47
|
+
summary = "Unable to drain NSQ for instance #{instance_id} in region #{region}"
|
48
|
+
|
49
|
+
# the PagerDuty integration key is added to the payload in the AWS integration
|
50
|
+
json_message = {
|
51
|
+
pagerduty: {
|
52
|
+
event_action: 'trigger',
|
53
|
+
payload: {
|
54
|
+
source: 'MovableInkAWS',
|
55
|
+
summary: summary,
|
56
|
+
timestamp: Time.now.utc.iso8601,
|
57
|
+
severity: 'error',
|
58
|
+
component: 'nsq',
|
59
|
+
group: 'nsq',
|
60
|
+
custom_details: {
|
61
|
+
InstanceId: instance_id,
|
62
|
+
},
|
63
|
+
},
|
64
|
+
dedup_key: "nsq-not-draining-#{instance_id}",
|
65
|
+
links: [{
|
66
|
+
href: "https://#{region}.console.aws.amazon.com/ec2/v2/home?region=#{region}#Instances:search=#{instance_id};sort=instanceId",
|
67
|
+
text: 'View Instance'
|
68
|
+
}],
|
69
|
+
}
|
70
|
+
}.to_json
|
71
|
+
|
72
|
+
run_with_backoff do
|
73
|
+
sns.publish(topic_arn: sns_pagerduty_topic_arn,
|
74
|
+
subject: add_subject_info(subject: "Unable to drain NSQ"),
|
75
|
+
message: json_message)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_subject_info(subject:)
|
33
80
|
required_info = " (#{instance_id}, #{my_region})"
|
34
|
-
|
81
|
+
"#{subject.slice(0, 99-required_info.length)}#{required_info}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def notify_slack(subject:, message:)
|
35
85
|
run_with_backoff do
|
36
86
|
sns.publish(topic_arn: sns_slack_topic_arn,
|
37
|
-
subject: subject,
|
87
|
+
subject: add_subject_info(subject: subject),
|
38
88
|
message: message)
|
39
89
|
end
|
40
90
|
end
|
data/lib/movable_ink/version.rb
CHANGED
data/spec/sns_spec.rb
CHANGED
@@ -6,6 +6,9 @@ describe MovableInk::AWS::SNS do
|
|
6
6
|
let(:topic_data) { sns.stub_data(:list_topics, topics: [
|
7
7
|
{
|
8
8
|
topic_arn: 'slack-aws-alerts'
|
9
|
+
},
|
10
|
+
{
|
11
|
+
topic_arn: 'pagerduty-custom-alerts'
|
9
12
|
}
|
10
13
|
])
|
11
14
|
}
|
@@ -19,6 +22,14 @@ describe MovableInk::AWS::SNS do
|
|
19
22
|
expect(aws.sns_slack_topic_arn).to eq('slack-aws-alerts')
|
20
23
|
end
|
21
24
|
|
25
|
+
it 'should find the pagerduty slack sns topic' do
|
26
|
+
sns.stub_responses(:list_topics, topic_data)
|
27
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
28
|
+
allow(aws).to receive(:sns).and_return(sns)
|
29
|
+
|
30
|
+
expect(aws.sns_pagerduty_topic_arn).to eq('pagerduty-custom-alerts')
|
31
|
+
end
|
32
|
+
|
22
33
|
it "should notify with the specified subject and message" do
|
23
34
|
sns.stub_responses(:list_topics, topic_data)
|
24
35
|
allow(aws).to receive(:my_region).and_return('us-east-1')
|
@@ -26,7 +37,15 @@ describe MovableInk::AWS::SNS do
|
|
26
37
|
allow(aws).to receive(:sns).and_return(sns)
|
27
38
|
|
28
39
|
expect(aws.notify_slack(subject: 'Test subject', message: 'Test message').message_id).to eq('messageId')
|
40
|
+
end
|
29
41
|
|
42
|
+
it 'should notify pagerduty with related information' do
|
43
|
+
sns.stub_responses(:list_topics, topic_data)
|
44
|
+
allow(aws).to receive(:my_region).and_return('us-east-1')
|
45
|
+
allow(aws).to receive(:instance_id).and_return('test instance')
|
46
|
+
allow(aws).to receive(:sns).and_return(sns)
|
47
|
+
|
48
|
+
expect(aws.notify_pagerduty(region: 'us-east-1', instance_id: 'i-987654321').message_id).to eq('messageId')
|
30
49
|
end
|
31
50
|
|
32
51
|
it "should truncate subjects longer than 100 characters" do
|
@@ -41,6 +60,5 @@ describe MovableInk::AWS::SNS do
|
|
41
60
|
expect(sns).to receive(:publish).with({:topic_arn=>"slack-aws-alerts", :message=>"Test message", :subject => expected_subject})
|
42
61
|
|
43
62
|
aws.notify_slack(subject: subject, message: message)
|
44
|
-
|
45
63
|
end
|
46
64
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: MovableInkAWS
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Chesler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|