Class: Fusuma::Plugin::Inputs::Input Abstract

Inherits:
Base
  • Object
show all
Defined in:
lib/fusuma/plugin/inputs/input.rb

Overview

This class is abstract.

Subclass and override #io to implement

Inherite this base

Direct Known Subclasses

LibinputCommandInput, TimerInput

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#config_index, #config_param_types, #config_params, inherited, plugins

Methods included from CustomProcess

#fork

Class Method Details

.select(inputs) ⇒ Event

Wait multiple inputs until it becomes readable and read lines with nonblock

Parameters:

Returns:

  • (Event)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fusuma/plugin/inputs/input.rb', line 16

def self.select(inputs)
  ios = IO.select(inputs.map(&:io))
  io = ios&.first&.first

  input = inputs.find { |i| i.io == io }

  begin
    line = io.readline_nonblock("\n").chomp
  rescue EOFError => e
    warn "#{input.class.name}: #{e}"
    warn 'Send SIGKILL to fusuma processes'
    inputs.reject { |i| i == input }.each do |i|
      warn "stop process: #{i.class.name.underscore}"
      Process.kill(:SIGKILL, i.pid)
    end
    exit 1
  rescue StandardError => e
    warn "#{input.class.name}: #{e}"
    exit 1
  end

  input.create_event(record: line)
end

Instance Method Details

#create_event(record: 'dummy input') ⇒ Event

Returns:

  • (Event)


51
52
53
54
55
# File 'lib/fusuma/plugin/inputs/input.rb', line 51

def create_event(record: 'dummy input')
  e = Events::Event.new(tag: tag, record: record)
  MultiLogger.debug(input_event: e)
  e
end

#ioIO

Returns:

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/fusuma/plugin/inputs/input.rb', line 46

def io
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end

#pidInteger

Returns:

  • (Integer)

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/fusuma/plugin/inputs/input.rb', line 41

def pid
  raise NotImplementedError, "override #{self.class.name}##{__method__}"
end

#tagObject



57
58
59
# File 'lib/fusuma/plugin/inputs/input.rb', line 57

def tag
  self.class.name.split('Inputs::').last.underscore
end