Class: LogStash::Inputs::Snmptrap

Inherits:
Base show all
Defined in:
lib/logstash/inputs/snmptrap.rb

Overview

Read snmp trap messages as events

Resulting @message looks like :

#<SNMP::SNMPv1_Trap:0x6f1a7a4 @varbind_list=[#<SNMP::VarBind:0x2d7bcd8f @value="teststring", 
@name=[1.11.12.13.14.15]>], @timestamp=#<SNMP::TimeTicks:0x1af47e9d @value=55>, @generic_trap=6, 
@enterprise=[1.2.3.4.5.6], @source_ip="127.0.0.1", @agent_addr=#<SNMP::IpAddress:0x29a4833e @value="\xC0\xC1\xC2\xC3">, 
@specific_trap=99>

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes inherited from Base

#params, #threadable

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#tag

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s

Constructor Details

#initialize(*args) ⇒ Snmptrap

Returns a new instance of Snmptrap.



31
32
33
# File 'lib/logstash/inputs/snmptrap.rb', line 31

def initialize(*args)
  super(*args)
end

Instance Method Details

#registerObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/logstash/inputs/snmptrap.rb', line 36

def register
  require "snmp"
  @snmptrap = nil
  if @yamlmibdir
    @logger.info("checking #{@yamlmibdir} for MIBs")
    Dir["#{@yamlmibdir}/*.yaml"].each do |yamlfile|
      mib_name = File.basename(yamlfile, ".*")
      @yaml_mibs ||= []
      @yaml_mibs << mib_name
    end
    @logger.info("found MIBs: #{@yaml_mibs.join(',')}") if @yaml_mibs
  end
end

#run(output_queue) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/logstash/inputs/snmptrap.rb', line 51

def run(output_queue)
  begin
    # snmp trap server
    snmptrap_listener(output_queue)
  rescue => e
    @logger.warn("SNMP Trap listener died", :exception => e, :backtrace => e.backtrace)
    sleep(5)
    retry
  end # begin
end