Class: AwsAlertMonitor::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-alert-monitor/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Parser

Returns a new instance of Parser.



4
5
6
7
8
9
# File 'lib/aws-alert-monitor/parser.rb', line 4

def initialize(args)
  log_level      = args[:log_level]
  @config        = AwsAlertMonitor::Config.new :log_level => log_level
  @config_file   = @config.file
  @logger        = @config.logger
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/aws-alert-monitor/parser.rb', line 11

def run
  @config_file.each_pair do |name, data|
    sqs_endpoint = data['sqs_endpoint']
    access_key   = data['access_key']
    secret_key   = data['secret_key']
    events       = data['events']

    ::AWS.config :access_key_id     => access_key,
                 :secret_access_key => secret_key

    @logger.info "Processing #{name}."
    @logger.debug "Receiving messages from #{sqs_endpoint}"

    count = sqs.approximate_number_of_messages sqs_endpoint
    @logger.info "Approximatley #{count} messages available."

    while message = sqs.receive_message(sqs_endpoint)
      alert.process :name    => name,
                    :message => message.body,
                    :events  => events
      @logger.info "Deleting message from queue."
      message.delete
    end
  end
end