Class: LogStash::Inputs::Snmptrap
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::Snmptrap
- Extended by:
- PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
- Includes:
- PluginMixins::ECSCompatibilitySupport::TargetCheck, PluginMixins::EventSupport::EventFactoryAdapter, PluginMixins::NormalizeConfigSupport, PluginMixins::Snmp::Common
- Defined in:
- lib/logstash/inputs/snmptrap.rb
Overview
Read snmp trap messages as events
Resulting ‘@message` looks like :
- source,json
-
“error_index”:0,“variable_bindings”:{“1.3.6.1.6.3.1.1.4.1.0”:“value”,“error_status”:0,“type”:“TRAP”,“error_status_text”:“Success”,“version”:“3”,“request_id”:145014487}
Constant Summary collapse
- MIB_DEFAULT_PATHS =
These MIBs were automatically added by ruby-snmp when no @yamlmibdir was provided.
[ ::File.join(MIB_BASE_PATH, 'ietf', 'SNMPv2-SMI.dic'), ::File.join(MIB_BASE_PATH, 'ietf', 'SNMPv2-MIB.dic'), ::File.join(MIB_BASE_PATH, 'ietf', 'IF-MIB.dic'), ::File.join(MIB_BASE_PATH, 'ietf', 'IP-MIB.dic'), ::File.join(MIB_BASE_PATH, 'ietf', 'TCP-MIB.dic'), ::File.join(MIB_BASE_PATH, 'ietf', 'UDP-MIB.dic') ].map { |path| ::File.(path) }
Constants included from PluginMixins::Snmp::Common
PluginMixins::Snmp::Common::MIB_BASE_PATH, PluginMixins::Snmp::Common::MIB_PROVIDED_PATHS, PluginMixins::Snmp::Common::OID_MAPPING_FORMAT_DEFAULT, PluginMixins::Snmp::Common::OID_MAPPING_FORMAT_RUBY_SNMP
Instance Method Summary collapse
- #client_listening? ⇒ Boolean
-
#initialize(params = {}) ⇒ Snmptrap
constructor
A new instance of Snmptrap.
- #register ⇒ Object
- #run(output_queue) ⇒ Object
- #stop ⇒ Object
Methods included from PluginMixins::Snmp::Common
#build_mib_manager!, #build_snmp_client!, included
Constructor Details
#initialize(params = {}) ⇒ Snmptrap
Returns a new instance of Snmptrap.
73 74 75 76 77 78 |
# File 'lib/logstash/inputs/snmptrap.rb', line 73 def initialize(params = {}) super(params) setup_deprecated_params! @host_ip_field = ecs_select[disabled: 'host', v1: '[host][ip]'] end |
Instance Method Details
#client_listening? ⇒ Boolean
113 114 115 |
# File 'lib/logstash/inputs/snmptrap.rb', line 113 def client_listening? @client.isListening() end |
#register ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/logstash/inputs/snmptrap.rb', line 80 def register validate_config! mib_manager = build_mib_manager! if !@mib_paths && !@use_provided_mibs logger.info("Using default MIB paths #{MIB_DEFAULT_PATHS}") MIB_DEFAULT_PATHS.each do |path| mib_manager.add(path) end end @client = build_client!(mib_manager) end |
#run(output_queue) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/logstash/inputs/snmptrap.rb', line 94 def run(output_queue) begin = lambda { |trap| (output_queue, trap) } @client.trap(@community, ) rescue => e @logger.warn('SNMP Trap listener died', format_log_data(e)) Stud.stoppable_sleep(5) { stop? } retry if !stop? end end |
#stop ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/logstash/inputs/snmptrap.rb', line 105 def stop begin @client.close unless @client.nil? rescue => e logger.warn('Error closing SNMP client. Ignoring', format_log_data(e)) end end |