logstash-input-snmp 0.1.0.beta5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb2edaea9339e4955345a99d3a7c36c3c11eb907d91ee91c7aadb9110a68c215
4
- data.tar.gz: bcd78c64a492e9025f277a5139d7517d75e52aa741f8c7314b4b9c51c0285879
3
+ metadata.gz: 9e8dd0042c7e0a91cfda117ab654b9633159d398e7cd13170a6e301a6de95fc8
4
+ data.tar.gz: 553989d20b7c2bd9bea0194f7513088dbf8629d2f59a9fbc2a7653af472a6c0a
5
5
  SHA512:
6
- metadata.gz: 4e6d4213da72a049d9d8f02a3e2ea9e6a93915746595bd14cb5e4c7115f74d549f97c069698090d89fc80a29095f4b399e05362e7449d2c84543cb7be0016d17
7
- data.tar.gz: 50441d39a18880a799cbf444af8ddf424d7c348b9f6ef162af195cd221310008b90f5bf58805fdabeea33f21fb33deafd557f64390383a84b175480e90a69017
6
+ metadata.gz: '0130086878a261d29b22b9bdb35b1607ac7fb7af1ef56207d9b690a7bbbf3416e98336071c06262e5268373834c96037e4175d87e59b6e9a25b4ccb7854afd2e'
7
+ data.tar.gz: bf4dfa3e025ebabd1eb4f9f064f9fccc79a62b9aab6971b593a4f7a68d6d389881df6069cc2c4a715b9b2e9db2552126068dc6148d1a9a1bc4f162dd6bb26086
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.0.0
2
+ - Added improved syntax coercion [#32](https://github.com/logstash-plugins/logstash-input-snmp/pull/32)
3
+
1
4
  ## 0.1.0.beta5
2
5
  - Added OPAQUE type coercion [#29](https://github.com/logstash-plugins/logstash-input-snmp/pull/29)
3
6
  - Added SNMPv3 support [#27](https://github.com/logstash-plugins/logstash-input-snmp/pull/27)
@@ -0,0 +1,309 @@
1
+ :plugin: snmp
2
+ :type: input
3
+ :default_codec: plain
4
+
5
+ // TO DO: VERIFY default codec!
6
+
7
+ ///////////////////////////////////////////
8
+ START - GENERATED VARIABLES, DO NOT EDIT!
9
+ ///////////////////////////////////////////
10
+ :version: %VERSION%
11
+ :release_date: %RELEASE_DATE%
12
+ :changelog_url: %CHANGELOG_URL%
13
+ :include_path: ../../../../logstash/docs/include
14
+ ///////////////////////////////////////////
15
+ END - GENERATED VARIABLES, DO NOT EDIT!
16
+ ///////////////////////////////////////////
17
+
18
+ [id="plugins-{type}s-{plugin}"]
19
+
20
+ === SNMP input plugin
21
+
22
+ include::{include_path}/plugin_header.asciidoc[]
23
+
24
+ ==== Description
25
+
26
+ The SNMP input polls network devices using Simple Network Management Protocol (SNMP)
27
+ to gather information related to the current state of the devices operation.
28
+
29
+ [id="plugins-{type}s-{plugin}-import-mibs"]
30
+ ==== Importing MIBs
31
+
32
+ This plugin already includes the IETF MIBs (management information bases) and these do not need to be imported.
33
+
34
+ Any other MIB will need to be manually imported to provide mapping of the numeric OIDs to MIB field names in the resulting event.
35
+
36
+ To import a MIB, the OSS https://www.ibr.cs.tu-bs.de/projects/libsmi/[libsmi library] is required.
37
+ libsmi is available and installable on most operating systems.
38
+
39
+ To import a MIB, you need to first convert the ASN.1 MIB file into a `.dic` file using the libsmi `smidump` command line utility.
40
+
41
+ Example (using `RFC1213-MIB` file)
42
+
43
+ [source,sh]
44
+ -----
45
+ $ smidump --level=1 -k -f python RFC1213-MIB > RFC1213-MIB.dic
46
+ -----
47
+
48
+ Note that the resulting file as output by `smidump` must have the `.dic` extension.
49
+
50
+ [id="plugins-{type}s-{plugin}-options"]
51
+ ==== SNMP Input Configuration Options
52
+
53
+ This plugin supports the following configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
54
+
55
+ [cols="<,<,<",options="header",]
56
+ |=======================================================================
57
+ |Setting |Input type|Required
58
+ | <<plugins-{type}s-{plugin}-auth_pass>> |<<password,password>>|No
59
+ | <<plugins-{type}s-{plugin}-auth_protocol>> |<<string,string>>, one of `["md5", "sha", "sha2", "hmac128sha224", "hmac192sha256", "hmac256sha384", "hmac384sha512"]`|No
60
+ | <<plugins-{type}s-{plugin}-get>> |<<array,array>>|No
61
+ | <<plugins-{type}s-{plugin}-hosts>> |<<array,array>>|No
62
+ | <<plugins-{type}s-{plugin}-interval>> |<<number,number>>|No
63
+ | <<plugins-{type}s-{plugin}-mib_paths>> |<<path,path>>|No
64
+ | <<plugins-{type}s-{plugin}-oid_root_skip>> |<<boolean,boolean>>|No
65
+ | <<plugins-{type}s-{plugin}-priv_pass>> |<<password,password>>|No
66
+ | <<plugins-{type}s-{plugin}-priv_protocol>> |<<string,string>>, one of `["des", "3des", "aes", "aes128", "aes192", "aes256"]`|No
67
+ | <<plugins-{type}s-{plugin}-security_level>> |<<string,string>>, one of `["noAuthNoPriv", "authNoPriv", "authPriv"]`|No
68
+ | <<plugins-{type}s-{plugin}-security_name>> |<<string,string>>|No
69
+ | <<plugins-{type}s-{plugin}-walk>> |<<array,array>>|No
70
+ |=======================================================================
71
+
72
+ Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
73
+ input plugins.
74
+
75
+ [id="plugins-{type}s-{plugin}-get"]
76
+ ===== `get`
77
+
78
+ Use the `get` option to query for scalar values for the given OID(s).
79
+ One or more OID(s) are specified as an array of strings of OID(s).
80
+
81
+ * Value type is <<array,array>>
82
+ * There is no default value for this setting
83
+
84
+ Example
85
+ [source,ruby]
86
+ -----
87
+ input {
88
+ snmp {
89
+ get => ["1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.3.0", "1.3.6.1.2.1.1.5.0"]
90
+ hosts => [{host => "udp:127.0.0.1/161" community => "public"}]
91
+ }
92
+ }
93
+ -----
94
+
95
+ [id="plugins-{type}s-{plugin}-hosts"]
96
+ ===== `hosts`
97
+
98
+ The `hosts` option specifies the list of hosts to query the configured `get` and `walk` options.
99
+
100
+ Each host definition is a hash and must define the `host` key and value.
101
+ `host` must use the format `{tcp|udp}:{ip address}/{port}`, for example `host => "udp:127.0.0.1/161"`
102
+
103
+ * Value type is <<array,array>>
104
+ * There is no default value for this setting
105
+
106
+ Each host definition can optionally include the following keys and values:
107
+
108
+ * `community` the community string, default is `public`.
109
+ * `version` `1`, `2c` or `3`, default is `2c`.
110
+ * `retries` is the number of retries in case of failure, default is `2`.
111
+ * `timeout` is the timeout in milliseconds with a default value of `1000`.
112
+
113
+ *Specifying all hosts options*
114
+
115
+ [source,ruby]
116
+ -----
117
+ input {
118
+ snmp {
119
+ get => ["1.3.6.1.2.1.1.1.0"]
120
+ hosts => [{host => "udp:127.0.0.1/161" community => "public" version => "2c" retries => 2 timeout => 1000}]
121
+ }
122
+ }
123
+ -----
124
+
125
+ *Specifying multiple hosts*
126
+
127
+ [source,ruby]
128
+ -----
129
+ input {
130
+ snmp {
131
+ get => ["1.3.6.1.2.1.1.1.0"]
132
+ hosts => [{host => "udp:127.0.0.1/161" community => "public"}, {host => "udp:192.168.0.1/161" community => "private"}]
133
+ }
134
+ }
135
+ -----
136
+
137
+ [id="plugins-{type}s-{plugin}-interval"]
138
+ ===== `interval`
139
+
140
+ The `interval` option specifies the polling interval in seconds.
141
+
142
+ * Value type is <<number,number>>
143
+ * Default value is `30`
144
+
145
+ [id="plugins-{type}s-{plugin}-mib_paths"]
146
+ ===== `mib_paths`
147
+
148
+ The `mib_paths` option specifies the location of one or more imported MIB files. The value can be either a dir path containing
149
+ the imported MIB `.dic` files or a file path to a single MIB `.dic` file.
150
+
151
+ * Value type is <<path,path>>
152
+ * There is no default value for this setting
153
+
154
+ This plugin includes the IETF MIBs.
155
+ If you require other MIBs, you need to import them. See <<plugins-{type}s-{plugin}-import-mibs>>.
156
+
157
+ [id="plugins-{type}s-{plugin}-oid_root_skip"]
158
+ ===== `oid_root_skip`
159
+
160
+ The `oid_root_skip` option specifies the number of OID root digits to ignore in event field name.
161
+ For example, in a numeric OID like "1.3.6.1.2.1.1.1.0" the first 5 digits could be ignored by setting `oid_root_skip => 5`
162
+ which would result in a field name "1.1.1.0". Similarly when a MIB is used an OID such
163
+ "1.3.6.1.2.mib-2.system.sysDescr.0" would become "mib-2.system.sysDescr.0"
164
+
165
+ * Value type is <<number,number>>
166
+ * Default value is `0`
167
+
168
+ [id="plugins-{type}s-{plugin}-walk"]
169
+ ===== `walk`
170
+
171
+ Use the `walk` option to retrieve the subtree of information for the given OID(s).
172
+ One or more OID(s) are specified as an array of strings of OID(s).
173
+
174
+ * Value type is <<array,array>>
175
+ * There is no default value for this setting
176
+
177
+ Queries the subtree of information starting at the given OID(s).
178
+
179
+ Example
180
+ [source,ruby]
181
+ -----
182
+ snmp {
183
+ walk => ["1.3.6.1.2.1.1"]
184
+ hosts => [{host => "udp:127.0.0.1/161" community => "public"}]
185
+ }
186
+ }
187
+ -----
188
+
189
+ ==== SNMPv3 Authentication Options
190
+
191
+ A **single user** can be configured and will be used for all defined SNMPv3 hosts.
192
+ Multiple snmp input declarations will be needed if multiple SNMPv3 users are required.
193
+ These options are required only if you are using SNMPv3.
194
+
195
+ [id="plugins-{type}s-{plugin}-auth_pass"]
196
+ ===== `auth_pass`
197
+
198
+ The `auth_pass` option specifies the SNMPv3 authentication passphrase or password
199
+
200
+ * Value type is <<password,password>>
201
+ * There is no default value for this setting
202
+
203
+ [id="plugins-{type}s-{plugin}-auth_protocol"]
204
+ ===== `auth_protocol`
205
+
206
+ The `auth_protocol` option specifies the SNMPv3 authentication protocol or type
207
+
208
+ * Value can be any of: `md5`, `sha`, `sha2`, `hmac128sha224`, `hmac192sha256`, `hmac256sha384`, `hmac384sha512`
209
+ * There is no default value for this setting
210
+
211
+ [id="plugins-{type}s-{plugin}-priv_pass"]
212
+ ===== `priv_pass`
213
+
214
+ The `priv_pass` option specifies the SNMPv3 encryption password
215
+
216
+ * Value type is <<password,password>>
217
+ * There is no default value for this setting
218
+
219
+ [id="plugins-{type}s-{plugin}-priv_protocol"]
220
+ ===== `priv_protocol`
221
+
222
+ The `priv_protocol` option specifies the SNMPv3 privacy/encryption protocol
223
+
224
+ * Value can be any of: `des`, `3des`, `aes`, `aes128`, `aes192`, `aes256`
225
+ * There is no default value for this setting
226
+
227
+ [id="plugins-{type}s-{plugin}-security_name"]
228
+ ===== `security_name`
229
+
230
+ The `security_name` option specifies the SNMPv3 security name or user name
231
+
232
+ * Value type is <<string,string>>
233
+ * There is no default value for this setting
234
+
235
+ [id="plugins-{type}s-{plugin}-security_level"]
236
+ ===== `security_level`
237
+
238
+ The `security_level` option specifies the SNMPv3 security level between Authentication, No Privacy; Authentication, Privacy; or no Authentication, no Privacy
239
+
240
+ * Value can be any of: `noAuthNoPriv`, `authNoPriv`, `authPriv`
241
+ * There is no default value for this setting
242
+
243
+ ==== More configuration examples
244
+
245
+ *Using both `get` and `walk` in the same poll cycle for each host(s)*
246
+
247
+ [source,ruby]
248
+ -----
249
+ input {
250
+ snmp {
251
+ get => ["1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.3.0", "1.3.6.1.2.1.1.5.0"]
252
+ walk => ["1.3.6.1.2.1.1"]
253
+ hosts => [{host => "udp:127.0.0.1/161" community => "public"}]
254
+ }
255
+ }
256
+ -----
257
+
258
+ *Specifying all global options*
259
+
260
+ [source,ruby]
261
+ -----
262
+ input {
263
+ snmp {
264
+ get => ["1.3.6.1.2.1.1.1.0"]
265
+ hosts => [{host => "udp:127.0.0.1/161"}]
266
+
267
+ mib_paths => ["path/to/converted/mibfile.dic"]
268
+ oid_root_skip => 0
269
+ interval => 30
270
+ }
271
+ }
272
+ -----
273
+
274
+ ==== Polled host information
275
+
276
+ All the polled host information is stored in the event `@metadata`:
277
+
278
+ * `[@metadata][host_protocol]` : `udp` or `tcp`
279
+ * `[@metadata][host_address]` : host address for example `127.0.0.1`
280
+ * `[@metadata][host_port]` : host port (for example `161`)
281
+ * `[@metadata][host_community]` : community string for example `public`
282
+
283
+
284
+ By default, a `host` field is added to the event with the `[@metadata][host_address]` value.
285
+
286
+ [source,ruby]
287
+ -----
288
+ config :add_field, :validate => :hash, :default => { "host" => "%{[@metadata][host_address]}" }
289
+ -----
290
+
291
+ You can customize the format and content of the `host` field by specifying an alternate `add_field`.
292
+
293
+ Example
294
+ [source,ruby]
295
+ -----
296
+ input {
297
+ snmp {
298
+ get => ["1.3.6.1.2.1.1.1.0"]
299
+ hosts => [{host => "udp:127.0.0.1/161"}]
300
+
301
+ add_field => {host => "%{[@metadata][host_protocol]}:%{[@metadata][host_address]}/%{[@metadata][host_port]},%{[@metadata][host_community]}"}
302
+ }
303
+ }
304
+ -----
305
+
306
+ [id="plugins-{type}s-{plugin}-common-options"]
307
+ include::{include_path}/{type}.asciidoc[]
308
+
309
+ :default_codec!:
@@ -1,6 +1,8 @@
1
1
  require "java"
2
2
  require "logstash-input-snmp_jars.rb"
3
3
 
4
+ require "logstash/util/loggable"
5
+
4
6
  java_import "org.snmp4j.CommunityTarget"
5
7
  java_import "org.snmp4j.PDU"
6
8
  java_import "org.snmp4j.ScopedPDU"
@@ -25,6 +27,7 @@ module LogStash
25
27
  end
26
28
 
27
29
  class BaseSnmpClient
30
+ include LogStash::Util::Loggable
28
31
 
29
32
  def initialize(protocol, address, port, retries, timeout, mib)
30
33
  transport = case protocol.to_s
@@ -124,10 +127,12 @@ module LogStash
124
127
  NULL_STRING
125
128
  when BER::OPAQUE
126
129
  variable.toString
127
- when BER::NOSUCHOBJECT
128
- "Error: No Such Instance currently exists at this OID"
130
+ when BER::NOSUCHOBJECT, BER::NOSUCHINSTANCE
131
+ "error: no such instance currently exists at this OID"
129
132
  else
130
- raise(SnmpClientError, "unknown variable syntax #{variable_syntax}, #{variable.getSyntaxString}")
133
+ msg = "error: unknown variable syntax #{variable_syntax}, #{variable.getSyntaxString}"
134
+ logger.error(msg)
135
+ msg
131
136
  end
132
137
  end
133
138
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-snmp'
3
- s.version = '0.1.0.beta5'
3
+ s.version = '1.0.0'
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"
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/snmp/base_client"
4
+
5
+ java_import "org.snmp4j.smi.AbstractVariable"
6
+ java_import "org.snmp4j.smi.SMIConstants"
7
+
8
+ module LogStash
9
+
10
+ class TestableBaseSnmpClient < BaseSnmpClient
11
+ def coerce(*args)
12
+ super(*args)
13
+ end
14
+ end
15
+
16
+ describe BaseSnmpClient do
17
+
18
+ subject { TestableBaseSnmpClient.new(*client_options) }
19
+
20
+ context "coercion" do
21
+ let(:mib) { SnmpMib.new }
22
+ let(:client_options) {["udp", "127.0.0.1", "161", 2, 1000, mib]}
23
+
24
+ it "should handle BER::NOSUCHINSTANCE" do
25
+ v = AbstractVariable.create_from_syntax(SMIConstants::EXCEPTION_NO_SUCH_INSTANCE)
26
+ expect(v.get_syntax).to eq(BER::NOSUCHINSTANCE)
27
+ expect(subject).to receive(:logger).never
28
+ expect(subject.coerce(v)).to eq("error: no such instance currently exists at this OID")
29
+ end
30
+
31
+ it "should log on unsupported coercion" do
32
+ v = AbstractVariable.create_from_syntax(SMIConstants::EXCEPTION_END_OF_MIB_VIEW )
33
+ expect(subject).to receive(:logger).exactly(1).times.and_call_original
34
+ expect(subject.coerce(v)).to eq("error: unknown variable syntax 130, EndOfMibView")
35
+ end
36
+ end
37
+ end
38
+ end
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.beta5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elasticsearch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-03 00:00:00.000000000 Z
11
+ date: 2018-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -106,6 +106,7 @@ files:
106
106
  - Gemfile
107
107
  - LICENSE
108
108
  - README.md
109
+ - docs/index.asciidoc
109
110
  - lib/logstash-input-snmp_jars.rb
110
111
  - lib/logstash/inputs/snmp.rb
111
112
  - lib/logstash/inputs/snmp/base_client.rb
@@ -413,6 +414,7 @@ files:
413
414
  - logstash-input-snmp.gemspec
414
415
  - spec/fixtures/RFC1213-MIB.dic
415
416
  - spec/fixtures/collision.dic
417
+ - spec/inputs/snmp/base_client_spec.rb
416
418
  - spec/inputs/snmp/mib_spec.rb
417
419
  - spec/inputs/snmp_spec.rb
418
420
  - vendor/jar-dependencies/org/snmp4j/snmp4j/2.5.11/snmp4j-2.5.11.jar
@@ -434,9 +436,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
434
436
  version: '0'
435
437
  required_rubygems_version: !ruby/object:Gem::Requirement
436
438
  requirements:
437
- - - ">"
439
+ - - ">="
438
440
  - !ruby/object:Gem::Version
439
- version: 1.3.1
441
+ version: '0'
440
442
  requirements: []
441
443
  rubyforge_project:
442
444
  rubygems_version: 2.6.13
@@ -446,5 +448,6 @@ summary: SNMP input plugin
446
448
  test_files:
447
449
  - spec/fixtures/RFC1213-MIB.dic
448
450
  - spec/fixtures/collision.dic
451
+ - spec/inputs/snmp/base_client_spec.rb
449
452
  - spec/inputs/snmp/mib_spec.rb
450
453
  - spec/inputs/snmp_spec.rb