aws-watcher 0.1.0 → 0.2.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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/aws_watcher.rb +13 -10
  3. data/lib/aws-watcher.rb +9 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f28f50f0ca7431183991d62d6ace837e3cc4c99b
4
- data.tar.gz: 06704407b72737f799420afd04406926fa945052
3
+ metadata.gz: 2bf8eeafa65fe3b5e1c3be1c34c3d6a5bb012379
4
+ data.tar.gz: 4c71a451b443e2da69140601bc10f9aac7eb5208
5
5
  SHA512:
6
- metadata.gz: 4aa9aae62d9199e876121220d4321aaa17c13d87986c26ae24fa167388e620f8587eb1054855b8eccc24cee8e3bf0a431d2817438ee55abaf87fa807d899ef2b
7
- data.tar.gz: beb7e55a6c11aa2c6a09a48ea3f83b07b7d0519ce05ebbf55620c5ebfaf0b21b28d3c1215961b799905a4c9742b5a703489db434900fcbfad8c25e5ba0ae1d23
6
+ metadata.gz: 4b0839c4435fa5cbb5012030fbc1bb99ec8c060ebfc0118fbdd6fe6aa5457de4a783a41b438da2f55cb235356e4f5163cdecb8f33155cf9c4970051093d05723
7
+ data.tar.gz: b9cefb0f11336db142c711e6023f4229894318620adaf2d9d0f542d883f8788766e4aae051d7d0f062a3aa73307eeb12e991cf67f1f1a48fb2489c3754be04b1
data/bin/aws_watcher.rb CHANGED
@@ -53,9 +53,9 @@ loop do
53
53
  visibility_timeout: 3
54
54
  ).messages
55
55
 
56
- puts "Got #{messages.size} messages"
56
+ puts "Got #{messages.size} message(s)"
57
57
  messages.each_with_index do |message, index|
58
- puts "Looking at message number #{index}"
58
+ puts "Looking at message number #{index}" unless messages.size.zero?
59
59
  body = AwsCleaner.new.parse(message.body)
60
60
  id = message.receipt_handle
61
61
  now = Time.now.utc
@@ -67,18 +67,22 @@ loop do
67
67
  end
68
68
 
69
69
  @instance_id = AwsCleaner.new.process_message(body)
70
- chef_node = AwsCleaner::Chef.get_chef_node_name(@instance_id, @config)
71
70
  elapsed_time = now - launch_time
72
71
  p "launch_time: #{launch_time}"
73
72
  p "now: #{now}"
74
- # if the node exists in chef it hass bootstrapped
73
+ # if the node is no longer in aws we don't care anymore
74
+ # we can delete the message message
75
+ if !AwsWatcher::EC2.instance_alive?(@instance_id, @config)
76
+ p "instance: #{@instance_id} is not in aws anymore, removing message from queue"
77
+ AwsCleaner.new.delete_message(id, @config)
78
+ # if the node exists in chef it has bootstrapped
75
79
  # so we can delete the message
76
- if chef_node || !AwsWatcher::EC2.instance_alive?(@instance_id, @config)
80
+ elsif AwsWatcher::Chef.registered?(@instance_id, @config)
77
81
  p "instance: #{@instance_id} has bootstrapped, removing message from queue"
78
82
  AwsCleaner.new.delete_message(id, @config)
79
-
83
+ else
84
+ p "instance: #{@instance_id}, launched: #{launch_time}, elapsed: #{elapsed_time} seconds"
80
85
  end
81
- p "instance: #{@instance_id}, launched: #{launch_time}, elapsed: #{elapsed_time}"
82
86
  # if the elapsed time is less than how long we consider
83
87
  # a 'normal' converge time that's ok we just move on and
84
88
  # wait for another pass
@@ -96,9 +100,8 @@ loop do
96
100
  p 'node elaspsed time is too high'
97
101
  notification = "node: #{@instance_id} has not checked in, "
98
102
  notification += 'it should have converged by: '
99
- notification += "#{@config[:bootstrap][:converged_by]} "
100
- notification += 'and has been running since:and has been '
101
- notification += "running since: #{elapsed_time}"
103
+ notification += "#{@config[:bootstrap][:converged_by]} seconds "
104
+ notification += "and has been running since: #{launch_time}"
102
105
  AwsCleaner::Notify.notify_chat(notification, @config)
103
106
  end
104
107
  end
data/lib/aws-watcher.rb CHANGED
@@ -3,6 +3,15 @@ class AwsWatcher
3
3
  require 'aws_cleaner/aws_cleaner.rb'
4
4
  module Chef
5
5
  include AwsCleaner::Chef
6
+ def self.registered?(instance_id, config)
7
+ chef = AwsCleaner::Chef.client(config)
8
+ results = chef.search.query(:node, "ec2_instance_id:#{instance_id} OR chef_provisioning_reference_server_id:#{instance_id}")
9
+ if results.rows.empty?
10
+ false
11
+ else
12
+ true
13
+ end
14
+ end
6
15
  end
7
16
 
8
17
  module SQS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Abrams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-14 00:00:00.000000000 Z
11
+ date: 2017-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler