logstash-input-snmp 0.1.0.beta2 → 0.1.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5599c9705618d89025096ef93521fc9af9c3459b34e57e1dabe3b697918ffca1
4
- data.tar.gz: 3b86026c9b6239f0628408d39926a757d7308c0d72b6fdf6a5742f2cc2cc2c1b
3
+ metadata.gz: 4cbe158bdaf1a09765f4f5590c770c85cd5005a094ee867ac97b720f39b69bab
4
+ data.tar.gz: 4be94637f117dd5e5e31d29c58c25e8c50aa307266f4b15b37bc749dcee3e462
5
5
  SHA512:
6
- metadata.gz: c03af9c1da2efbbdccff38d322ed7b8f15331cca3de4b987d22145c2b150d1c93a65035a664d88a245c89e0461ba3a89236a429b3d806cc996503ecce55fa60a
7
- data.tar.gz: da07ed21485a35b58b915f974003ad747c3ff6d4a36ed1b6ccb07d3f8066e7910ed826e8ff5f63454f2fb4af5cc663aceb8755f18959f35d016bc19e137e46a2
6
+ metadata.gz: dbe55fe3d13e49d62c4a7376aef50f3daf38e19aeaddcb9dd32c933d648a1dc2fb69adb6625e3cc24d05559cf20faa25bf6785192299ae5da3781c1bf7a240fd
7
+ data.tar.gz: 8f93b7fbb5005b8c4321e7d39534b7f2a540da3f2aa0b6d30c433d66f59578bcf5af042db64533fd54b2869404aff9ecf0af4bd6feb91f4f1400c33511ffe1cd
@@ -1,3 +1,7 @@
1
+ ## 0.1.0.beta3
2
+ - add tcp transport protocol support, https://github.com/logstash-plugins/logstash-input-snmp/pull/8
3
+ - add SNMPv1 protocol version support, https://github.com/logstash-plugins/logstash-input-snmp/pull/9
4
+
1
5
  ## 0.1.0.beta2
2
6
  - add host info in metadata and host field, https://github.com/logstash-plugins/logstash-input-snmp/pull/7
3
7
 
@@ -26,7 +26,7 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
26
26
  # for example `host => "udp:127.0.0.1/161"`
27
27
  # Each host definition can optionally include the following keys and values:
28
28
  # `community` with a default value of `public`
29
- # `version` with a default value of `2c`
29
+ # `version` `1` or `2c` with a default value of `2c`
30
30
  # `retries` with a detault value of `2`
31
31
  # `timeout` in milliseconds with a default value of `1000`
32
32
  config :hosts, :validate => :array #[ {"host" => "udp:127.0.0.1/161", "community" => "public"} ]
@@ -71,21 +71,28 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
71
71
  host_name = host["host"]
72
72
  community = host["community"] || "public"
73
73
  version = host["version"] || "2c"
74
+ raise(LogStash::ConfigurationError, "only protocol version '1' and '2c' are supported for host option '#{host_name}'") unless version =~ VERSION_REGEX
75
+
74
76
  retries = host["retries"] || 2
75
77
  timeout = host["timeout"] || 1000
76
78
 
79
+ # TODO: move these validations in a custom validator so it happens before the register method is called.
77
80
  host_details = host_name.match(HOST_REGEX)
78
81
  raise(LogStash::ConfigurationError, "invalid format for host option '#{host_name}'") unless host_details
79
- raise(LogStash::ConfigurationError, "only the udp protocol is supported for now") unless host_details[:host_protocol].to_s =~ /udp/i
82
+ raise(LogStash::ConfigurationError, "only udp & tcp protocols are supported for host option '#{host_name}'") unless host_details[:host_protocol].to_s =~ /^(?:udp|tcp)$/i
83
+
84
+ protocol = host_details[:host_protocol]
85
+ address = host_details[:host_address]
86
+ port = host_details[:host_port]
80
87
 
81
88
  definition = {
82
- :client => LogStash::SnmpClient.new(host_name, community, version, retries, timeout, mib),
89
+ :client => LogStash::SnmpClient.new(protocol, address, port, community, version, retries, timeout, mib),
83
90
  :get => Array(get),
84
91
  :walk => Array(walk),
85
92
 
86
- :host_protocol => host_details[:host_protocol],
87
- :host_address => host_details[:host_address],
88
- :host_port => host_details[:host_port],
93
+ :host_protocol => protocol,
94
+ :host_address => address,
95
+ :host_port => port,
89
96
  :host_community => community,
90
97
  }
