logstash-input-snmp 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ # python version 1.0 DO NOT EDIT
2
+ #
3
+ # This python file has been generated by smidump version 0.5.0:
4
+ #
5
+ # smidump -f python RFC1213-MIB
6
+
7
+ FILENAME = "tmp/RFC1213-MIB.txt"
8
+
9
+ MIB = {
10
+ "moduleName" : "RFC1213-MIB",
11
+
12
+ "nodes" : {
13
+ "system" : {
14
+ "nodetype" : "node",
15
+ "moduleName" : "RFC1213-MIB",
16
+ "oid" : "0.0.0",
17
+ }, # node
18
+
19
+ "foo" : {
20
+ "nodetype" : "node",
21
+ "moduleName" : "RFC1213-MIB",
22
+ "oid" : "1.3.6.1.2.1.1",
23
+ }, # node
24
+ }, # nodes
25
+ }
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/snmp/mib"
4
+
5
+ module LogStash
6
+ describe SnmpMib do
7
+
8
+ subject { SnmpMib.new }
9
+ let (:fixtures_dir) { ::File.expand_path(::File.join("..", "..", "..", "fixtures/"), __FILE__) }
10
+ let (:rfc1213_mib) { ::File.join(fixtures_dir, "RFC1213-MIB.dic") }
11
+ let (:collision_mib) { ::File.join(fixtures_dir, "collision.dic") }
12
+
13
+ it "should read valid mib dic file" do
14
+ module_name, nodes = subject.read_mib_dic(rfc1213_mib)
15
+ expect(module_name).to eq("RFC1213-MIB")
16
+ expect(nodes.keys.size).to eq(201)
17
+ end
18
+
19
+ it "should produce 0 warning when first adding a mib path" do
20
+ warnings = subject.add_mib_path(rfc1213_mib)
21
+ expect(warnings.size).to eq(0)
22
+ end
23
+
24
+ it "should produce 0 warning when adding same keys and values" do
25
+ warnings = subject.add_mib_path(rfc1213_mib)
26
+ expect(warnings.size).to eq(0)
27
+ warnings = subject.add_mib_path(rfc1213_mib)
28
+ expect(warnings.size).to eq(0)
29
+ end
30
+
31
+ it "should produce warning when adding mib with collisions" do
32
+ warnings = subject.add_mib_path(rfc1213_mib)
33
+ expect(warnings.size).to eq(0)
34
+ warnings = subject.add_mib_path(collision_mib)
35
+ expect(warnings.size).to eq(1)
36
+ expect(warnings[0]).to eq("warning: overwriting MIB OID '1.3.6.1.2.1.1' and name 'system' with new name 'foo' from module 'RFC1213-MIB'")
37
+ end
38
+
39
+ it "should read all dic files in the dir" do
40
+ warnings = subject.add_mib_path(fixtures_dir)
41
+ expect(warnings.size).to eq(1) # since we have 2 fixtures that produce 1 collision
42
+ end
43
+
44
+ it "should find existing oid" do
45
+ subject.add_mib_path(rfc1213_mib)
46
+ expect(subject.map_oid("1.3.6.1.2.1.1")).to eq("1.3.6.1.2.mib-2.system")
47
+ end
48
+
49
+ it "should not find inexisting oid " do
50
+ subject.add_mib_path(rfc1213_mib)
51
+ expect(subject.map_oid("0.0.0.0")).to eq("0.0.0.0")
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/inputs/snmp"
4
+
5
+ describe LogStash::Inputs::Snmp do
6
+ let(:mock_client) { double("LogStash::SnmpClient") }
7
+
8
+ it_behaves_like "an interruptible input plugin" do
9
+ let(:config) {{
10
+ "get" => ["1.3.6.1.2.1.1.1.0"],
11
+ "hosts" => [{"host" => "udp:127.0.0.1/161", "community" => "public"}]
12
+ }}
13
+
14
+ before do
15
+ expect(LogStash::SnmpClient).to receive(:new).and_return(mock_client)
16
+ expect(mock_client).to receive(:get).and_return({})
17
+ end
18
+ end
19
+
20
+ context "OIDs options validation" do
21
+ let(:valid_configs) {
22
+ [
23
+ {"get" => ["1.3.6.1.2.1.1.1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
24
+ {"get" => [".1.3.6.1.2.1.1.1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
25
+ {"get" => ["1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1"], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
26
+ {"get" => ["1.3.6.1.2.1.1.1.0", ".1.3.6.1.2.1.1"], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
27
+ ]
28
+ }
29
+
30
+ let(:invalid_configs) {
31
+ [
32
+ {"get" => ["1.3.6.1.2.1.1.1.a"], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
33
+ {"get" => ["test"], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
34
+ {"get" => [], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
35
+ {"get" => "foo", "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
36
+ ]
37
+ }
38
+
39
+ it "validates get oids" do
40
+ valid_configs.each do |config|
41
+ expect{ described_class.new(config).register }.not_to raise_error
42
+ end
43
+ invalid_configs.each do |config|
44
+ expect{ described_class.new(config).register }.to raise_error(LogStash::ConfigurationError)
45
+ end
46
+ end
47
+ end
48
+
49
+ context "hosts options validation" do
50
+ let(:valid_configs) {
51
+ [
52
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
53
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161"}]},
54
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:localhost/161"}]},
55
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/112345"}]},
56
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161", "community" => "public"}]},
57
+ ]
58
+ }
59
+
60
+ let(:invalid_configs) {
61
+ [
62
+ {"get" => ["1.0"], "hosts" => [{"host" => "aaa:127.0.0.1/161"}]},
63
+ {"get" => ["1.0"], "hosts" => [{"host" => "tcp:127.0.0.1/161"}]},
64
+ {"get" => ["1.0"], "hosts" => [{"host" => "localhost"}]},
65
+ {"get" => ["1.0"], "hosts" => [{"host" => "localhost/161"}]},
66
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1"}]},
67
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/"}]},
68
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/aaa"}]},
69
+ {"get" => ["1.0"], "hosts" => [{"host" => "udp:127.0.0.1/161"}, {"host" => "udp:127.0.0.1/aaa"}]},
70
+ {"get" => ["1.0"], "hosts" => ""},
71
+ {"get" => ["1.0"], "hosts" => []},
72
+ {"get" => ["1.0"] },
73
+ ]
74
+ }
75
+
76
+ it "validates hosts" do
77
+ valid_configs.each do |config|
78
+ expect{ described_class.new(config).register }.not_to raise_error
79
+ end
80
+ invalid_configs.each do |config|
81
+ expect{ described_class.new(config).register }.to raise_error(LogStash::ConfigurationError)
82
+ end
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-input-snmp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Elasticsearch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-11 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.60'
19
+ - - "<="
20
+ - !ruby/object:Gem::Version
21
+ version: '2.99'
22
+ name: logstash-core-plugin-api
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 0.0.22
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.1.0
42
+ name: stud
43
+ prerelease: false
44
+ type: :runtime
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.22
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 0.1.0
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ name: logstash-codec-plain
60
+ prerelease: false
61
+ type: :runtime
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ name: logstash-devutils
74
+ prerelease: false
75
+ type: :development
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ name: rspec-wait
88
+ prerelease: false
89
+ type: :development
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: This gem is a Logstash plugin required to be installed on top of the
96
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
97
+ gem is not a stand-alone program
98
+ email: info@elastic.co
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - CHANGELOG.md
104
+ - CONTRIBUTORS
105
+ - DEVELOPER.md
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - lib/logstash-input-snmp_jars.rb
110
+ - lib/logstash/inputs/snmp.rb
111
+ - lib/logstash/inputs/snmp/client.rb
112
+ - lib/logstash/inputs/snmp/mib.rb
113
+ - logstash-input-snmp.gemspec
114
+ - spec/fixtures/RFC1213-MIB.dic
115
+ - spec/fixtures/collision.dic
116
+ - spec/inputs/snmp/mib_spec.rb
117
+ - spec/inputs/snmp_spec.rb
118
+ - vendor/jar-dependencies/org/snmp4j/snmp4j/2.5.11/snmp4j-2.5.11.jar
119
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
120
+ licenses:
121
+ - Apache-2.0
122
+ metadata:
123
+ logstash_plugin: 'true'
124
+ logstash_group: input
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ - vendor/jar-dependencies
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">"
138
+ - !ruby/object:Gem::Version
139
+ version: 1.3.1
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.6.13
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: SNMP input plugin
146
+ test_files:
147
+ - spec/fixtures/RFC1213-MIB.dic
148
+ - spec/fixtures/collision.dic
149
+ - spec/inputs/snmp/mib_spec.rb
150
+ - spec/inputs/snmp_spec.rb