logstash-output-opennms 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/lib/logstash/outputs/opennms.rb +250 -0
- data/logstash-output-opennms.gemspec +26 -0
- data/spec/README.md +98 -0
- data/spec/helpers/opennms_helper.rb +71 -0
- data/spec/outputs/opennms_spec.rb +94 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c165a76106a883993225957e07688745f3339cb3
|
4
|
+
data.tar.gz: 1ef23846b764564b5ec6b71a61de0547b656bae1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f4b75b3881e3bf71c14c1589fd4c448c1f062ea7e8782cc31a0bb1e0eb72cd049dbbf92da4400e7c7059a27e9c5fd1f2af7633b634783b1758b44629f1a0af7
|
7
|
+
data.tar.gz: d1a6baad25139074f2996c3e8adb6721caf2e7e2209191ed9c4db41cfd860a7c76f494ae0cd0e547a78a7d21cdb97fcde8ad627b1b2c27ae5cf3e5b4f049ef47
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2016 Markus Schneider <markus.schneider73@gmail.com>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
@@ -0,0 +1,250 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/outputs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "socket"
|
5
|
+
require "timeout"
|
6
|
+
require "rexml/document"
|
7
|
+
|
8
|
+
# The OpenNMS output is used to send an event (xml document) to an OpenNMS
|
9
|
+
# server. The event `@timestamp` will automatically be associated with the
|
10
|
+
# OpenNMS item data.
|
11
|
+
#
|
12
|
+
# Each "host" is an identifier, and each item is associated with that host.
|
13
|
+
# Items are typed on the OpenNMS side. You can send numbers as strings and
|
14
|
+
# OpenNMS will Do The Right Thing.
|
15
|
+
#
|
16
|
+
# In the OpenNMS UI, ensure that your hostname matches the value referenced by
|
17
|
+
# `opennms_host`. Create the item with the key as it appears in the field
|
18
|
+
# referenced by `opennms_key`. In the item configuration window, ensure that the
|
19
|
+
# type dropdown is set to OpenNMS Trapper. Also be sure to set the type of
|
20
|
+
# information that OpenNMS should expect for this item.
|
21
|
+
#
|
22
|
+
# This plugin does not currently send in batches. While it is possible to do
|
23
|
+
# so, this is not supported. Be careful not to flood your OpenNMS server with
|
24
|
+
# too many events per second.
|
25
|
+
#
|
26
|
+
# NOTE: This plugin will log a warning if a necessary field is missing. It will
|
27
|
+
# not attempt to resend if OpenNMS is down, but will log an error message.
|
28
|
+
|
29
|
+
class LogStash::Outputs::OpenNMS < LogStash::Outputs::Base
|
30
|
+
config_name "opennms"
|
31
|
+
concurrency :single
|
32
|
+
|
33
|
+
# The IP or resolvable hostname where the OpenNMS server is running
|
34
|
+
config :opennms_server_hosts, :validate => :hash, :default => {"localhost" => 5817}
|
35
|
+
|
36
|
+
# The number of seconds to wait before giving up on a connection to the OpenNMS
|
37
|
+
# server. This number should be very small, otherwise delays in delivery of
|
38
|
+
# other outputs could result.
|
39
|
+
config :opennms_server_timeout, :validate => :number, :default => 1
|
40
|
+
|
41
|
+
# The field name which holds the OpenNMS time zone. This can be a sub-field of
|
42
|
+
# the @metadata field.
|
43
|
+
config :opennms_event_timezone, :validate => :string, :required => true
|
44
|
+
|
45
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
46
|
+
# the @metadata field.
|
47
|
+
config :opennms_event_service, :validate => :string
|
48
|
+
|
49
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
50
|
+
# the @metadata field.
|
51
|
+
config :opennms_event_nodeid, :validate => :number
|
52
|
+
|
53
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
54
|
+
# the @metadata field.
|
55
|
+
config :opennms_event_interface, :validate => :string
|
56
|
+
|
57
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
58
|
+
# the @metadata field.
|
59
|
+
config :opennms_event_uei, :validate => :string, :default => "uei.opennms.org/logstash"
|
60
|
+
|
61
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
62
|
+
# the @metadata field.
|
63
|
+
config :opennms_event_origin, :validate => :string, :default => "None"
|
64
|
+
|
65
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
66
|
+
# the @metadata field.
|
67
|
+
config :opennms_event_severity, :validate => :number, :required => true, :default => 4
|
68
|
+
|
69
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
70
|
+
# the @metadata field.
|
71
|
+
config :opennms_event_source, :validate => :string, :default => "logstash"
|
72
|
+
|
73
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
74
|
+
# the @metadata field.
|
75
|
+
config :opennms_event_description, :validate => :string, :default => "None"
|
76
|
+
|
77
|
+
# The field name which holds the OpenNMS ... This can be a sub-field of
|
78
|
+
# the @metadata field.
|
79
|
+
config :opennms_event_logmsg, :validate => :string, :default => "None"
|
80
|
+
|
81
|
+
# This directive cannot be used in conjunction with the single-value directives
|
82
|
+
# `opennms_key` and `opennms_value`.
|
83
|
+
config :opennms_event_parms, :validate => :hash
|
84
|
+
|
85
|
+
public
|
86
|
+
def register
|
87
|
+
if !@opennms_key.nil? && !@multi_value.nil?
|
88
|
+
@logger.warn("Cannot use multi_value in conjunction with opennms_key/opennms_value. Ignoring opennms_key.")
|
89
|
+
end
|
90
|
+
|
91
|
+
if @opennms_event_parms.nil?
|
92
|
+
@opennms_event_parms = { 'a' => '1', 'b' => '2', 'c' => '3' }
|
93
|
+
end
|
94
|
+
|
95
|
+
# We're only going to use @multi_value in the end, so let's build it from
|
96
|
+
# @opennms_key and @opennms_value if it is empty (single value configuration).
|
97
|
+
if @multi_value.nil?
|
98
|
+
@multi_value = [ @opennms_key, @opennms_value ]
|
99
|
+
end
|
100
|
+
if @multi_value.length % 2 == 1
|
101
|
+
raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_register",
|
102
|
+
:plugin => "output", :type => "opennms",
|
103
|
+
:error => "Invalid opennms configuration #{@multi_value}. multi_value requires an even number of elements as ['opennms_key1', 'opennms_value1', 'opennms_key2', 'opennms_value2']")
|
104
|
+
end
|
105
|
+
end # def register
|
106
|
+
|
107
|
+
public
|
108
|
+
def field_check(event, fieldname)
|
109
|
+
if !event.get(fieldname)
|
110
|
+
@logger.warn("Field referenced by #{fieldname} is missing")
|
111
|
+
false
|
112
|
+
else
|
113
|
+
true
|
114
|
+
end
|
115
|
+
end # def field_check
|
116
|
+
|
117
|
+
public
|
118
|
+
def kv_check(event, key_field, value_field)
|
119
|
+
errors = 0
|
120
|
+
for field in [key_field, value_field]
|
121
|
+
errors += 1 unless field_check(event, field)
|
122
|
+
end
|
123
|
+
errors < 1 ? true : false
|
124
|
+
end # def kv_check
|
125
|
+
|
126
|
+
public
|
127
|
+
def validate_fields(event)
|
128
|
+
found = []
|
129
|
+
(0..@multi_value.length-1).step(2) do |idx|
|
130
|
+
@logger.warn("---> " + @multi_value[idx].to_s)
|
131
|
+
if kv_check(event, @multi_value[idx], @multi_value[idx+1])
|
132
|
+
found << @multi_value[idx]
|
133
|
+
found << @multi_value[idx+1]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
found
|
137
|
+
end # def validate_fields
|
138
|
+
|
139
|
+
public
|
140
|
+
def validate_props(event,props,found)
|
141
|
+
props.each do |props_key,props_value|
|
142
|
+
if props_value.is_a?(::Hash)
|
143
|
+
found[props_key] = validate_props(event,props_value,{})
|
144
|
+
else
|
145
|
+
if !event.get(props_value)
|
146
|
+
@logger.warn("Field referenced by #{props_value} is missing")
|
147
|
+
found[props_key] = props_value.empty? ? "n/a" : props_value
|
148
|
+
else
|
149
|
+
found[props_key]=event.get(props_value)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
found
|
154
|
+
end # def validate_props
|
155
|
+
|
156
|
+
# Build XML event document
|
157
|
+
public
|
158
|
+
def format_request(message)
|
159
|
+
event_doc = "<log>"
|
160
|
+
event_doc += "<events>"
|
161
|
+
event_doc += "<event>"
|
162
|
+
event_doc += "<uei>" + message['uei'] + "</uei>"
|
163
|
+
event_doc += "<source>" + message['source'] + "</source>"
|
164
|
+
event_doc += "<nodeid>" + message['nodeid'] + "</nodeid>" if !message['nodeid'].empty?
|
165
|
+
event_doc += "<time>" + Time.now.strftime("%A %d %B %Y %H:%M:%S o'clock GMT") + "</time>"
|
166
|
+
event_doc += "<host>" + message['origin'] + "</host>"
|
167
|
+
event_doc += "<interface>" + message['interface'] + "</interface>" if !message['interface'].empty?
|
168
|
+
event_doc += "<service>" + message ['service'] + "</service>" if !message['service'].empty?
|
169
|
+
event_doc += "<parms>"
|
170
|
+
message['parms'].each do |parm_name, parm_value|
|
171
|
+
next if parm_name == 'severity'
|
172
|
+
event_doc += "<parm>"
|
173
|
+
event_doc += "<parmName><![CDATA[" + parm_name + "]]></parmName>"
|
174
|
+
event_doc += "<value type=\"string\" encoding=\"text\"><![CDATA[" + parm_value + "]]></value>"
|
175
|
+
event_doc += "</parm>"
|
176
|
+
end
|
177
|
+
event_doc += "</parms>"
|
178
|
+
event_doc += "<descr>" + message['description'] + "</descr>" if !message['description'].empty?
|
179
|
+
event_doc += "<logmsg>" + message['logmsg'] + "</logmsg>" if !message['logmsg'].empty?
|
180
|
+
event_doc += "<severity>" + message['severity'] + "</severity>"
|
181
|
+
event_doc += "</event>"
|
182
|
+
event_doc += "</events>"
|
183
|
+
event_doc += "</log>"
|
184
|
+
xml_event = REXML::Document.new(event_doc)
|
185
|
+
end # def format_request
|
186
|
+
|
187
|
+
def tcp_send(message)
|
188
|
+
begin
|
189
|
+
@opennms_server_hosts.each do |server,port|
|
190
|
+
TCPSocket.open(server,port) do |sock|
|
191
|
+
xml_event = format_request(message).to_s
|
192
|
+
logger.debug("XML Event: " + xml_event)
|
193
|
+
sock.print xml_event
|
194
|
+
end
|
195
|
+
end
|
196
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET
|
197
|
+
@logger.error("Connection error. Unable to connect to OpenNMS server",
|
198
|
+
:server => @opennms_server_hosts,
|
199
|
+
)
|
200
|
+
false
|
201
|
+
end
|
202
|
+
end # def tcp_send
|
203
|
+
|
204
|
+
def send_to_opennms(event)
|
205
|
+
begin
|
206
|
+
Timeout::timeout(@opennms_server_timeout) do
|
207
|
+
tcp_send(event)
|
208
|
+
end
|
209
|
+
rescue Timeout::Error
|
210
|
+
@logger.warn("Connection attempt to OpenNMS server timed out.",
|
211
|
+
:server => @opennms_server_host,
|
212
|
+
:port => @opennms_server_port.to_s,
|
213
|
+
:timeout => @opennms_server_timeout.to_s
|
214
|
+
)
|
215
|
+
false
|
216
|
+
end
|
217
|
+
end # def send_to_opennms
|
218
|
+
|
219
|
+
public
|
220
|
+
def receive(event)
|
221
|
+
#parms = validate_props(event,@opennms_event_parms)
|
222
|
+
|
223
|
+
message_map = { 'host' => @opennms_server_host.to_s,
|
224
|
+
'port' => @opennms_server_port.to_s,
|
225
|
+
'timezone' => @opennms_event_timezone.to_s,
|
226
|
+
'service' => @opennms_event_service.to_s,
|
227
|
+
'nodeid' => @opennms_event_nodeid.to_s,
|
228
|
+
'interface' => @opennms_event_interface.to_s,
|
229
|
+
'uei' => @opennms_event_uei.to_s,
|
230
|
+
'origin' => @opennms_event_origin.to_s,
|
231
|
+
'severity' => @opennms_event_severity.to_s,
|
232
|
+
'source' => @opennms_event_source.to_s,
|
233
|
+
'description' => @opennms_event_description.to_s,
|
234
|
+
'logmsg' => @opennms_event_logmsg.to_s,
|
235
|
+
'parms' => @opennms_event_parms,
|
236
|
+
}
|
237
|
+
|
238
|
+
message = validate_props(event,message_map,{})
|
239
|
+
|
240
|
+
#message['parms'].each do |k,v|
|
241
|
+
# @logger.debug("Hash: " + k + " => " + v)
|
242
|
+
#end
|
243
|
+
|
244
|
+
#return unless field_check(event, @opennms_host)
|
245
|
+
|
246
|
+
send_to_opennms(message)
|
247
|
+
|
248
|
+
end # def receive
|
249
|
+
|
250
|
+
end # class LogStash::Outputs::OpenNMS
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-output-opennms'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.licenses = ["Apache License (2.0)"]
|
5
|
+
s.summary = "This output sends a xml document (event) to an OpenNMS server."
|
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"
|
7
|
+
s.authors = ["schneidermatic"]
|
8
|
+
s.email = "markus.schneider73@gmail.com"
|
9
|
+
s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
14
|
+
# Tests
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
|
17
|
+
# Special flag to let us know this is actually a logstash plugin
|
18
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
|
19
|
+
|
20
|
+
# Gem dependencies
|
21
|
+
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
|
22
|
+
s.add_runtime_dependency "logstash-codec-plain"
|
23
|
+
s.add_development_dependency "logstash-devutils", ">= 0.0.12"
|
24
|
+
s.add_development_dependency "logstash-filter-mutate"
|
25
|
+
s.add_development_dependency "longshoreman"
|
26
|
+
end
|
data/spec/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-output-zabbix.svg)](https://travis-ci.org/logstash-plugins/logstash-output-zabbix)
|
4
|
+
|
5
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
6
|
+
|
7
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
|
8
|
+
|
9
|
+
## Documentation
|
10
|
+
|
11
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
12
|
+
|
13
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
14
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
15
|
+
|
16
|
+
## Need Help?
|
17
|
+
|
18
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
19
|
+
|
20
|
+
## Developing
|
21
|
+
|
22
|
+
### 1. Plugin Developement and Testing
|
23
|
+
|
24
|
+
#### Code
|
25
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
26
|
+
|
27
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
28
|
+
|
29
|
+
- Install dependencies
|
30
|
+
```sh
|
31
|
+
bundle install
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Test
|
35
|
+
|
36
|
+
- Update your dependencies
|
37
|
+
|
38
|
+
```sh
|
39
|
+
bundle install
|
40
|
+
```
|
41
|
+
|
42
|
+
- Run tests
|
43
|
+
|
44
|
+
```sh
|
45
|
+
bundle exec rspec
|
46
|
+
```
|
47
|
+
|
48
|
+
### 2. Running your unpublished Plugin in Logstash
|
49
|
+
|
50
|
+
#### 2.1 Run in a local Logstash clone
|
51
|
+
|
52
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
53
|
+
```ruby
|
54
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
55
|
+
```
|
56
|
+
- Install plugin
|
57
|
+
```sh
|
58
|
+
# Logstash 2.3 and higher
|
59
|
+
bin/logstash-plugin install --no-verify
|
60
|
+
|
61
|
+
# Prior to Logstash 2.3
|
62
|
+
bin/plugin install --no-verify
|
63
|
+
|
64
|
+
```
|
65
|
+
- Run Logstash with your plugin
|
66
|
+
```sh
|
67
|
+
bin/logstash -e 'filter {awesome {}}'
|
68
|
+
```
|
69
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
70
|
+
|
71
|
+
#### 2.2 Run in an installed Logstash
|
72
|
+
|
73
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
74
|
+
|
75
|
+
- Build your plugin gem
|
76
|
+
```sh
|
77
|
+
gem build logstash-filter-awesome.gemspec
|
78
|
+
```
|
79
|
+
- Install the plugin from the Logstash home
|
80
|
+
```sh
|
81
|
+
# Logstash 2.3 and higher
|
82
|
+
bin/logstash-plugin install --no-verify
|
83
|
+
|
84
|
+
# Prior to Logstash 2.3
|
85
|
+
bin/plugin install --no-verify
|
86
|
+
|
87
|
+
```
|
88
|
+
- Start Logstash and proceed to test the plugin
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
93
|
+
|
94
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
95
|
+
|
96
|
+
It is more important to the community that you are able to contribute.
|
97
|
+
|
98
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module OpenNMSHelper
|
2
|
+
|
3
|
+
require 'rexml/document'
|
4
|
+
|
5
|
+
# This is used to ensure the (Docker) OpenNMS port is up and running
|
6
|
+
def port_open?(ip, port, seconds=1)
|
7
|
+
Timeout::timeout(seconds) do
|
8
|
+
begin
|
9
|
+
TCPSocket.new(ip, port).close
|
10
|
+
true
|
11
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
12
|
+
false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
rescue Timeout::Error
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def port_responding?(ip, port)
|
20
|
+
# Try for up to 10 seconds to get a response
|
21
|
+
10.times do
|
22
|
+
if port_open?(ip, port)
|
23
|
+
return true
|
24
|
+
else
|
25
|
+
sleep 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
false
|
29
|
+
end
|
30
|
+
|
31
|
+
def opennms_server_up?(opennms_ip, port)
|
32
|
+
data = {
|
33
|
+
"request" => "sender data",
|
34
|
+
"data" => [{
|
35
|
+
"host" => "opennms.example.com",
|
36
|
+
"key" => "opennms.key",
|
37
|
+
"value" => "This is a log entry.",
|
38
|
+
"clock" => 1429100000,
|
39
|
+
}],
|
40
|
+
"clock" => Time.now.to_i,
|
41
|
+
}
|
42
|
+
if port_responding?(opennms_ip, port)
|
43
|
+
###
|
44
|
+
### This is a hacky way to guarantee that OpenNMS is responsive, because the
|
45
|
+
### port check alone is insufficient. TCP tests say the port is open, but
|
46
|
+
### it can take another 2 to 5 seconds (depending on the machine) before it
|
47
|
+
### is responding in the way we need for these tests.
|
48
|
+
###
|
49
|
+
resp = ""
|
50
|
+
# Try for up to 10 seconds to get a response.
|
51
|
+
10.times do
|
52
|
+
TCPSocket.open(opennms_ip, port) do |sock|
|
53
|
+
sock.print ZabbixProtocol.dump(data)
|
54
|
+
resp = sock.read
|
55
|
+
end
|
56
|
+
if resp.length == 0
|
57
|
+
sleep 1
|
58
|
+
else
|
59
|
+
return true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
if resp.length == 0
|
63
|
+
puts "OpenNMS server or db is unreachable"
|
64
|
+
end
|
65
|
+
else
|
66
|
+
puts "Unable to reach OpenNMS server on #{opennms_ip}:#{port}"
|
67
|
+
end
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
2
|
+
require "logstash/outputs/opennms"
|
3
|
+
require "logstash/codecs/plain"
|
4
|
+
require "logstash/event"
|
5
|
+
require "socket"
|
6
|
+
require "timeout"
|
7
|
+
require "longshoreman"
|
8
|
+
require "rexml/document"
|
9
|
+
|
10
|
+
include REXML
|
11
|
+
|
12
|
+
NAME = "logstash-output-opennms-#{rand(999).to_s}"
|
13
|
+
IMAGE = "untergeek/logstash_output_opennms_rspec"
|
14
|
+
TAG = "latest"
|
15
|
+
OPENNMS_PORT = 5817
|
16
|
+
TIMEOUT = 1
|
17
|
+
NODEID = 1
|
18
|
+
SEVERITY = 6 # MAJOR
|
19
|
+
|
20
|
+
describe LogStash::Outputs::OpenNMS do
|
21
|
+
# Building block "lets"
|
22
|
+
let(:opennms_server_hosts) { {"localhost" => OPENNMS_PORT} }
|
23
|
+
let(:opennms_server_timeout) { TIMEOUT }
|
24
|
+
let(:opennms_event_timezone) { "cest" }
|
25
|
+
let(:opennms_event_nodeid) { NODEID }
|
26
|
+
let(:opennms_event_interface) { "192.168.1.1" }
|
27
|
+
let(:opennms_event_uei) { "uei.opennms.com" }
|
28
|
+
let(:opennms_event_origin) { "localhost" }
|
29
|
+
let(:opennms_event_severity) { 7 }
|
30
|
+
let(:opennms_event_source) { "logstash" }
|
31
|
+
let(:opennms_event_description) { "sample description" }
|
32
|
+
let(:opennms_event_logmsg) { "sample logmsg" }
|
33
|
+
let(:opennms_event_parms) {
|
34
|
+
{
|
35
|
+
"Type" => "auto",
|
36
|
+
"EventId" => "12345",
|
37
|
+
"OpsInstruct" => "https://en.wikipedia.org/wiki/RTFM",
|
38
|
+
"IncidentMessage" => "Outage of Business Service",
|
39
|
+
"SubSource" => "Webapp",
|
40
|
+
"TicketOwner" => "Linux Team",
|
41
|
+
"TicketPriority" => "1",
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
# Assembled "lets"
|
46
|
+
let(:onms_event) {
|
47
|
+
{
|
48
|
+
"opennms_server_hosts" => opennms_server_hosts,
|
49
|
+
"opennms_server_timeout" => opennms_server_timeout,
|
50
|
+
"opennms_event_timezone" => opennms_event_timezone,
|
51
|
+
"opennms_event_nodeid" => opennms_event_nodeid,
|
52
|
+
"opennms_event_interface" => opennms_event_interface,
|
53
|
+
"opennms_event_uei" => opennms_event_uei,
|
54
|
+
"opennms_event_origin" => opennms_event_origin,
|
55
|
+
"opennms_event_severity" => opennms_event_severity,
|
56
|
+
"opennms_event_source" => opennms_event_source,
|
57
|
+
"opennms_event_description" => opennms_event_description,
|
58
|
+
"opennms_event_logmsg" => opennms_event_logmsg,
|
59
|
+
"opennms_event_parms" => opennms_event_parms,
|
60
|
+
}
|
61
|
+
}
|
62
|
+
let(:onms_output) { onms_event }
|
63
|
+
|
64
|
+
# Finished object "lets"
|
65
|
+
let(:sample_event) { LogStash::Event.new(onms_event) }
|
66
|
+
let(:output) { LogStash::Outputs::OpenNMS.new(onms_output) }
|
67
|
+
|
68
|
+
before do
|
69
|
+
output.register
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "Unit Tests" do
|
73
|
+
|
74
|
+
describe "#field_check" do
|
75
|
+
|
76
|
+
context "when expected field not found" do
|
77
|
+
subject { output.field_check(sample_event, "not_appearing") }
|
78
|
+
it "should return false" do
|
79
|
+
expect(subject).to eq(false)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when expected field found" do
|
84
|
+
subject { output.field_check(sample_event, "opennms_event_uei") }
|
85
|
+
it "should return true" do
|
86
|
+
expect(subject).to eq(true)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end # "#field_check"
|
91
|
+
|
92
|
+
end # "Unit Tests"
|
93
|
+
|
94
|
+
end # describe LogStash::Outputs::OpenNMS
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-output-opennms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- schneidermatic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-04 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'
|
39
|
+
name: logstash-codec-plain
|
40
|
+
prerelease: false
|
41
|
+
type: :runtime
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.0.12
|
53
|
+
name: logstash-devutils
|
54
|
+
prerelease: false
|
55
|
+
type: :development
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.0.12
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
name: logstash-filter-mutate
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
name: longshoreman
|
82
|
+
prerelease: false
|
83
|
+
type: :development
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
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
|
90
|
+
email: markus.schneider73@gmail.com
|
91
|
+
executables: []
|
92
|
+
extensions: []
|
93
|
+
extra_rdoc_files: []
|
94
|
+
files:
|
95
|
+
- CHANGELOG.md
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE
|
98
|
+
- lib/logstash/outputs/opennms.rb
|
99
|
+
- logstash-output-opennms.gemspec
|
100
|
+
- spec/README.md
|
101
|
+
- spec/helpers/opennms_helper.rb
|
102
|
+
- spec/outputs/opennms_spec.rb
|
103
|
+
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
104
|
+
licenses:
|
105
|
+
- Apache License (2.0)
|
106
|
+
metadata:
|
107
|
+
logstash_plugin: 'true'
|
108
|
+
logstash_group: output
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.8
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: This output sends a xml document (event) to an OpenNMS server.
|
129
|
+
test_files:
|
130
|
+
- spec/README.md
|
131
|
+
- spec/helpers/opennms_helper.rb
|
132
|
+
- spec/outputs/opennms_spec.rb
|