class LogStash::Outputs::Snmptrap
An example output that does nothing.
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/logstash/outputs/snmptrap.rb, line 28 def initialize(*args) super(*args) end
Public Instance Methods
receive(event)
click to toggle source
# 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
register()
click to toggle source
# 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