Sha256: 0296c06030f1b88cf8389f2abb1331c7dffb14a883ffc4ec7c67cf064accef69

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

class Radiosonde::Exporter
  class << self
    def export(cloud_watch, opts = {})
      self.new(cloud_watch, opts).export
    end
  end # of class methods

  def initialize(cloud_watch, options = {})
    @cloud_watch = cloud_watch
    @options = options
  end

  def export
    result = {}

    @cloud_watch.alarms.each do |alarm|
      export_alarm(alarm, result)
    end

    return result
  end

  private

  def export_alarm(alarm, result)
    alarm_attrs = {
      :description => alarm.alarm_description,
      :metric_name => alarm.metric_name,
      :namespace => alarm.namespace,
      :dimensions => alarm.dimensions,
      :period => alarm.period,
      :statistic => alarm.statistic,
      :threshold => alarm.threshold,
      :comparison_operator => alarm.comparison_operator,
      :evaluation_periods => alarm.evaluation_periods,
      :actions_enabled => alarm.actions_enabled,
      :alarm_actions => alarm.alarm_actions,
      :ok_actions => alarm.ok_actions,
      :insufficient_data_actions => alarm.insufficient_data_actions,
      :unit => alarm.unit,
    }

    if @options[:with_status]
      alarm_attrs[:status] = export_alarm_status(alarm)
    end

    result[alarm.alarm_name] = alarm_attrs
  end

  def export_alarm_status(alarm)
    {
      :alarm_arn => alarm.alarm_arn,
      :state_value => alarm.state_value,
      :state_reason => alarm.state_reason,
      :state_reason_data => alarm.state_reason_data ? JSON.parse(alarm.state_reason_data) : nil,
      :state_updated_timestamp => alarm.state_updated_timestamp,
      :alarm_configuration_updated_timestamp => alarm.alarm_configuration_updated_timestamp,
    }
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
radiosonde-0.0.8 lib/radiosonde/exporter.rb
radiosonde-0.0.7 lib/radiosonde/exporter.rb
radiosonde-0.0.6 lib/radiosonde/exporter.rb
radiosonde-0.0.5 lib/radiosonde/exporter.rb
radiosonde-0.0.4 lib/radiosonde/exporter.rb