Created
August 5, 2013 07:18
-
-
Save mechamogera/6154028 to your computer and use it in GitHub Desktop.
AWS EC2の全イベント取得サンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AWSOperation | |
def self.get_ec2_events(config = {}) | |
report = [] | |
config[:proxy_uri] ||= ENV['HTTP_PROXY'] || ENV['http_proxy'] | |
ec2 = AWS::EC2.new(config) | |
ec2.regions.each do |region| | |
reg = ec2.regions[region.name] | |
reg.instances.each do |instance| | |
status = reg.client.describe_instance_status({"instance_ids" => [ instance.id ]}) | |
event = status.data[:instance_status_set][0][:events_set] rescue nil | |
event = [] unless event | |
next if event.empty? | |
report << "ec2-instance[#{instance.tags["Name"] || instance.dns_name}] of #{region.name} has event #{event}" | |
end | |
end | |
report | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment