Sha256: 4fde06da499b465bb8ba97b9e491ece871fb13d6b6e787deb5ca9e6d018618b2

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require 'riemann/tools'

module Riemann
  module Tools
    module Aws
      class SqsStatus
        include Riemann::Tools
        require 'fog/aws'

        opt :access_key, 'AWS access key', type: String
        opt :secret_key, 'Secret access key', type: String
        opt :region, 'AWS region', type: String, default: 'us-east-1'
        opt :queue, 'SQS Queue name', type: String
        def initialize
          creds = if opts.key?('access_key') && opts.key?('secret_key')
                    {
                      aws_access_key_id: opts[:access_key],
                      aws_secret_access_key: opts[:secret_key],
                    }
                  else
                    { use_iam_profile: true }
                  end
          creds['region'] = opts[:region]
          @sqs = Fog::AWS::SQS.new(creds)
          response = @sqs.list_queues({ 'QueueNamePrefix' => opts[:queue] })
          @queue_url = response[:body]['QueueUrls'].first
        end

        def tick
          response = @sqs.get_queue_attributes(@queue_url, 'All')
          %w[ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible].each do |attr|
            msg = {
              metric: response[:body]['Attributes'][attr],
              service: "#{opts[:queue]} #{attr}",
              state: 'ok',
            }
            report msg
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
riemann-tools-1.10.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.9.1 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.9.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.8.2 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.8.1 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.8.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.7.1 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.7.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.6.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.5.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.4.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.3.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb
riemann-tools-1.2.0 tools/riemann-aws/lib/riemann/tools/aws/sqs_status.rb