Class: Carnivore::Source::CarnFile

Inherits:
Carnivore::Source show all
Defined in:
lib/carnivore-files/carn_file.rb

Overview

Carnivore source for consumption from files

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fetcherSymbol (readonly)

Returns registry name of fetcher.

Returns:

  • (Symbol)

    registry name of fetcher



11
12
13
# File 'lib/carnivore-files/carn_file.rb', line 11

def fetcher
  @fetcher
end

#pathString (readonly)

Returns path to file.

Returns:

  • (String)

    path to file



9
10
11
# File 'lib/carnivore-files/carn_file.rb', line 9

def path
  @path
end

Instance Method Details

#connectObject

Start the line fetcher



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/carnivore-files/carn_file.rb', line 30

def connect
  @fetcher_name = "log_fetcher_#{name}".to_sym
  case args[:foundation].to_sym
  when :poll
    @fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args)
  else
    @fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args)
  end
  self.link fetcher
  fetcher.async.start_fetcher
end

#fetcher_destroyerObject



53
54
55
56
57
# File 'lib/carnivore-files/carn_file.rb', line 53

def fetcher_destroyer
  if(fetcher && fetcher.alive?)
    fetcher.terminate
  end
end

#fetcher_failure(object, reason) ⇒ Object

Restart file collector if unexpectedly failed

Parameters:

  • object (Actor)

    crashed actor

  • reason (Exception, NilClass)


46
47
48
49
50
51
# File 'lib/carnivore-files/carn_file.rb', line 46

def fetcher_failure(object, reason)
  if(reason && object == fetcher)
    error "File message collector unexpectedly failed: #{reason} (restarting)"
    connect
  end
end

#receive(*args) ⇒ Array<Hash>

Return messages

Returns:

  • (Array<Hash>)

    return messages



60
61
62
# File 'lib/carnivore-files/carn_file.rb', line 60

def receive(*args)
  format_message(Celluloid::Future.new{ fetcher.messages.pop }.value)
end

#setup(*_) ⇒ Object

Setup source

Parameters:

  • args (Hash)


22
23
24
25
26
27
# File 'lib/carnivore-files/carn_file.rb', line 22

def setup(*_)
  @path = ::File.expand_path(args[:path])
  unless(args[:foundation])
    args[:foundation] = RUBY_PLATFORM == 'java' ? :poll : :penguin
  end
end

#transmit(payload, *args) ⇒ Object

Send payload

Parameters:

  • payload (Object)

    payload to transmit



67
68
69
# File 'lib/carnivore-files/carn_file.rb', line 67

def transmit(payload, *args)
  fetcher.write_line(payload)
end