Class: LogStash::Outputs::Snmptrap

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/outputs/snmptrap.rb

Overview

An example output that does nothing.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Snmptrap

Returns a new instance of Snmptrap.



28
29
30
# File 'lib/logstash/outputs/snmptrap.rb', line 28

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

Instance Method Details

#receive(event) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/logstash/outputs/snmptrap.rb', line 68

def receive(event)
  return unless output?(event)
  if event == LogStash::SHUTDOWN
    finished
    return
  end
  @oid = event.sprintf(@oid)
  @codec.encode(event)
end

#registerObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/logstash/outputs/snmptrap.rb', line 33

def register
  require "snmp"

  @codec.on_event do |event|

    #set some variables for the trap sender
    trapsender_opts = {:trap_port => @port, :host => @host, :community => @community }

    #prep and do the full send
    SNMP::Manager.open(trapsender_opts) do |snmp|
      #set it up and send the whole event using the user specified codec
      varbinds = []
      @varbinds.each do |key, expression|
        value = expression.clone
        if value.start_with?("!") 
          value.delete_prefix!("!")
          value = eval(value)
        elsif value.start_with?("@") 
          value.delete_prefix!("@")
          value = event.get(value)
        end
        unless value.nil?
          varbinds << SNMP::VarBind.new(key, SNMP::OctetString.new(value.force_encoding('ASCII-8BIT')))
        end
      end

      #we dont actually care about the sys_up_time...do we.
      snmp.trap_v2(0, @oid, varbinds)
      
      @logger.info("@oid: #{@oid.to_s} @varbinds: #{varbinds.to_s}", :event => event) if @log
      end
  end
end