Class: LogStash::Inputs::Yasuri

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/inputs/yasuri.rb

Instance Method Summary collapse

Instance Method Details

#inner_run(queue) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/logstash/inputs/yasuri.rb', line 64

def inner_run(queue)
  parsed = scrape()
  elements =  if @split
                parsed.flatten
              else
                [parsed]
              end

  elements.each do |e|
    event = LogStash::Event.new("parsed" => e, "host" => @host, "url" => @url)
    decorate(event)
    queue << event
  end
end

#registerObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/logstash/inputs/yasuri.rb', line 33

def register
  @host = Socket.gethostname
  @agent = Mechanize.new
  @scheduler = Rufus::Scheduler.new

  # If given both, logstash-input-yasuri use :parse_tree.
  tree = @parse_tree || File.read(@parse_tree_path)

  @tree  = Yasuri.json2tree(tree)
end

#run(queue) ⇒ Object

def register



44
45
46
47
48
49
50
51
52
53
# File 'lib/logstash/inputs/yasuri.rb', line 44

def run(queue)
  # we can abort the loop if stop? becomes true
  scheduler.cron @cron do
    # because the sleep interval can be big, when shutdown happens
    # we want to be able to abort the sleep
    # Stud.stoppable_sleep will frequently evaluate the given block
    # and abort the sleep(@interval) if the return value is true
    inner_run(queue)
  end
end

#scrapeObject



79
80
81
82
# File 'lib/logstash/inputs/yasuri.rb', line 79

def scrape()
  page = @agent.get(@url)
  @tree.inject(@agent, page)
end

#stopObject

def run



55
56
57
58
59
60
61
62
# File 'lib/logstash/inputs/yasuri.rb', line 55

def stop
  # nothing to do in this case so it is not necessary to define stop
  # examples of common "stop" tasks:
  #  * close sockets (unblocking blocking reads/accepts)
  #  * cleanup temporary files
  #  * terminate spawned threads
  @scheduler.shutdown
end