module FFWD::Plugin::Riemann::Shared

Public Instance Methods

make_event(event) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 82
def make_event event
  e = ::Riemann::Event.new

  write_attributes e, event.attributes
  write_tags e, event.tags
  write_time e, event.time

  EVENT_MAPPING.each do |key, reader, writer|
    if (v = event.send(key)).nil?
      next
    end

    v = v.to_s if v.is_a? Symbol
    e.send writer, v
  end

  e
end
make_message(message) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 138
def make_message(message)
  ::Riemann::Message.new(message)
end
make_metric(metric) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 101
def make_metric metric
  e = ::Riemann::Event.new

  write_attributes e, metric.attributes
  write_tags e, metric.tags
  write_time e, metric.time

  METRIC_MAPPING.each do |key, reader, writer|
    if (v = metric.send(key)).nil?
      next
    end

    v = v.to_s if v.is_a? Symbol
    e.send writer, v
  end

  e
end
read_attributes(e, source) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 40
def read_attributes e, source
  return if source.nil? or source.empty?

  attributes = {}

  source.each do |a|
    attributes[a.key] = a.value
  end

  e[:attributes] = attributes
end
read_event(event) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 120
def read_event event
  e = {}

  read_attributes e, event.attributes
  read_tags e, event.tags
  read_time e, event.time

  EVENT_MAPPING.each do |key, reader, writer|
    if (v = event.send(reader)).nil?
      next
    end

    e[key] = v
  end

  e
end
read_message(data) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 142
def read_message(data)
  ::Riemann::Message.decode data
end
read_tags(e, source) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 62
def read_tags e, source
  return if source.nil? or source.empty?
  e[:tags] = source.to_a
end
read_time(e, source) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 72
def read_time e, source
  return if source.nil?
  e[:time] = Time.at source
end
write_attributes(e, source) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 52
def write_attributes e, source
  return if source.nil? or source.empty?

  e.attributes = source.map{|k, v|
    k = k.to_s.dup unless k.nil?
    v = v.to_s.dup unless v.nil?
    ::Riemann::Attribute.new(:key => k, :value => v)
  }
end
write_tags(e, source) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 67
def write_tags e, source
  return if source.nil? or source.empty?
  e.tags = source.map{|v| v.dup}
end
write_time(e, source) click to toggle source
# File lib/ffwd/plugin/riemann/shared.rb, line 77
def write_time e, source
  return if source.nil?
  e.time = source.to_i
end