Class: Fluent::SnmpInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_snmp.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (ConfigError)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fluent/plugin/in_snmp.rb', line 52

def configure(conf)                                                         
  super

  raise ConfigError, "snmp: 'tag' is required param" if @tag.empty?
  raise ConfigError, "snmp: 'polling_type' parameter is required on snmp input" if @polling_type.empty?

  # @mib, @mib_modules, @nodesを配列に変換
  @mib = @mib.split(',').map{|str| str.strip} 
  raise ConfigError, "snmp: 'mib' parameter is required on snmp input" if @mib.empty?

  @mib_modules = @mib_modules.split(',').map{|str| str.strip} unless @mib_modules.nil?
  raise ConfigError, "snmp: 'mib_modules' parameter is required on snmp input" if !@mib_modules.nil? && @mib_modules.empty?

  @nodes = @nodes.split(',').map{|str| str.strip} unless @nodes.nil?
  raise ConfigError, "snmp: 'nodes' parameter is required on snmp input" if !@nodes.nil? && @nodes.empty?

  @polling_time = @polling_time.split(',').map{|str| str.strip} unless @polling_time.nil?
  raise ConfigError, "snmp: 'polling_time' parameter is required on snmp input" if !@polling_time.nil? && @polling_time.empty?

  # snmp version
  @version = @version == "1" ? :SNMPv1 : :SNMPv2c

  # SNMP Libraryの初期値を設定
  @snmp_init_params = {
    :host            => @host, #or conf["host"]
    :port            => @port,
    :trap_port       => @trap_port,
    :community       => @community,
    :write_community => @write_community,
    :version         => @version,
    :timeout         => @timeout,
    :retries         => @retries,
    :transport       => @transport,
    :max_recv_bytes  => @max_recv_bytes,
    :mib_dir         => @mib_dir,
    :mib_modules     => @mib_modules,
    :use_IPv6        => @use_IPv6
  }

  unless @out_executor.nil?
    $log.info "load snmp out executor #{out_executor}"
    @out_exec = lambda do |manager|
      load @out_executor
      opts = {
        :tag         => @tag,
        :mib         => @mib,
        :mib_modules => @mib_modules,
        :nodes       => @nodes,
        :conf        => conf
      }
      Fluent::SnmpInput.new.out_exec(manager, opts)
    end
  end
end

#runObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fluent/plugin/in_snmp.rb', line 121

def run
  Polling.setting offset: @polling_offset
  Polling.__send__(@polling_type, @polling_time) do
    break if @end_flag
    exec_snmp(manager: @manager, mib: @mib, nodes: @nodes, method_type: @method_type)
  end
rescue TypeError => ex
  $log.error "run TypeError", :error=>ex.message
  exit
rescue => ex
  $log.fatal "run failed", :error=>ex.inspect
  $log.error_backtrace ex.backtrace
  exit
end

#shutdownObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/fluent/plugin/in_snmp.rb', line 136

def shutdown
  @end_flag = true
  if @thread 
    @thread.run
    @thread.join
    @thread = nil
  end
  if @starter
    @starter.join 
    @starter = nil
  end
  if @manager
    @manager.close 
  end
end

#startObject



113
114
115
116
117
118
119
# File 'lib/fluent/plugin/in_snmp.rb', line 113

def start
  starter do
    @manager = SNMP::Manager.new(@snmp_init_params)
    @thread = Thread.new(&method(:run))
    @end_flag = false
  end
end

#starterObject



107
108
109
110
111
# File 'lib/fluent/plugin/in_snmp.rb', line 107

def starter
  @starter = Thread.new do
    yield
  end
end