Selaa lähdekoodia

load sqs queues

Chris Mague 6 vuotta sitten
vanhempi
commit
516a269a55
2 muutettua tiedostoa jossa 64 lisäystä ja 1 poistoa
  1. 32 1
      lib/neoinfra/aws.rb
  2. 32 0
      models/sqs.rb

+ 32 - 1
lib/neoinfra/aws.rb

@@ -5,6 +5,7 @@ require 'regions'
 require 'mime-types'
 require 'fog-aws'
 require 's3'
+require 'sqs'
 require 'date'
 require 'ipaddr'
 require 'neo4j'
@@ -130,7 +131,7 @@ module NeoInfra
         end
       end
     end
-
+####
     def load_security_groups
       @cfg.accounts.each do |account|
         base_conf = {
@@ -339,6 +340,36 @@ module NeoInfra
       end
     end
 
+    def load_queues
+      aws = NeoInfra::Aws.new
+      cw = NeoInfra::Cloudwatch.new
+      @cfg.accounts.each do |account|
+        base_conf = {
+          aws_access_key_id: account[:key],
+          aws_secret_access_key: account[:secret]
+        }
+        aws.regions.each do |region|
+          region_conf = { region: region }
+          q = Fog::AWS::SQS.new(region_conf.merge(base_conf))
+          q.list_queues.data[:body]['QueueUrls'].each do |x|
+            next unless SQSQueue.where(url: x).empty?
+            theAttrs = q.get_queue_attributes(x, "All").data[:body]['Attributes']
+            z = SQSQueue.new(
+              url: x,
+              name: x.split('/')[-1],
+              modified: theAttrs['LastModifiedTimestamp'],
+              creation: theAttrs['CreatedTimestamp'],
+              retention: theAttrs['MessageRetentionPeriod'],
+              maxsize: theAttrs['MaximumMessageSize'],
+            )
+            z.save
+            SQSQueueRegion.create(from_node: z, to_node: Region.where(region: region).first)
+            SQSQueueAccount.create(from_node: z, to_node: AwsAccount.where(name: account[:name]).first)
+          end
+        end
+      end
+    end   
+
     def load_rds
       @cfg.accounts.each do |account|
         base_conf = {

+ 32 - 0
models/sqs.rb

@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require 'neo4j'
+
+# Information on SQSQueue
+class SQSQueue
+  include Neo4j::ActiveNode
+  property :url, constraint: :unique
+  property :name
+  property :modified
+  property :creation
+  property :retention
+  property :maxsize
+  has_one :out, :region, rel_class: :SQSQueueRegion
+  has_one :out, :owner, rel_class: :SQSQueueAccount
+end
+
+# Map SQSQueue to Region
+class SQSQueueRegion
+  include Neo4j::ActiveRel
+  from_class :SQSQueue
+  to_class :Region
+  type :region
+end
+
+# Map SQSQueue to Region
+class SQSQueueAccount
+  include Neo4j::ActiveRel
+  from_class :SQSQueue
+  to_class :AwsAccount
+  type :owner
+end