logstash-input-snmp4jtrap 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +104 -0
- data/TODO.md +9 -0
- data/lib/logstash/inputs/snmp4jtrap.rb +90 -0
- data/lib/snmp4j-2.3.0.jar +0 -0
- data/lib/snmp4j-agent-2.2.2.jar +0 -0
- data/lib/snmp4j-smi-pro.jar +0 -0
- data/lib/snmp4jr-smi-pro.rb +11 -0
- data/lib/snmp4jr.rb +60 -0
- data/lib/snmp4jr/message.rb +52 -0
- data/lib/snmp4jr/mib_manager.rb +101 -0
- data/lib/snmp4jr/trap_listener.rb +74 -0
- data/lib/snmp4jr/variable_binding.rb +58 -0
- data/logstash-input-snmp4jtrap.gemspec +29 -0
- data/spec/logstash/input/snmp4jtrap_spec.rb +5 -0
- data/spec/spec_helper.rb +2 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0830da6627975560c8df20298ad086f117dea47e
|
4
|
+
data.tar.gz: 87864198e3a2724005d97dbf119fa1f392a281ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4a7c85eae9883956ced43df50611d7f66412c9ff096a5b1c9156f4abf1c8606b8b2ee752fbdbcea6214ad9aba3d2b5d763befaba2b4c246c7092b81534887d98
|
7
|
+
data.tar.gz: f87d0f6e206a3e0578732902022621a158c2d799f395666b74e5d089afb9621368c3d802f7203f507505fbf784d9ad372642d0514b98f4e82edbd94470ff947f
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Michael Zaccari
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# SNMP4J Trap Input for Logstash
|
2
|
+
|
3
|
+
SNMP4J: http://www.snmp4j.org/
|
4
|
+
|
5
|
+
Uses the SMI-Pro library from SNMP4J to compile and transform custom MIB oids into strings.
|
6
|
+
|
7
|
+
Heavily based on the ruby-snmp plugin found here:
|
8
|
+
|
9
|
+
https://github.com/logstash-plugins/logstash-input-snmptrap
|
10
|
+
|
11
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
12
|
+
|
13
|
+
It is fully free and fully open source. The license is MIT, meaning you are pretty much free to use it however you want in whatever way.
|
14
|
+
|
15
|
+
## Documentation
|
16
|
+
|
17
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
18
|
+
|
19
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
20
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
21
|
+
|
22
|
+
## Need Help?
|
23
|
+
|
24
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
25
|
+
|
26
|
+
## Developing
|
27
|
+
|
28
|
+
### 1. Plugin Developement and Testing
|
29
|
+
|
30
|
+
#### Code
|
31
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
32
|
+
|
33
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
34
|
+
|
35
|
+
- Install dependencies
|
36
|
+
```sh
|
37
|
+
bundle install
|
38
|
+
```
|
39
|
+
|
40
|
+
#### Test
|
41
|
+
|
42
|
+
- Update your dependencies
|
43
|
+
|
44
|
+
```sh
|
45
|
+
bundle install
|
46
|
+
```
|
47
|
+
|
48
|
+
- Run tests
|
49
|
+
|
50
|
+
```sh
|
51
|
+
bundle exec rspec
|
52
|
+
```
|
53
|
+
|
54
|
+
### 2. Running your unpublished Plugin in Logstash
|
55
|
+
|
56
|
+
#### 2.1 Run in a local Logstash clone
|
57
|
+
|
58
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
59
|
+
```ruby
|
60
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
61
|
+
```
|
62
|
+
- Install plugin
|
63
|
+
```sh
|
64
|
+
# Logstash 2.3 and higher
|
65
|
+
bin/logstash-plugin install --no-verify
|
66
|
+
|
67
|
+
# Prior to Logstash 2.3
|
68
|
+
bin/plugin install --no-verify
|
69
|
+
|
70
|
+
```
|
71
|
+
- Run Logstash with your plugin
|
72
|
+
```sh
|
73
|
+
bin/logstash -e 'filter {awesome {}}'
|
74
|
+
```
|
75
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
76
|
+
|
77
|
+
#### 2.2 Run in an installed Logstash
|
78
|
+
|
79
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
80
|
+
|
81
|
+
- Build your plugin gem
|
82
|
+
```sh
|
83
|
+
gem build logstash-filter-awesome.gemspec
|
84
|
+
```
|
85
|
+
- Install the plugin from the Logstash home
|
86
|
+
```sh
|
87
|
+
# Logstash 2.3 and higher
|
88
|
+
bin/logstash-plugin install --no-verify
|
89
|
+
|
90
|
+
# Prior to Logstash 2.3
|
91
|
+
bin/plugin install --no-verify
|
92
|
+
|
93
|
+
```
|
94
|
+
- Start Logstash and proceed to test the plugin
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
99
|
+
|
100
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
101
|
+
|
102
|
+
It is more important to the community that you are able to contribute.
|
103
|
+
|
104
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
data/TODO.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'logstash/inputs/base'
|
3
|
+
require 'logstash/namespace'
|
4
|
+
|
5
|
+
# Read snmp trap messages as events with optional custom MIB support.
|
6
|
+
|
7
|
+
class LogStash::Inputs::Snmp4JTrap < LogStash::Inputs::Base
|
8
|
+
config_name 'snmp4jtrap'
|
9
|
+
|
10
|
+
# The address to listen on
|
11
|
+
config :host, validate: :string, default: '0.0.0.0'
|
12
|
+
|
13
|
+
# The port to listen on. Remember that ports less than 1024 (privileged
|
14
|
+
# ports) may require root to use. hence the default of 10162.
|
15
|
+
config :port, validate: :number, default: 1162
|
16
|
+
|
17
|
+
# Transport protocol
|
18
|
+
config :protocol, validate: ['udp', 'tcp'], default: 'udp'
|
19
|
+
|
20
|
+
# Directory containing MIB files
|
21
|
+
config :mib_dir, validate: :string, default: '/usr/share/snmp/mibs'
|
22
|
+
|
23
|
+
# SNMP4J-SMI PRO License Key
|
24
|
+
config :license_key, validate: :string
|
25
|
+
|
26
|
+
def initialize(*args)
|
27
|
+
super(*args)
|
28
|
+
end # def initialize
|
29
|
+
|
30
|
+
def register
|
31
|
+
require 'snmp4jr'
|
32
|
+
@snmptrap = nil
|
33
|
+
load_mib_manager
|
34
|
+
end
|
35
|
+
|
36
|
+
def run(output_queue)
|
37
|
+
begin
|
38
|
+
snmptrap_listener(output_queue)
|
39
|
+
rescue => e
|
40
|
+
@logger.warn('SNMP4J Trap listener died', exception: e, backtrace: e.backtrace)
|
41
|
+
Stud.stoppable_sleep(5) { stop? }
|
42
|
+
retry if !stop?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def stop
|
47
|
+
@snmptrap.close if @snmptrap
|
48
|
+
@snmptrap = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def load_mib_manager
|
54
|
+
@mib_manager = SNMP4JR::MibManager.instance
|
55
|
+
|
56
|
+
@mib_manager.license_key = @license_key
|
57
|
+
@mib_manager.mib_directory = @mib_dir
|
58
|
+
|
59
|
+
@mib_manager.load
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_trap_listener
|
63
|
+
listener_opts = {
|
64
|
+
protocol: @protocol,
|
65
|
+
host: @host,
|
66
|
+
port: @port
|
67
|
+
}
|
68
|
+
|
69
|
+
@logger.info("It's a Trap!", listener_opts.dup)
|
70
|
+
|
71
|
+
@snmptrap = SNMP4JR::TrapListener.new(listener_opts)
|
72
|
+
end
|
73
|
+
|
74
|
+
def snmptrap_listener(output_queue)
|
75
|
+
build_trap_listener
|
76
|
+
|
77
|
+
@snmptrap.on_trap do |trap|
|
78
|
+
begin
|
79
|
+
event = LogStash::Event.new(trap.to_h)
|
80
|
+
decorate(event)
|
81
|
+
@logger.debug('SNMP Trap received: ', trap_object: trap.inspect)
|
82
|
+
output_queue << event
|
83
|
+
rescue => error
|
84
|
+
@logger.error('Failed to create event', trap_object: trap.inspect)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
@snmptrap.join
|
89
|
+
end
|
90
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
data/lib/snmp4jr.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'snmp4j-2.3.0.jar'
|
3
|
+
require 'snmp4j-agent-2.2.2.jar'
|
4
|
+
|
5
|
+
module SNMP4JR
|
6
|
+
include_package 'org.snmp4j'
|
7
|
+
|
8
|
+
module Agent
|
9
|
+
module MO
|
10
|
+
module Snmp
|
11
|
+
include_package 'org.snmp4j.agent.mo.snmp'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ASN1
|
17
|
+
include_package 'org.snmp4j.asn1'
|
18
|
+
end
|
19
|
+
|
20
|
+
module Event
|
21
|
+
include_package 'org.snmp4j.event'
|
22
|
+
end
|
23
|
+
|
24
|
+
module Log
|
25
|
+
include_package 'org.snmp4j.log'
|
26
|
+
end
|
27
|
+
|
28
|
+
module MP
|
29
|
+
include_package 'org.snmp4j.mp'
|
30
|
+
end
|
31
|
+
|
32
|
+
module Security
|
33
|
+
include_package 'org.snmp4j.security'
|
34
|
+
end
|
35
|
+
|
36
|
+
module SMI
|
37
|
+
include_package 'org.snmp4j.smi'
|
38
|
+
|
39
|
+
module Util
|
40
|
+
include_package 'org.snmp4j.smi.util'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
module Transport
|
45
|
+
include_package 'org.snmp4j.transport'
|
46
|
+
end
|
47
|
+
|
48
|
+
module Util
|
49
|
+
include_package 'org.snmp4j.util'
|
50
|
+
end
|
51
|
+
|
52
|
+
module Version
|
53
|
+
include_package 'org.snmp4j.version'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
require 'snmp4jr/mib_manager'
|
58
|
+
require 'snmp4jr/variable_binding'
|
59
|
+
require 'snmp4jr/message'
|
60
|
+
require 'snmp4jr/trap_listener'
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module SNMP4JR
|
2
|
+
class Message
|
3
|
+
|
4
|
+
attr_reader :event, :data
|
5
|
+
|
6
|
+
def initialize(event)
|
7
|
+
@event = event
|
8
|
+
parse_event
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_h
|
12
|
+
data
|
13
|
+
end
|
14
|
+
alias_method :to_hash, :to_h
|
15
|
+
|
16
|
+
def [](oid)
|
17
|
+
data[oid]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def parse_event
|
23
|
+
@data = {
|
24
|
+
'snmp_request_id' => request_id,
|
25
|
+
'peer_address' => peer_address,
|
26
|
+
'host' => peer_address
|
27
|
+
}
|
28
|
+
|
29
|
+
variable_bindings.each do |variable|
|
30
|
+
@data[variable.oid] = variable.value
|
31
|
+
end
|
32
|
+
|
33
|
+
@data
|
34
|
+
end
|
35
|
+
|
36
|
+
def variable_bindings
|
37
|
+
pdu.variable_bindings.map { |vb| VariableBinding.new(vb) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def pdu
|
41
|
+
@pdu ||= event.pdu
|
42
|
+
end
|
43
|
+
|
44
|
+
def request_id
|
45
|
+
@request_id ||= pdu.request_id.toInt
|
46
|
+
end
|
47
|
+
|
48
|
+
def peer_address
|
49
|
+
@peer_address ||= event.peer_address.toString
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'snmp4jr-smi-pro'
|
3
|
+
|
4
|
+
module SNMP4JR
|
5
|
+
class MibManager
|
6
|
+
include ::Singleton
|
7
|
+
|
8
|
+
attr_accessor :license_key, :mib_directory
|
9
|
+
|
10
|
+
attr_reader :compilation_monitor, :load_into_repository, :update_existent,
|
11
|
+
:compile_leniently
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@compilation_monitor = nil
|
15
|
+
@load_into_repository = true
|
16
|
+
@update_existent = true
|
17
|
+
@compile_leniently = false
|
18
|
+
end
|
19
|
+
|
20
|
+
def load
|
21
|
+
return if loaded? || license_key.nil? || mib_directory.nil?
|
22
|
+
compile_mibs
|
23
|
+
set_formats
|
24
|
+
@loaded = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def loaded?
|
28
|
+
@loaded == true
|
29
|
+
end
|
30
|
+
|
31
|
+
# http://www.snmp4j.org/smi/doc/com/snmp4j/smi/SmiManager.html#findSmiObject(org.snmp4j.smi.OID)
|
32
|
+
def find_smi_object(oid)
|
33
|
+
return nil unless loaded?
|
34
|
+
manager.find_smi_object(SNMP4JR::SMI::OID.new(oid))
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# The SmiManager Pro class manages the Structure of Management Information
|
40
|
+
# (SMI) specifications. SMIv1 and v2 MIB modules can be parsed and compiled
|
41
|
+
# to a MIB repository which provides its content to SNMP4J through a OID and
|
42
|
+
# Variable formatter and parser.
|
43
|
+
def manager
|
44
|
+
@manager ||= SNMP4JR::SMI::SmiManager.new(license_key, driver)
|
45
|
+
end
|
46
|
+
|
47
|
+
# MemRepositoryDriver stores all MIB modules in memory.
|
48
|
+
# http://www.snmp4j.org/smi/doc/com/snmp4j/smi/util/MemRepositoryDriver.html
|
49
|
+
def driver
|
50
|
+
@driver ||= SNMP4JR::SMI::Util::MemRepositoryDriver.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def compile_mibs
|
54
|
+
results = manager.compile(mib_list,
|
55
|
+
compilation_monitor,
|
56
|
+
load_into_repository,
|
57
|
+
update_existent,
|
58
|
+
compile_leniently)
|
59
|
+
|
60
|
+
results.each do |result|
|
61
|
+
smi_errors = result.smi_error_list
|
62
|
+
file_name = result.file_name.to_s.split('/').last
|
63
|
+
last_file = nil
|
64
|
+
|
65
|
+
if last_file.nil? || last_file != file_name
|
66
|
+
debug "------ #{file_name} ------"
|
67
|
+
last_file = file_name
|
68
|
+
end
|
69
|
+
|
70
|
+
if smi_errors.nil?
|
71
|
+
debug ">>> OK: #{file_name}"
|
72
|
+
else
|
73
|
+
smi_errors.size.to_i.times do |i|
|
74
|
+
debug ">>> ERROR: #{file_name} ##{i + 1}: #{smi_errors.get(i).message}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
manager.list_modules.each do |mod|
|
80
|
+
debug "Loaded SNMP module '#{mod}'"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def set_formats
|
85
|
+
SNMP4JR::SNMP4JSettings.setOIDTextFormat(manager)
|
86
|
+
SNMP4JR::SNMP4JSettings.setVariableTextFormat(manager)
|
87
|
+
end
|
88
|
+
|
89
|
+
def mib_list
|
90
|
+
java.io.File.new(mib_directory).list_files
|
91
|
+
end
|
92
|
+
|
93
|
+
def debug(message = '')
|
94
|
+
puts(message) if debug?
|
95
|
+
end
|
96
|
+
|
97
|
+
def debug?
|
98
|
+
!ENV['DEBUG'].nil?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module SNMP4JR
|
2
|
+
class TrapListener
|
3
|
+
def initialize(options = {})
|
4
|
+
@protocol = options[:protocol] || 'udp'
|
5
|
+
@host = options[:host] || '127.0.0.1'
|
6
|
+
@port = options[:port] || 1162
|
7
|
+
@done = false
|
8
|
+
@lock = Mutex.new
|
9
|
+
@trap_handler = Proc.new {}
|
10
|
+
@handler_thread = Thread.new { process_traps }
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_trap(&block)
|
14
|
+
raise ArgumentError, 'a block must be provided' unless block
|
15
|
+
@lock.synchronize { @trap_handler = block }
|
16
|
+
end
|
17
|
+
|
18
|
+
def join
|
19
|
+
@handler_thread.join
|
20
|
+
end
|
21
|
+
|
22
|
+
def process_pdu(event)
|
23
|
+
begin
|
24
|
+
@trap_handler.call(Message.new(event))
|
25
|
+
rescue => e
|
26
|
+
puts "Error handling trap: #{e.message}"
|
27
|
+
puts e.backtrace.join("\n")
|
28
|
+
puts "Event:"
|
29
|
+
p event
|
30
|
+
end
|
31
|
+
end
|
32
|
+
alias_method :processPdu, :process_pdu
|
33
|
+
|
34
|
+
def close
|
35
|
+
@snmp.close if @snmp
|
36
|
+
@done = true
|
37
|
+
@handler_thread.join
|
38
|
+
end
|
39
|
+
|
40
|
+
alias_method :exit, :close
|
41
|
+
alias_method :kill, :close
|
42
|
+
alias_method :terminate, :close
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def process_traps
|
47
|
+
snmp.add_notification_listener(address, self)
|
48
|
+
snmp.listen
|
49
|
+
|
50
|
+
# TODO: Come up with a better way to block here
|
51
|
+
until @done
|
52
|
+
sleep 0.5
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def snmp
|
57
|
+
@snmp ||= SNMP4JR::Snmp.new(transport)
|
58
|
+
end
|
59
|
+
|
60
|
+
def transport
|
61
|
+
@transport ||= begin
|
62
|
+
if @protocol == 'tcp'
|
63
|
+
SNMP4JR::Transport::DefaultTcpTransportMapping.new
|
64
|
+
else
|
65
|
+
SNMP4JR::Transport::DefaultUdpTransportMapping.new
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def address
|
71
|
+
@address ||= SNMP4JR::SMI::GenericAddress.parse("#{@protocol}:#{@host}/#{@port}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module SNMP4JR
|
2
|
+
class VariableBinding
|
3
|
+
|
4
|
+
DATE_AND_TIME = 'DateAndTime'
|
5
|
+
IPV6_ADDRESS = 'InetAddressIPv6'
|
6
|
+
|
7
|
+
attr_reader :oid, :value, :variable_binding, :mib_manager
|
8
|
+
|
9
|
+
def initialize(variable_binding)
|
10
|
+
@variable_binding = variable_binding
|
11
|
+
@mib_manager = MibManager.instance
|
12
|
+
|
13
|
+
@oid = variable_binding.oid.to_s
|
14
|
+
@value = variable_binding.variable.to_s
|
15
|
+
|
16
|
+
format_smi_object
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def format_smi_object
|
22
|
+
return unless has_smi_syntax?
|
23
|
+
|
24
|
+
# If we have a DateAndTime object, parse it into a usable format.
|
25
|
+
if smi_syntax_clause == DATE_AND_TIME
|
26
|
+
date_and_time = SNMP4JR::SMI::OctetString.new(variable_binding.variable)
|
27
|
+
|
28
|
+
# Parse the SNMPv2-TC DateAndTime syntax into a datetime object.
|
29
|
+
# http://www.snmp4j.org/agent/doc/org/snmp4j/agent/mo/snmp/DateAndTime.html
|
30
|
+
calendar = SNMP4JR::Agent::MO::Snmp::DateAndTime.make_calendar(date_and_time)
|
31
|
+
|
32
|
+
# Convert datetime to Unix Epoch
|
33
|
+
@value = calendar.time_in_millis * 1000
|
34
|
+
|
35
|
+
# Addresses are (correctly) rendered like "ab:cd:ef:gh...",
|
36
|
+
# we want "abcd:efgh...."
|
37
|
+
elsif smi_syntax_clause == IPV6_ADDRESS
|
38
|
+
@value = value.gsub(/(..):(..)/,'\1\2')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_smi_syntax?
|
43
|
+
!smi_object.nil? && !smi_syntax.nil? && !smi_syntax_clause.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def smi_object
|
47
|
+
@smi_object ||= mib_manager.find_smi_object(oid)
|
48
|
+
end
|
49
|
+
|
50
|
+
def smi_syntax
|
51
|
+
@smi_syntax ||= smi_object.syntax if smi_object.respond_to?(:syntax)
|
52
|
+
end
|
53
|
+
|
54
|
+
def smi_syntax_clause
|
55
|
+
@smi_syntax_clause ||= smi_syntax.syntax_clause if smi_syntax.respond_to?(:syntax_clause)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'logstash-input-snmp4jtrap'
|
5
|
+
s.version = '1.0.2'
|
6
|
+
s.authors = ['Michael Zaccari']
|
7
|
+
s.email = ['michael.zaccari@accelerated.com']
|
8
|
+
|
9
|
+
s.summary = 'Read snmp trap messages as event with SNMP4J'
|
10
|
+
s.description = 'This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install logstash-input-snmp4jtrap. This gem is not a stand-alone program'
|
11
|
+
s.homepage = 'https://github.com/mzaccari/logstash-input-snmp4jtrap'
|
12
|
+
s.license = 'MIT'
|
13
|
+
s.require_paths = ['lib']
|
14
|
+
|
15
|
+
# Files
|
16
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE.txt']
|
17
|
+
|
18
|
+
# Tests
|
19
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
20
|
+
|
21
|
+
# Special flag to let us know this is actually a logstash plugin
|
22
|
+
s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'input' }
|
23
|
+
|
24
|
+
# Gem dependencies
|
25
|
+
s.add_runtime_dependency 'logstash-core-plugin-api', '~> 1.0'
|
26
|
+
s.add_runtime_dependency 'logstash-codec-plain'
|
27
|
+
|
28
|
+
s.add_development_dependency 'logstash-devutils'
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-input-snmp4jtrap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Zaccari
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.0'
|
19
|
+
name: logstash-core-plugin-api
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
name: logstash-codec-plain
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
name: logstash-devutils
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install logstash-input-snmp4jtrap. This gem is not a stand-alone program
|
56
|
+
email:
|
57
|
+
- michael.zaccari@accelerated.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- TODO.md
|
66
|
+
- lib/logstash/inputs/snmp4jtrap.rb
|
67
|
+
- lib/snmp4j-2.3.0.jar
|
68
|
+
- lib/snmp4j-agent-2.2.2.jar
|
69
|
+
- lib/snmp4j-smi-pro.jar
|
70
|
+
- lib/snmp4jr-smi-pro.rb
|
71
|
+
- lib/snmp4jr.rb
|
72
|
+
- lib/snmp4jr/message.rb
|
73
|
+
- lib/snmp4jr/mib_manager.rb
|
74
|
+
- lib/snmp4jr/trap_listener.rb
|
75
|
+
- lib/snmp4jr/variable_binding.rb
|
76
|
+
- logstash-input-snmp4jtrap.gemspec
|
77
|
+
- spec/logstash/input/snmp4jtrap_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
homepage: https://github.com/mzaccari/logstash-input-snmp4jtrap
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata:
|
83
|
+
logstash_plugin: 'true'
|
84
|
+
logstash_group: input
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.6.4
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Read snmp trap messages as event with SNMP4J
|
105
|
+
test_files:
|
106
|
+
- spec/logstash/input/snmp4jtrap_spec.rb
|
107
|
+
- spec/spec_helper.rb
|