Class: LogStash::Outputs::Snmptrap
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::Snmptrap
- Defined in:
- lib/logstash/outputs/snmptrap.rb
Overview
An example output that does nothing.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Snmptrap
constructor
A new instance of Snmptrap.
- #receive(event) ⇒ Object
- #register ⇒ Object
Constructor Details
#initialize(*args) ⇒ Snmptrap
Returns a new instance of Snmptrap.
26 27 28 |
# File 'lib/logstash/outputs/snmptrap.rb', line 26 def initialize(*args) super(*args) end |
Instance Method Details
#receive(event) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/logstash/outputs/snmptrap.rb', line 64 def receive(event) return unless output?(event) if event == LogStash::SHUTDOWN finished return end @oid = event.sprintf(@oid) @codec.encode(event) end |
#register ⇒ Object
31 32 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 |
# File 'lib/logstash/outputs/snmptrap.rb', line 31 def register require "snmp" #from snmp trap input plugin, thanks # 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 @codec.on_event do |event| #set some variables for the trap sender trapsender_opts = {:trap_port => @port, :host => @host, :community => @community } #check for and add user specified mibs # if @yaml_mibs && !@yaml_mibs.empty? # trapsender_opts.merge!({:mib_dir => @yamlmibdir, :mib_modules => @yaml_mibs}) # end #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 varbind = SNMP::VarBind.new(@oid, SNMP::OctetString.new(event.to_s)) #we dont actually care about the sys_up_time...do we. Also I am re-using the oid that was input. snmp.trap_v2(0, @oid, varbind) end end end |