-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathec2-maintinence-find
executable file
·49 lines (41 loc) · 1.21 KB
/
ec2-maintinence-find
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#! /usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "fog"
require "fileutils"
require 'trollop'
require 'yaml'
require_relative 'environment.rb'
include Environment
require 'csv'
def write_file(records)
time=Time.now.strftime('%Y%m%d%H%M%S%L')
file_name = "rebooted-#{time}-response.csv"
puts file_name
CSV.open(file_name, "wb") do |csv|
csv << records.first.keys # adds the attributes name on the first line
records.each do |hash|
csv << hash.values
end
end
end
hashes = []
environments.each do |key, settings|
@connection = Fog::Compute::AWS.new(settings)
@connection.servers.all.each do |instance|
response = @connection.describe_instance_status({"InstanceId" =>instance.id })
# puts instance.inspect
response[:body]["instanceStatusSet"].each_with_object("foo") do |item, obj|
# puts "#{obj}: #{item}"
if item["eventsSet"].size>0
hash = item["eventsSet"].first
hash["notBefore"] = DateTime.parse(hash["notBefore"]).new_offset('+10:00')
hash["notAfter"] = DateTime.parse(hash["notAfter"]).new_offset('+10:00')
hash["instance-name"] = instance.tags['Name']
hash["account"] = key
hashes << hash
end
end
end
end
write_file(hashes)