Class: Interferon::HostSources::AwsRds

Inherits:
Object
  • Object
show all
Defined in:
lib/interferon/host_sources/aws_rds.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AwsRds

Returns a new instance of AwsRds.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/interferon/host_sources/aws_rds.rb', line 5

def initialize(options)
  missing = %w{access_key_id secret_access_key}.reject{|r| options.key?(r)}

  AWS.config({
      :access_key_id => options['access_key_id'],
      :secret_access_key => options['secret_access_key']
  }) if missing.empty?

  # initialize a list of regions to check
  if options['regions'] && !options['regions'].empty?
    @regions = options['regions']
  else
    @regions = AWS::regions.map(&:name)
  end
end

Instance Method Details

#list_hostsObject



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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/interferon/host_sources/aws_rds.rb', line 21

def list_hosts
  hosts = []

  @regions.each do |region|
    rds = AWS::RDS.new(:region => region)

    AWS.memoize do
      rds.instances.each do |instance|
        # get the tags for the instance
        arn = arn(region, instance.id)
        tag_list = rds.client.list_tags_for_resource(:resource_name => arn)[:tag_list]
        tags = Hash[ tag_list.map { |h| [h[:key], h[:value]] } ]

        tags['owners'] ||= ''
        tags['owner_groups'] ||= ''

        # build the host data for this instance
        hosts << {
          :source => 'aws_rds',
          :region => region,
          :instance_id => instance.id,
          :db_name => instance.db_name,
          :engine => instance.engine,
          :engine_version => instance.engine_version,

          # metrics
          :allocated_storage => instance.allocated_storage,
          :iops => instance.iops,

          # replication info
          :is_replica => !instance.read_replica_source_db_instance_identifier.nil?,
          :replica_source_name => instance.read_replica_source_db_instance_identifier,
          :replica_names => instance.read_replica_db_instance_identifiers.join(','),
          :replicas => instance.read_replica_db_instance_identifiers.count,

          :owners => tags['owners'].split(','),
          :owner_groups => tags['owner_groups'].split(','),

          :db_env => tags['db_env'],
          :db_role => tags['db_role'],
        }
      end
    end
  end

  return hosts
end