logstash-input-snmp 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/logstash/inputs/snmp.rb +8 -1
- data/lib/logstash/inputs/snmp/base_client.rb +13 -47
- data/lib/logstash/inputs/snmp/client.rb +8 -0
- data/lib/logstash/inputs/snmp/clientv3.rb +24 -20
- data/logstash-input-snmp.gemspec +1 -1
- data/spec/inputs/snmp_spec.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb5609c18eaaec9aeef2b6061112def84acb1f2057d90bd507a785dcf452ccd4
|
4
|
+
data.tar.gz: 60bc0983f862f184d6b17b6e64c31c333998468d54610397b3ce4f1ed64e8163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d34c2e4575a756c34dfa4680bfed5f003787aeaee5cd5a73d8408eb76dce677c540e8437d778b0875ec5c1f75677322d3dfb6d2a10f85572479c1da28e8e8a7
|
7
|
+
data.tar.gz: f53c711c10cc10d51b4a9919e9b0c3624176df89bc79116cb394ee10ab15266e8a61f8907346c670e9d959f2cce1c387586850dd98c9b3135d1b20a434863131
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 1.2.4
|
2
|
+
- Fixed: support SNMPv3 multiple identical security name with different credentials [#84](https://github.com/logstash-plugins/logstash-input-snmp/pull/84)
|
3
|
+
|
1
4
|
## 1.2.3
|
2
5
|
- Fixed: multithreading problem when using multiple snmp inputs with multiple v3 credentials [#80](https://github.com/logstash-plugins/logstash-input-snmp/pull/80)
|
3
6
|
|
data/lib/logstash/inputs/snmp.rb
CHANGED
@@ -212,7 +212,14 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
215
|
-
def
|
215
|
+
def close
|
216
|
+
@client_definitions.each do |definition|
|
217
|
+
begin
|
218
|
+
definition[:client].close
|
219
|
+
rescue => e
|
220
|
+
logger.warn("error closing client on #{definition[:host_address]}, ignoring", :exception => e)
|
221
|
+
end
|
222
|
+
end
|
216
223
|
end
|
217
224
|
|
218
225
|
private
|
@@ -7,42 +7,6 @@ module LogStash
|
|
7
7
|
class SnmpClientError < StandardError
|
8
8
|
end
|
9
9
|
|
10
|
-
# Only one Snmp instance per transport should be created and listened on.
|
11
|
-
# The Snmp object is thread safe and can be shared across input threads and pipelines.
|
12
|
-
class SnmpFactory
|
13
|
-
java_import "org.snmp4j.Snmp"
|
14
|
-
java_import "org.snmp4j.transport.DefaultUdpTransportMapping"
|
15
|
-
java_import "org.snmp4j.transport.DefaultTcpTransportMapping"
|
16
|
-
|
17
|
-
include Singleton
|
18
|
-
|
19
|
-
def initialize
|
20
|
-
@lock = Mutex.new
|
21
|
-
@udp = nil
|
22
|
-
@tcp = nil
|
23
|
-
end
|
24
|
-
|
25
|
-
def udp
|
26
|
-
@lock.synchronize do
|
27
|
-
if @udp.nil?
|
28
|
-
@udp = Snmp.new(DefaultUdpTransportMapping.new)
|
29
|
-
@udp.listen
|
30
|
-
end
|
31
|
-
end
|
32
|
-
@udp
|
33
|
-
end
|
34
|
-
|
35
|
-
def tcp
|
36
|
-
@lock.synchronize do
|
37
|
-
if @tcp.nil?
|
38
|
-
@tcp = Snmp.new(DefaultTcpTransportMapping.new)
|
39
|
-
@tcp.listen
|
40
|
-
end
|
41
|
-
end
|
42
|
-
@tcp
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
10
|
class BaseSnmpClient
|
47
11
|
java_import "org.snmp4j.TransportMapping"
|
48
12
|
java_import "org.snmp4j.mp.SnmpConstants"
|
@@ -51,20 +15,13 @@ module LogStash
|
|
51
15
|
java_import "org.snmp4j.util.TableUtils"
|
52
16
|
java_import "org.snmp4j.util.TreeUtils"
|
53
17
|
java_import "org.snmp4j.asn1.BER"
|
18
|
+
java_import "org.snmp4j.transport.DefaultUdpTransportMapping"
|
19
|
+
java_import "org.snmp4j.transport.DefaultTcpTransportMapping"
|
54
20
|
|
55
21
|
include LogStash::Util::Loggable
|
56
22
|
|
57
23
|
def initialize(protocol, address, port, retries, timeout, mib)
|
58
24
|
@mib = mib
|
59
|
-
|
60
|
-
transport = case protocol.to_s
|
61
|
-
when "udp"
|
62
|
-
@snmp = SnmpFactory.instance.udp
|
63
|
-
when "tcp"
|
64
|
-
@snmp = SnmpFactory.instance.tcp
|
65
|
-
else
|
66
|
-
raise(SnmpClientError, "invalid transport protocol specified '#{protocol.to_s}', expecting 'udp' or 'tcp'")
|
67
|
-
end
|
68
25
|
end
|
69
26
|
|
70
27
|
def get(oids, strip_root = 0, path_length = 0)
|
@@ -94,7 +51,6 @@ module LogStash
|
|
94
51
|
result
|
95
52
|
end
|
96
53
|
|
97
|
-
|
98
54
|
def walk(oid, strip_root = 0, path_length = 0)
|
99
55
|
result = {}
|
100
56
|
|
@@ -202,7 +158,6 @@ module LogStash
|
|
202
158
|
end
|
203
159
|
end
|
204
160
|
|
205
|
-
|
206
161
|
def parse_version(version)
|
207
162
|
case version.to_s
|
208
163
|
when "3"
|
@@ -218,6 +173,17 @@ module LogStash
|
|
218
173
|
|
219
174
|
private
|
220
175
|
|
176
|
+
def create_transport(protocol)
|
177
|
+
case protocol.to_s
|
178
|
+
when "udp"
|
179
|
+
DefaultUdpTransportMapping.new
|
180
|
+
when "tcp"
|
181
|
+
DefaultTcpTransportMapping.new
|
182
|
+
else
|
183
|
+
raise(SnmpClientError, "invalid transport protocol specified '#{protocol.to_s}', expecting 'udp' or 'tcp'")
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
221
187
|
def get_pdu
|
222
188
|
raise("abstract method")
|
223
189
|
end
|
@@ -18,9 +18,17 @@ module LogStash
|
|
18
18
|
def initialize(protocol, address, port, community, version, retries, timeout, mib)
|
19
19
|
super(protocol, address, port, retries, timeout, mib)
|
20
20
|
raise(SnmpClientError, "SnmpClient is expecting verison '1' or '2c'") unless ["1", "2c"].include?(version.to_s)
|
21
|
+
|
22
|
+
@snmp = Snmp.new(create_transport(protocol))
|
23
|
+
@snmp.listen
|
24
|
+
|
21
25
|
@target = build_target("#{protocol}:#{address}/#{port}", community, version, retries, timeout)
|
22
26
|
end
|
23
27
|
|
28
|
+
def close
|
29
|
+
@snmp.close
|
30
|
+
end
|
31
|
+
|
24
32
|
private
|
25
33
|
|
26
34
|
def get_pdu
|
@@ -3,23 +3,6 @@ require 'logstash-input-snmp_jars.rb'
|
|
3
3
|
|
4
4
|
module LogStash
|
5
5
|
|
6
|
-
# Only a single USM instance should be created and added to the SecurityModels
|
7
|
-
class USMFactory
|
8
|
-
java_import 'org.snmp4j.security.SecurityProtocols'
|
9
|
-
java_import 'org.snmp4j.security.SecurityModels'
|
10
|
-
java_import 'org.snmp4j.security.USM'
|
11
|
-
java_import 'org.snmp4j.smi.OctetString'
|
12
|
-
java_import 'org.snmp4j.mp.MPv3'
|
13
|
-
|
14
|
-
include Singleton
|
15
|
-
attr_reader :usm
|
16
|
-
|
17
|
-
def initialize
|
18
|
-
@usm = USM.new(SecurityProtocols.getInstance, OctetString.new(MPv3.createLocalEngineID), 0)
|
19
|
-
SecurityModels.getInstance.addSecurityModel(@usm)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
6
|
class SnmpClientV3 < BaseSnmpClient
|
24
7
|
java_import 'org.snmp4j.PDU'
|
25
8
|
java_import 'org.snmp4j.ScopedPDU'
|
@@ -41,11 +24,16 @@ module LogStash
|
|
41
24
|
java_import 'org.snmp4j.security.PrivAES256'
|
42
25
|
java_import 'org.snmp4j.security.UsmUser'
|
43
26
|
java_import 'org.snmp4j.security.SecurityLevel'
|
27
|
+
java_import 'org.snmp4j.security.SecurityModels'
|
28
|
+
java_import 'org.snmp4j.security.SecurityProtocols'
|
29
|
+
java_import 'org.snmp4j.security.USM'
|
44
30
|
java_import 'org.snmp4j.smi.Address'
|
45
31
|
java_import 'org.snmp4j.smi.GenericAddress'
|
46
32
|
java_import 'org.snmp4j.smi.OctetString'
|
47
33
|
java_import 'org.snmp4j.UserTarget'
|
48
34
|
java_import 'org.snmp4j.util.DefaultPDUFactory'
|
35
|
+
java_import 'org.snmp4j.mp.MPv3'
|
36
|
+
java_import "org.snmp4j.MessageDispatcherImpl"
|
49
37
|
|
50
38
|
def initialize(protocol, address, port, retries, timeout, mib, security_name, auth_protocol, auth_pass, priv_protocol, priv_pass, security_level)
|
51
39
|
super(protocol, address, port, retries, timeout, mib)
|
@@ -57,13 +45,29 @@ module LogStash
|
|
57
45
|
auth_pass = auth_pass.nil? ? nil : OctetString.new(auth_pass)
|
58
46
|
priv_pass = priv_pass.nil? ? nil : OctetString.new(priv_pass)
|
59
47
|
|
60
|
-
|
61
|
-
|
48
|
+
engine_id = OctetString.new(MPv3.createLocalEngineID)
|
49
|
+
|
50
|
+
security_protocols = SecurityProtocols.getInstance
|
51
|
+
security_protocols.addDefaultProtocols
|
52
|
+
|
53
|
+
usm = USM.new(security_protocols, engine_id, 0)
|
54
|
+
usm.addUser(UsmUser.new(security_name, auth_protocol, auth_pass, priv_protocol, priv_pass))
|
55
|
+
|
56
|
+
SecurityModels.getInstance.addSecurityModel(usm)
|
57
|
+
|
58
|
+
dispatcher = MessageDispatcherImpl.new
|
59
|
+
dispatcher.addMessageProcessingModel(MPv3.new(usm))
|
60
|
+
|
61
|
+
@snmp = Snmp.new(dispatcher, create_transport(protocol))
|
62
|
+
@snmp.listen
|
62
63
|
|
63
|
-
@snmp.getUSM.addUser(UsmUser.new(security_name, auth_protocol, auth_pass, priv_protocol, priv_pass))
|
64
64
|
@target = build_target("#{protocol}:#{address}/#{port}", security_name, security_level, retries, timeout)
|
65
65
|
end
|
66
66
|
|
67
|
+
def close
|
68
|
+
@snmp.close
|
69
|
+
end
|
70
|
+
|
67
71
|
private
|
68
72
|
|
69
73
|
def build_target(address, name, seclevel, retries, timeout)
|
data/logstash-input-snmp.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-input-snmp'
|
3
|
-
s.version = '1.2.
|
3
|
+
s.version = '1.2.4'
|
4
4
|
s.licenses = ['Apache-2.0']
|
5
5
|
s.summary = "SNMP input plugin"
|
6
6
|
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 gemname. This gem is not a stand-alone program"
|
data/spec/inputs/snmp_spec.rb
CHANGED
@@ -15,6 +15,8 @@ describe LogStash::Inputs::Snmp do
|
|
15
15
|
before do
|
16
16
|
expect(LogStash::SnmpClient).to receive(:new).and_return(mock_client)
|
17
17
|
expect(mock_client).to receive(:get).and_return({})
|
18
|
+
# devutils in v6 calls close on the test pipelines while it does not in v7+
|
19
|
+
expect(mock_client).to receive(:close).at_most(:once)
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
@@ -128,6 +130,8 @@ describe LogStash::Inputs::Snmp do
|
|
128
130
|
before do
|
129
131
|
expect(LogStash::SnmpClient).to receive(:new).and_return(mock_client)
|
130
132
|
expect(mock_client).to receive(:get).and_return({"foo" => "bar"})
|
133
|
+
# devutils in v6 calls close on the test pipelines while it does not in v7+
|
134
|
+
expect(mock_client).to receive(:close).at_most(:once)
|
131
135
|
end
|
132
136
|
|
133
137
|
it "shoud add @metadata fields and add default host field" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-input-snmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elasticsearch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|