aws-cleaner 1.0.0 → 2.0.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/aws_cleaner.rb +31 -11
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3e12b5da2b7a3faf0306e0b1bf6ab5523037fce
4
- data.tar.gz: f5b9194b693b8a90efdfc064c45a96434e60ff66
3
+ metadata.gz: 4cac446b2547a119136092534b75f3ea31ae2986
4
+ data.tar.gz: a26ce3525908ff62c301b623cf7bf3ab765f1584
5
5
  SHA512:
6
- metadata.gz: 87e1b163d917511724d63a96c529316c9876fe3d9b7f125a3788aaddd1fe346ea01a1fe3d7b2a1bd76ad2ac65cad2e2f6d76f9e698d263063965b3de8926a99d
7
- data.tar.gz: 8c649c46e91d6a32c4508781b7b5e27355870f85e6fb8a539ed6e2629b2c2e9828afe8d4b19fb3830562b3535cfec2e0a713547d39a7c0df3eb69717c4151a7a
6
+ metadata.gz: f9235bced7a80ac1390f229ae198ba9f17ea02a5340da3a79978c94a925a888dfde1bb6c5c243908018e7179c82ac0223be7e879f54732f125b19d3c31dabbcf
7
+ data.tar.gz: 05020a834092037f3b086860e0eac24491312072e601a862c89eb1265200a0efc5af4d395ee9c5caa94052ac04bdd283338069166b6bac758d30bc33ed599fb2
@@ -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
- notify_hipchat('Removed ' + node_name + ' from Sensu') if @config[:hipchat][:enable]
109
+ notify_chat('Removed ' + node_name + ' from Sensu')
109
110
  return true
110
111
  else
111
- notify_hipchat('Failed to remove ' + node_name + ' from Sensu') if @config[:hipchat][:enable]
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
- notify_hipchat('Removed ' + node_name + ' from Chef') if @config[:hipchat][:enable]
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 hipchat when webhook is successful
173
- if config[:hipchat][:enable]
192
+ # notify chat when webhook is successful
193
+ if config[:chat][:enable]
174
194
  msg = generate_template(
175
- config[:hipchat][:message],
176
- config[:hipchat][:method],
177
- config[:hipchat][:argument],
178
- config[:hipchat][:variable]
195
+ config[:chat][:message],
196
+ config[:chat][:method],
197
+ config[:chat][:argument],
198
+ config[:chat][:variable]
179
199
  )
180
- notify_hipchat(msg)
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: 1.0.0
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-04-26 00:00:00.000000000 Z
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.0.14.1
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