Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions slack-aws/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
require 'aws-sdk'
require 'slack-aws/util/aws_client_response'
require 'slack-aws/commands/s3'
require 'slack-aws/commands/ec2'
require 'slack-aws/commands/ops_works'
34 changes: 34 additions & 0 deletions slack-aws/commands/ec2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module SlackAws
module Commands
# Do the AWS EC2 things
class EC2 < SlackRubyBot::Commands::Base
extend SlackAws::Util::AwsClientResponse

command 'ec2' do |client, data, match|
arguments = match['expression'].split.reject(&:blank?) if match.names.include?('expression')
case arguments && arguments.shift
when 'instances' then
reap = Aws::EC2::Client.new
instances = reap.describe_instances
instanceprofile = "\n*Summary*:\n"
instances.reservations.each do |reservation|
reservation.instances.each do |instance|
if instance.state.name != 'running'
next
end
instanceprofile =
"\n#{instanceprofile}\n
*Instance Identifier:* #{instance.instance_id}\n
*IP Address:* #{instance.public_ip_address}\n
*Image Identifier:* #{instance.image_id}\n
*Instance Type:* #{instance.instance_type}\n"
end
end
client.say(text: instanceprofile, channel: data.channel)
else
client.say(text: 'Syntax: aws ec2 [command], need `aws help`? Message @awsbot help.', channel: data.channel)
end
end
end
end
end