91
98
  @client_definitions << definition
@@ -141,6 +148,7 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
141
148
 
142
149
  OID_REGEX = /^\.?([0-9\.]+)$/
143
150
  HOST_REGEX = /^(?<host_protocol>udp|tcp):(?<host_address>.+)\/(?<host_port>\d+)$/i
151
+ VERSION_REGEX =/^1|2c$/
144
152
 
145
153
  def validate_oids!
146
154
  @get = Array(@get).map do |oid|
@@ -14,6 +14,7 @@ java_import "org.snmp4j.smi.OID"
14
14
  java_import "org.snmp4j.smi.OctetString"
15
15
  java_import "org.snmp4j.smi.VariableBinding"
16
16
  java_import "org.snmp4j.transport.DefaultUdpTransportMapping"
17
+ java_import "org.snmp4j.transport.DefaultTcpTransportMapping"
17
18
  java_import "org.snmp4j.util.TreeUtils"
18
19
  java_import "org.snmp4j.util.DefaultPDUFactory"
19
20
  java_import "org.snmp4j.asn1.BER"
@@ -24,12 +25,19 @@ module LogStash
24
25
 
25
26
  class SnmpClient
26
27
 
27
- def initialize(address, community, version, retries, timeout, mib)
28
- @target = build_target(address, community, version, retries, timeout)
28
+ def initialize(protocol, address, port, community, version, retries, timeout, mib)
29
+ transport = case protocol.to_s
30
+ when "udp"
31
+ DefaultUdpTransportMapping.new
32
+ when "tcp"
33
+ DefaultTcpTransportMapping.new
34
+ else
35
+ raise(SnmpClientError, "invalid transport protocol specified '#{protocol.to_s}', expecting 'udp' or 'tcp'")
36
+ end
37
+
38
+ @target = build_target("#{protocol}:#{address}/#{port}", community, version, retries, timeout)
29
39
  @mib = mib
30
40
 
31
- # for now hardwired udp transport
32
- transport = DefaultUdpTransportMapping.new
33
41
  @snmp = Snmp.new(transport)
34
42
  transport.listen()
35
43
  end
@@ -128,8 +136,14 @@ module LogStash
128
136
  end
129
137
 
130
138
  def parse_version(version)
131
- # TODO implement
132
- SnmpConstants.version2c
139
+ case version.to_s
140
+ when "2c"
141
+ SnmpConstants.version2c
142
+ when "1"
143
+ SnmpConstants.version1
144
+ else
145
+ raise(SnmpClientError, "protocol version '#{version}' is not supported, expected versions are '1' and '2c'")
146
+ end
133
147
  end
134
148
  end
135
149
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-snmp'
3
- s.version = '0.1.0.beta2'
3
+ s.version = '0.1.0.beta3'
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"
@@ -54,19 +54,25 @@ describe LogStash::Inputs::Snmp do
54
54
  {"get" => ["1.0"], "hosts" => [{"host" => "udp:localhost/161"}]},
55
55
  {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/112345"}]},
56
56
  {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "community" => "public"}]},
57
+ {"get" => ["1.0"], "hosts" => [{"host" => "tcp:127.0.0.1/112345"}]},
58
+ {"get" => ["1.0"], "hosts" => [{"host" => "tcp:127.0.0.1/161", "community" => "public"}]},
59
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "1"}]},
60
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "2c"}]},
57
61
  ]
58
62
  }
59
63
 
60
64
  let(:invalid_configs) {
61
65
  [
62
66
  {"get" => ["1.0"], "hosts" => [{"host" => "aaa:127.0.0.1/161"}]},
63
- {"get" => ["1.0"], "hosts" => [{"host" => "tcp:127.0.0.1/161"}]},
67
+ {"get" => ["1.0"], "hosts" => [{"host" => "tcp.127.0.0.1/161"}]},
64
68
  {"get" => ["1.0"], "hosts" => [{"host" => "localhost"}]},
65
69
  {"get" => ["1.0"], "hosts" => [{"host" => "localhost/161"}]},
66
70
  {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1"}]},
67
71
  {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/"}]},
68
72
  {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/aaa"}]},
69
73
  {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161"}, {"host" => "udp:127.0.0.1/aaa"}]},
74
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "2"}]},
75
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "version" => "3"}]},
70
76
  {"get" => ["1.0"], "hosts" => ""},
71
77
  {"get" => ["1.0"], "hosts" => []},
72
78
  {"get" => ["1.0"] },
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: 0.1.0.beta2
4
+ version: 0.1.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement