class Fluent::GeoBlipperOutput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_geoblipper.rb, line 4
def initialize
  super
  require 'geoip'
  require 'pubnub'
end

Public Instance Methods

format(tag, time, record) click to toggle source
# File lib/fluent/plugin/out_geoblipper.rb, line 24
def format(tag, time, record)
  address = record.delete(@ip_key)
  loc = @geodata.city(address)
  extra = {}
  if loc
    record.merge({latitude: loc.latitude, longitude: loc.longitude}).to_json + "\n"
  else
     Fluent::Engine.emit('debug.livemap', Time.now, {message: "geodata not found for #{address}"})
     ''
  end
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_geoblipper.rb, line 18
def start
  super
  @geodata = GeoIP.new(@geodata_location)
  @pubnub = Pubnub.new( publish_key: @pubnub_publish_key, subscribe_key: @pubnub_subscribe_key, logger: Logger.new(STDOUT) )
end
write(chunk) click to toggle source
# File lib/fluent/plugin/out_geoblipper.rb, line 36
def write(chunk)
  chunk.open do |io|
    items = io.read.split("\n")
    entries = items.slice(0..@max_entries).map {|item| JSON.parse(item) }
    unless entries.empty?
      unless @debug
        @pubnub.publish(http_sync: true, message: entries, channel: @pubnub_channel)
      else
        Fluent::Engine.emit('debug.pubnub', Time.now, {message: entries, channel: @pubnub_channel})
      end
    end
  end
end