logstash-input-snmp 0.1.0.beta1 → 0.1.0.beta2
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 +21 -5
- data/logstash-input-snmp.gemspec +1 -1
- data/spec/inputs/snmp_spec.rb +41 -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: 5599c9705618d89025096ef93521fc9af9c3459b34e57e1dabe3b697918ffca1
|
4
|
+
data.tar.gz: 3b86026c9b6239f0628408d39926a757d7308c0d72b6fdf6a5742f2cc2cc2c1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c03af9c1da2efbbdccff38d322ed7b8f15331cca3de4b987d22145c2b150d1c93a65035a664d88a245c89e0461ba3a89236a429b3d806cc996503ecce55fa60a
|
7
|
+
data.tar.gz: da07ed21485a35b58b915f974003ad747c3ff6d4a36ed1b6ccb07d3f8066e7910ed826e8ff5f63454f2fb4af5cc663aceb8755f18959f35d016bc19e137e46a2
|
data/CHANGELOG.md
CHANGED
data/lib/logstash/inputs/snmp.rb
CHANGED
@@ -53,6 +53,9 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
|
|
53
53
|
# The default, `30`, means poll each host every 30second.
|
54
54
|
config :interval, :validate => :number, :default => 30
|
55
55
|
|
56
|
+
# Add the default "host" field to the event.
|
57
|
+
config :add_field, :validate => :hash, :default => { "host" => "%{[@metadata][host_address]}" }
|
58
|
+
|
56
59
|
def register
|
57
60
|
validate_oids!
|
58
61
|
validate_hosts!
|
@@ -71,10 +74,19 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
|
|
71
74
|
retries = host["retries"] || 2
|
72
75
|
timeout = host["timeout"] || 1000
|
73
76
|
|
77
|
+
host_details = host_name.match(HOST_REGEX)
|
78
|
+
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
|
80
|
+
|
74
81
|
definition = {
|
75
82
|
:client => LogStash::SnmpClient.new(host_name, community, version, retries, timeout, mib),
|
76
83
|
:get => Array(get),
|
77
84
|
:walk => Array(walk),
|
85
|
+
|
86
|
+
:host_protocol => host_details[:host_protocol],
|
87
|
+
:host_address => host_details[:host_address],
|
88
|
+
:host_port => host_details[:host_port],
|
89
|
+
:host_community => community,
|
78
90
|
}
|
79
91
|
@client_definitions << definition
|
80
92
|
end
|
@@ -104,6 +116,14 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
|
|
104
116
|
end
|
105
117
|
|
106
118
|
unless result.empty?
|
119
|
+
metadata = {
|
120
|
+
"host_protocol" => definition[:host_protocol],
|
121
|
+
"host_address" => definition[:host_address],
|
122
|
+
"host_port" => definition[:host_port],
|
123
|
+
"host_community" => definition[:host_community],
|
124
|
+
}
|
125
|
+
result["@metadata"] = metadata
|
126
|
+
|
107
127
|
event = LogStash::Event.new(result)
|
108
128
|
decorate(event)
|
109
129
|
queue << event
|
@@ -120,7 +140,7 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
|
|
120
140
|
private
|
121
141
|
|
122
142
|
OID_REGEX = /^\.?([0-9\.]+)$/
|
123
|
-
HOST_REGEX = /^(udp|tcp)
|
143
|
+
HOST_REGEX = /^(?<host_protocol>udp|tcp):(?<host_address>.+)\/(?<host_port>\d+)$/i
|
124
144
|
|
125
145
|
def validate_oids!
|
126
146
|
@get = Array(@get).map do |oid|
|
@@ -149,10 +169,6 @@ class LogStash::Inputs::Snmp < LogStash::Inputs::Base
|
|
149
169
|
|
150
170
|
@hosts.each do |host|
|
151
171
|
raise(LogStash::ConfigurationError, "each host definition must have a \"host\" option") if !host.is_a?(Hash) || host["host"].nil?
|
152
|
-
unless host["host"] =~ HOST_REGEX
|
153
|
-
raise(LogStash::ConfigurationError, "invalid host option format")
|
154
|
-
end
|
155
|
-
raise(LogStash::ConfigurationError, "tcp is not yet supported, only udp") if $1 =~ /tcp/i
|
156
172
|
end
|
157
173
|
end
|
158
174
|
end
|
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 = '0.1.0.
|
3
|
+
s.version = '0.1.0.beta2'
|
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
@@ -82,4 +82,45 @@ describe LogStash::Inputs::Snmp do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
context "@metadata" do
|
87
|
+
before do
|
88
|
+
expect(LogStash::SnmpClient).to receive(:new).and_return(mock_client)
|
89
|
+
expect(mock_client).to receive(:get).and_return({"foo" => "bar"})
|
90
|
+
end
|
91
|
+
|
92
|
+
it "shoud add @metadata fields and add default host field" do
|
93
|
+
config = <<-CONFIG
|
94
|
+
input {
|
95
|
+
snmp {
|
96
|
+
get => ["1.3.6.1.2.1.1.1.0"]
|
97
|
+
hosts => [{host => "udp:127.0.0.1/161" community => "public"}]
|
98
|
+
}
|
99
|
+
}
|
100
|
+
CONFIG
|
101
|
+
event = input(config) { |_, queue| queue.pop }
|
102
|
+
|
103
|
+
expect(event.get("[@metadata][host_protocol]")).to eq("udp")
|
104
|
+
expect(event.get("[@metadata][host_address]")).to eq("127.0.0.1")
|
105
|
+
expect(event.get("[@metadata][host_port]")).to eq("161")
|
106
|
+
expect(event.get("[@metadata][host_community]")).to eq("public")
|
107
|
+
expect(event.get("host")).to eq("127.0.0.1")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "shoud add custom host field" do
|
111
|
+
config = <<-CONFIG
|
112
|
+
input {
|
113
|
+
snmp {
|
114
|
+
get => ["1.3.6.1.2.1.1.1.0"]
|
115
|
+
hosts => [{host => "udp:127.0.0.1/161" community => "public"}]
|
116
|
+
add_field => { host => "%{[@metadata][host_protocol]}:%{[@metadata][host_address]}/%{[@metadata][host_port]},%{[@metadata][host_community]}" }
|
117
|
+
}
|
118
|
+
}
|
119
|
+
CONFIG
|
120
|
+
event = input(config) { |_, queue| queue.pop }
|
121
|
+
|
122
|
+
expect(event.get("host")).to eq("udp:127.0.0.1/161,public")
|
123
|
+
end
|
124
|
+
end
|
85
125
|
end
|
126
|
+
|
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.
|
4
|
+
version: 0.1.0.beta2
|
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-
|
11
|
+
date: 2018-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|