aws-cleaner 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/aws_cleaner.rb +32 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9da716cb03b98e3f96803ea61d439e0742342000
4
- data.tar.gz: 046b434375c5162c69576b071522da65e41a3413
3
+ metadata.gz: a860204167856b0780e8d060df21fa840282d4f7
4
+ data.tar.gz: 14f02a03f31bfb6a88cc094e0f5b407b348a91ec
5
5
  SHA512:
6
- metadata.gz: fb0c1283415898539326b64f0ada29e1cc0fdf35be695294880e5d2075e32680dceaa04df27bc8281501c58825d255534063bf4fccaaf35e926d8d3a0b6d6187
7
- data.tar.gz: 29f93af8ec083c44b4b853dd1292732a58e0e1f7621ec643fa7c1bbd4108acd62dc4fa38dbf18407b7facdf32ff1a3c2c50d0fc87a90c55025421b6ffd468cab
6
+ metadata.gz: 12570ca1ccde43a84f34d13a0c10a816900b880d75203a70f151f382dc7bfa8d1f127b8b8366662bf39fe5af8f1e96328c155afa1749cbbcb7610203b1a33204
7
+ data.tar.gz: 2553ca1184dec0443c0ad1db5e796a198fdb2179bf92cc23307907a55f05554bd89f2e87036480b89ada5fb3d1bcf58cd0338e6c42736c5a4c2acdba26e15e07
@@ -142,17 +142,17 @@ def notify_hipchat(msg)
142
142
  end
143
143
 
144
144
  # generate the URL for the webhook
145
- def generate_webhook_url(url, template_variable_method, template_variable_argument, template_variable)
145
+ def generate_template(item, template_variable_method, template_variable_argument, template_variable)
146
146
  replacement = send(template_variable_method, eval(template_variable_argument))
147
- url.gsub!(/{#{template_variable}/, replacement)
148
- url
147
+ item.gsub!(/{#{template_variable}}/, replacement)
148
+ item
149
149
  end
150
150
 
151
151
  # call an HTTP endpoint
152
152
  def fire_webhook(config)
153
153
  # generate templated URL
154
154
  if config[:template_variables] && config[:url] =~ /\{\S+\}/
155
- url = generate_webhook_url(
155
+ url = generate_template(
156
156
  config[:url],
157
157
  config[:template_variables][:method],
158
158
  config[:template_variables][:argument],
@@ -163,11 +163,20 @@ def fire_webhook(config)
163
163
  end
164
164
 
165
165
  hook = { method: config[:method].to_sym, url: url }
166
- begin
167
- RestClient::Request.execute(hook)
168
- rescue
166
+ r = RestClient::Request.execute(hook)
167
+ if r.code != 200
169
168
  return false
170
169
  else
170
+ # notify hipchat when webhook is successful
171
+ if config[:hipchat][:enable]
172
+ msg = generate_template(
173
+ config[:hipchat][:message],
174
+ config[:hipchat][:method],
175
+ config[:hipchat][:argument],
176
+ config[:hipchat][:variable]
177
+ )
178
+ notify_hipchat(msg)
179
+ end
171
180
  return true
172
181
  end
173
182
  end
@@ -193,10 +202,21 @@ loop do
193
202
  next
194
203
  end
195
204
 
196
- instance_id = process_message(body)
205
+ @instance_id = process_message(body)
206
+
207
+ if @instance_id
208
+ if @config[:webhooks]
209
+ @config[:webhooks].each do |hook, config|
210
+ if fire_webhook(config)
211
+ puts "Successfully ran webhook #{hook}"
212
+ else
213
+ puts "Failed to run webhook #{hook}"
214
+ end
215
+ end
216
+ delete_message(id)
217
+ end
197
218
 
198
- if instance_id
199
- chef_node = get_chef_node_name(instance_id)
219
+ chef_node = get_chef_node_name(@instance_id)
200
220
 
201
221
  if chef_node
202
222
  if remove_from_chef(chef_node)
@@ -204,7 +224,7 @@ loop do
204
224
  delete_message(id)
205
225
  end
206
226
  else
207
- puts "Instance #{instance_id} does not exist in Chef, deleting message"
227
+ puts "Instance #{@instance_id} does not exist in Chef, deleting message"
208
228
  delete_message(id)
209
229
  end
210
230
 
@@ -213,18 +233,11 @@ loop do
213
233
  puts "Removed #{chef_node} from Sensu"
214
234
  delete_message(id)
215
235
  else
216
- puts "Instance #{instance_id} does not exist in Sensu, deleting message"
236
+ puts "Instance #{@instance_id} does not exist in Sensu, deleting message"
217
237
  delete_message(id)
218
238
  end
219
239
  end
220
240
 
221
- if @config[:webhooks]
222
- @config[:webbooks].each do |_hook, config|
223
- fire_webhook(config)
224
- end
225
- delete_message(id)
226
- end
227
-
228
241
  else
229
242
  puts 'Message not relevant, deleting'
230
243
  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.2.1
4
+ version: 0.3.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-12-23 00:00:00.000000000 Z
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-core