diff --git a/slack-aws/commands.rb b/slack-aws/commands.rb index bf4b475..d877ff3 100644 --- a/slack-aws/commands.rb +++ b/slack-aws/commands.rb @@ -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' diff --git a/slack-aws/commands/ec2.rb b/slack-aws/commands/ec2.rb new file mode 100644 index 0000000..308ea7d --- /dev/null +++ b/slack-aws/commands/ec2.rb @@ -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