aws-cleaner 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/aws_cleaner.rb +31 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cac446b2547a119136092534b75f3ea31ae2986
|
4
|
+
data.tar.gz: a26ce3525908ff62c301b623cf7bf3ab765f1584
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9235bced7a80ac1390f229ae198ba9f17ea02a5340da3a79978c94a925a888dfde1bb6c5c243908018e7179c82ac0223be7e879f54732f125b19d3c31dabbcf
|
7
|
+
data.tar.gz: 05020a834092037f3b086860e0eac24491312072e601a862c89eb1265200a0efc5af4d395ee9c5caa94052ac04bdd283338069166b6bac758d30bc33ed599fb2
|
data/bin/aws_cleaner.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Listen for AWS CloudWatch Events EC2 termination events delivered via SQS
|
4
4
|
# and remove the node from Chef and Sensu and send a notification
|
5
|
-
# to Hipchat
|
5
|
+
# to Hipchat or Slack
|
6
6
|
#
|
7
7
|
# Copyright (c) 2015, 2016 Eric Heydrick
|
8
8
|
# Licensed under The MIT License
|
@@ -16,6 +16,7 @@ begin
|
|
16
16
|
require 'hipchat'
|
17
17
|
require 'rest-client'
|
18
18
|
require 'trollop'
|
19
|
+
require 'slack/poster'
|
19
20
|
rescue LoadError => e
|
20
21
|
raise "Missing gems: #{e}"
|
21
22
|
end
|
@@ -105,10 +106,10 @@ def remove_from_sensu(node_name)
|
|
105
106
|
response = RestClient::Request.execute(url: "#{@config[:sensu][:url]}/clients/#{node_name}", method: :delete, timeout: 5, open_timeout: 5)
|
106
107
|
case response.code
|
107
108
|
when 202
|
108
|
-
|
109
|
+
notify_chat('Removed ' + node_name + ' from Sensu')
|
109
110
|
return true
|
110
111
|
else
|
111
|
-
|
112
|
+
notify_chat('Failed to remove ' + node_name + ' from Sensu')
|
112
113
|
return false
|
113
114
|
end
|
114
115
|
end
|
@@ -123,10 +124,11 @@ def remove_from_chef(node_name)
|
|
123
124
|
rescue => e
|
124
125
|
puts "Failed to remove chef node: #{e}"
|
125
126
|
else
|
126
|
-
|
127
|
+
notify_chat('Removed ' + node_name + ' from Chef')
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
131
|
+
# notify hipchat
|
130
132
|
def notify_hipchat(msg)
|
131
133
|
hipchat = HipChat::Client.new(
|
132
134
|
@config[:hipchat][:api_token],
|
@@ -136,6 +138,24 @@ def notify_hipchat(msg)
|
|
136
138
|
hipchat[room].send('AWS Cleaner', msg)
|
137
139
|
end
|
138
140
|
|
141
|
+
# notify slack
|
142
|
+
def notify_slack(msg)
|
143
|
+
slack = Slack::Poster.new(@config[:slack][:webhook_url])
|
144
|
+
slack.channel = @config[:slack][:channel]
|
145
|
+
slack.username = @config[:slack][:username] ||= 'aws-cleaner'
|
146
|
+
slack.icon_emoji = @config[:slack][:icon_emoji] ||= nil
|
147
|
+
slack.send_message(msg)
|
148
|
+
end
|
149
|
+
|
150
|
+
# generic chat notification method
|
151
|
+
def notify_chat(msg)
|
152
|
+
if @config[:hipchat][:enable]
|
153
|
+
notify_hipchat(msg)
|
154
|
+
elsif @config[:slack][:enable]
|
155
|
+
notify_slack(msg)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
139
159
|
# generate the URL for the webhook
|
140
160
|
def generate_template(item, template_variable_method, template_variable_argument, template_variable)
|
141
161
|
begin
|
@@ -169,15 +189,15 @@ def fire_webhook(config)
|
|
169
189
|
if r.code != 200
|
170
190
|
return false
|
171
191
|
else
|
172
|
-
# notify
|
173
|
-
if config[:
|
192
|
+
# notify chat when webhook is successful
|
193
|
+
if config[:chat][:enable]
|
174
194
|
msg = generate_template(
|
175
|
-
config[:
|
176
|
-
config[:
|
177
|
-
config[:
|
178
|
-
config[:
|
195
|
+
config[:chat][:message],
|
196
|
+
config[:chat][:method],
|
197
|
+
config[:chat][:argument],
|
198
|
+
config[:chat][:variable]
|
179
199
|
)
|
180
|
-
|
200
|
+
notify_chat(msg)
|
181
201
|
end
|
182
202
|
return true
|
183
203
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws-cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Heydrick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.5.1
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: AWS Cleaner cleans up after EC2 instances are terminated
|