aws-cleaner 0.1.3 → 0.2.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 +55 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4e9cb3c17a953b6e31c33653adfabcc8e624de4
|
4
|
+
data.tar.gz: 2a02b8c09de9ca83022b0da35a97fbf3a71fa55a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26e021cc9cdd9a950de13bc6246cb3458b61c79308f4acbb7dbeb8ee3ff4c9ff340f3b62be4827f1d10411293f5b8d76ca3ce8c3c3689c9c2f9eefcc1e35c081
|
7
|
+
data.tar.gz: c5abb5b0ed1a2244b14f99734b06a5e38450e26cd0d1ba0cd6260227dee4e60337bbf3c910a6d3e0d43b91276095754599fa932ee731046c0cbf2ab59ec4466c
|
data/bin/aws_cleaner.rb
CHANGED
@@ -22,13 +22,13 @@ end
|
|
22
22
|
|
23
23
|
def config(file)
|
24
24
|
YAML.load(File.read(file))
|
25
|
-
|
26
|
-
|
25
|
+
rescue StandardError => e
|
26
|
+
raise "Failed to open config file: #{e}"
|
27
27
|
end
|
28
28
|
|
29
29
|
# get options
|
30
30
|
opts = Trollop::options do
|
31
|
-
opt :config, 'Path to config file', :
|
31
|
+
opt :config, 'Path to config file', type: 'string', default: 'config.yml'
|
32
32
|
end
|
33
33
|
|
34
34
|
@config = config(opts[:config])
|
@@ -46,15 +46,15 @@ def delete_message(id)
|
|
46
46
|
delete = @sqs.delete_message(
|
47
47
|
queue_url: @config[:sqs][:queue],
|
48
48
|
receipt_handle: id
|
49
|
-
|
49
|
+
)
|
50
50
|
delete ? true : false
|
51
51
|
end
|
52
52
|
|
53
53
|
# return the body of the SQS message in JSON
|
54
54
|
def parse(body)
|
55
55
|
JSON.parse(body)
|
56
|
-
|
57
|
-
|
56
|
+
rescue JSON::ParserError
|
57
|
+
return false
|
58
58
|
end
|
59
59
|
|
60
60
|
# return the instance_id of the terminated instance
|
@@ -81,6 +81,16 @@ def get_chef_node_name(instance_id)
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
|
+
# call the Chef API to get the FQDN of the instance
|
85
|
+
def get_chef_fqdn(instance_id)
|
86
|
+
results = @chef.search.query(:node, "ec2_instance_id:#{instance_id} OR chef_provisioning_reference_server_id:#{instance_id}")
|
87
|
+
if results.rows.size > 0
|
88
|
+
return results.rows.first['automatic']['fqdn']
|
89
|
+
else
|
90
|
+
return false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
84
94
|
# check if the node exists in Sensu
|
85
95
|
def in_sensu?(node_name)
|
86
96
|
begin
|
@@ -131,6 +141,37 @@ def notify_hipchat(msg)
|
|
131
141
|
hipchat[room].send('AWS Cleaner', msg)
|
132
142
|
end
|
133
143
|
|
144
|
+
# generate the URL for the webhook
|
145
|
+
def generate_webhook_url(url, template_variable_method, template_variable_argument, template_variable)
|
146
|
+
replacement = send(template_variable_method, eval(template_variable_argument))
|
147
|
+
url.gsub!(/{#{template_variable}/, replacement)
|
148
|
+
url
|
149
|
+
end
|
150
|
+
|
151
|
+
# call an HTTP endpoint
|
152
|
+
def fire_webhook(config)
|
153
|
+
# generate templated URL
|
154
|
+
if config[:template_variables] && config[:url] =~ /\{\S+\}/
|
155
|
+
url = generate_webhook_url(
|
156
|
+
config[:url],
|
157
|
+
config[:template_variables][:method],
|
158
|
+
config[:template_variables][:argument],
|
159
|
+
config[:template_variables][:variable]
|
160
|
+
)
|
161
|
+
else
|
162
|
+
url = config[:url]
|
163
|
+
end
|
164
|
+
|
165
|
+
hook = { method: config[:method].to_sym, url: url }
|
166
|
+
begin
|
167
|
+
RestClient::Request.execute(hook)
|
168
|
+
rescue
|
169
|
+
return false
|
170
|
+
else
|
171
|
+
return true
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
134
175
|
# main loop
|
135
176
|
loop do
|
136
177
|
# get messages from SQS
|
@@ -176,6 +217,14 @@ loop do
|
|
176
217
|
delete_message(id)
|
177
218
|
end
|
178
219
|
end
|
220
|
+
|
221
|
+
if @config[:webhooks]
|
222
|
+
@config[:webbooks].each do |_hook, config|
|
223
|
+
fire_webhook(config)
|
224
|
+
end
|
225
|
+
delete_message(id)
|
226
|
+
end
|
227
|
+
|
179
228
|
else
|
180
229
|
puts 'Message not relevant, deleting'
|
181
230
|
delete_message(id)
|
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: 0.
|
4
|
+
version: 0.2.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: 2015-
|
11
|
+
date: 2015-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-core
|