flexciton-logstash-output-opsgenie 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 +7 -0
- data/CHANGELOG.md +43 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +5 -0
- data/README.md +56 -0
- data/lib/logstash/outputs/opsgenie.rb +294 -0
- data/logstash-output-opsgenie.gemspec +24 -0
- data/spec/outputs/opsgenie_spec.rb +52 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bde1d899898b78b0af27e898c6a07d8daf07e3ae84e97520a2b6fec854944b6f
|
4
|
+
data.tar.gz: dcb75c88e77ba0834b45ce94f564f709b0fa053e796fddbd5b7677c228c4e275
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d2be0b3b8b10a208a46fbb4e09579a14812f31e75322d888a15e6d65a4d360ecf5c90a9697946123868df6c005fd7c16401a91850ecf7d6a610dfda35954d19
|
7
|
+
data.tar.gz: a9aa782d9ddf3e3685c5582c0a0bf474f2a8c5ecc56c8db3a91c930f79ecb1a016cba57e1bd44108a11aa7acad2c407a883e9a3f685de825220f94eee9978610
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
## 3.0.0 (September 22, 2017)
|
2
|
+
|
3
|
+
### logstash-output-opsgenie
|
4
|
+
|
5
|
+
* Update plugin to work with Rest API.
|
6
|
+
* Please visit the documentation for more information about the API: https://docs.opsgenie.com/docs/alert-api
|
7
|
+
|
8
|
+
## 2.1.0 (June 13, 2017)
|
9
|
+
|
10
|
+
### logstash-output-opsgenie
|
11
|
+
|
12
|
+
* Rewrite event getter to make it compatible with Logstash 5.4.
|
13
|
+
* Added proxy settings to the HTTP request.
|
14
|
+
|
15
|
+
## 2.0.2 (April 11, 2016)
|
16
|
+
|
17
|
+
### logstash-output-opsgenie
|
18
|
+
|
19
|
+
* Convert alert details to hash.
|
20
|
+
|
21
|
+
## 2.0.1 (March 31, 2016)
|
22
|
+
|
23
|
+
### logstash-output-opsgenie
|
24
|
+
|
25
|
+
* Alert details field bug fix.
|
26
|
+
|
27
|
+
## 2.0.0 (February 23, 2016)
|
28
|
+
|
29
|
+
### logstash-output-opsgenie
|
30
|
+
|
31
|
+
* Change Logstash core dependency.
|
32
|
+
|
33
|
+
## 1.0.0 (September 30, 2015)
|
34
|
+
|
35
|
+
### logstash-output-opsgenie
|
36
|
+
|
37
|
+
* Update Readme with OpsGenie Integration and plugin installation info.
|
38
|
+
|
39
|
+
## 0.1.0 (September 29, 2015)
|
40
|
+
|
41
|
+
### logstash-output-opsgenie
|
42
|
+
|
43
|
+
* Initial public release.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
|
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.
|
data/NOTICE.TXT
ADDED
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# OpsGenie Logstash Plugin
|
2
|
+
|
3
|
+
This is a plugin for [Logstash](https://github.com/elastic/logstash).
|
4
|
+
|
5
|
+
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.
|
6
|
+
|
7
|
+
### Install and Run OpsGenie Output Plugin in Logstash
|
8
|
+
|
9
|
+
OpsGenie Logstash Output plugin is available in [RubyGems.org](https://rubygems.org/gems/logstash-output-opsgenie)
|
10
|
+
|
11
|
+
- `Logstash 5.4+`
|
12
|
+
```sh
|
13
|
+
bin/logstash-plugin install logstash-output-opsgenie
|
14
|
+
```
|
15
|
+
- `Other Versions`
|
16
|
+
```sh
|
17
|
+
bin/plugin install logstash-output-opsgenie
|
18
|
+
```
|
19
|
+
|
20
|
+
- OpsGenie has an integration with Logstash. To use the plugin you need to add a [Logstash Integration](https://app.opsgenie.com/integration?add=Logstash) in OpsGenie and obtain the API Key.
|
21
|
+
|
22
|
+
- You may use plugins like [Mutate](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) to populate the fields which will be used in [logstash-output-opsgenie](https://github.com/opsgenie/logstash-output-opsgenie).
|
23
|
+
```filter {
|
24
|
+
mutate{
|
25
|
+
add_field => {
|
26
|
+
"opsgenieAction" => "create"
|
27
|
+
"alias" => "neo123"
|
28
|
+
"description" => "Every alert needs a description"
|
29
|
+
"actions" => ["Restart", "AnExampleAction"]
|
30
|
+
"tags" => ["OverwriteQuietHours","Critical"]
|
31
|
+
"[details][prop1]"=> "val1"
|
32
|
+
"[details][prop2]" => "val2"
|
33
|
+
"entity" => "An example entity"
|
34
|
+
"priority" => "P4"
|
35
|
+
"source" => "custom source"
|
36
|
+
"user" => "custom user"
|
37
|
+
"note" => "alert is created"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
ruby {
|
41
|
+
code => "event.set('teams', [{'name' => 'Integration'}, {'name' => 'Platform'}])"
|
42
|
+
}
|
43
|
+
}
|
44
|
+
```
|
45
|
+
|
46
|
+
- Add the following configuration to your configuration file and populate "apiKey" field with your Logstash Integration API Key
|
47
|
+
```sh
|
48
|
+
output {
|
49
|
+
opsgenie {
|
50
|
+
"apiKey" => "logstash_integration_api_key"
|
51
|
+
}
|
52
|
+
}
|
53
|
+
```
|
54
|
+
- Run Logstash.
|
55
|
+
|
56
|
+
For more information about OpsGenie Logstash Integration, please refer to [integration guide](https://docs.opsgenie.com/docs/logstash-integration).
|
@@ -0,0 +1,294 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/outputs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require 'json'
|
5
|
+
require "uri"
|
6
|
+
require "net/http"
|
7
|
+
require "net/https"
|
8
|
+
|
9
|
+
|
10
|
+
HTTP_EXCEPTIONS = [
|
11
|
+
Errno::EINVAL,
|
12
|
+
Net::HTTPBadResponse,
|
13
|
+
Net::HTTPHeaderSyntaxError,
|
14
|
+
]
|
15
|
+
|
16
|
+
RETRYABLE_HTTP_EXCEPTIONS = [
|
17
|
+
OpenSSL::SSL::SSLError,
|
18
|
+
EOFError,
|
19
|
+
Timeout::Error,
|
20
|
+
Errno::ETIMEDOUT,
|
21
|
+
Errno::ECONNRESET,
|
22
|
+
Errno::ECONNREFUSED,
|
23
|
+
Net::ProtocolError,
|
24
|
+
SocketError,
|
25
|
+
EOFError
|
26
|
+
]
|
27
|
+
|
28
|
+
HTTP_EXCEPTION_RETRIES = 5
|
29
|
+
|
30
|
+
# The OpsGenie output is used to Create, Close, Acknowledge Alerts and Add Note to alerts in OpsGenie.
|
31
|
+
# For this output to work, your event must contain "opsgenieAction" field and you must configure apiKey field in configuration.
|
32
|
+
# If opsgenieAction is "create", event must contain "message" field.
|
33
|
+
# For other actions ("close", "acknowledge" or "note"), event must contain "alias" or "alertId" field.
|
34
|
+
#
|
35
|
+
# If your event have the following fields (If you use default field names).
|
36
|
+
#
|
37
|
+
# Example event:
|
38
|
+
#
|
39
|
+
# {
|
40
|
+
# "note" => "test note",
|
41
|
+
# "opsgenieAction" => "create",
|
42
|
+
# "teams" => ["teams"],
|
43
|
+
# "description" => "test description",
|
44
|
+
# "source" => "test source",
|
45
|
+
# "message" => "test message",
|
46
|
+
# "priority" => "P4",
|
47
|
+
# "tags" => ["tags"],
|
48
|
+
# "@timestamp" => 2017-09-15T13:32:00.747Z,
|
49
|
+
# "@version" => "1",
|
50
|
+
# "host" => "Neo's-MacBook-Pro.local",
|
51
|
+
# "alias" => "test-alias",
|
52
|
+
# "details" => {
|
53
|
+
# "prop2" => "val2",
|
54
|
+
# "prop1" => "val1"
|
55
|
+
# },
|
56
|
+
# "actions" => ["actions"],
|
57
|
+
# "user" => "test user",
|
58
|
+
# "entity" => "test entity"
|
59
|
+
# }
|
60
|
+
#
|
61
|
+
# An alert with following properties will be created.
|
62
|
+
#
|
63
|
+
# {
|
64
|
+
# "message": "test message",
|
65
|
+
# "alias": "test alias",
|
66
|
+
# "teams": ["teams"],
|
67
|
+
# "description": "test description",
|
68
|
+
# "source": "test source",
|
69
|
+
# "note": "test note",
|
70
|
+
# "user": "test user",
|
71
|
+
# "priority": "P4",
|
72
|
+
# "tags": [
|
73
|
+
# "tags"
|
74
|
+
# ],
|
75
|
+
# "details": {
|
76
|
+
# "prop2": "val2",
|
77
|
+
# "prop1": "val1"
|
78
|
+
# },
|
79
|
+
# "actions": [
|
80
|
+
# "actions"
|
81
|
+
# ],
|
82
|
+
# "entity": "test entity",
|
83
|
+
# }
|
84
|
+
#
|
85
|
+
# Fields with prefix "Attribute" are the keys of the fields will be extracted from Logstash event.
|
86
|
+
# For more information about the api requests and their contents,
|
87
|
+
# please refer to Alert API("https://docs.opsgenie.com/docs/alert-api") support doc.
|
88
|
+
|
89
|
+
class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
|
90
|
+
|
91
|
+
config_name "opsgenie"
|
92
|
+
|
93
|
+
# OpsGenie Logstash Integration API Key
|
94
|
+
config :apiKey, :validate => :string, :required => true
|
95
|
+
|
96
|
+
# Proxy settings
|
97
|
+
config :proxy_address, :validate => :string, :required => false
|
98
|
+
config :proxy_port, :validate => :number, :required => false
|
99
|
+
|
100
|
+
|
101
|
+
# Host of opsgenie api, normally you should not need to change this field.
|
102
|
+
config :opsGenieBaseUrl, :validate => :string, :required => false, :default => 'https://api.opsgenie.com/v2/alerts/'
|
103
|
+
|
104
|
+
# Url will be used to close alerts in OpsGenie
|
105
|
+
config :closeActionPath, :validate => :string, :required => false, :default =>'/close'
|
106
|
+
|
107
|
+
# Url will be used to acknowledge alerts in OpsGenie
|
108
|
+
config :acknowledgeActionPath, :validate => :string, :required => false, :default =>'/acknowledge'
|
109
|
+
|
110
|
+
# Url will be used to add notes to alerts in OpsGenie
|
111
|
+
config :noteActionPath, :validate => :string, :required => false, :default =>'/notes'
|
112
|
+
|
113
|
+
# The value of this field holds the name of the action will be executed in OpsGenie.
|
114
|
+
# This field must be in Event object. Should be one of "create", "close", "acknowledge" or "note". Other values will be discarded.
|
115
|
+
config :actionAttribute, :validate => :string, :required => false, :default => 'opsgenieAction'
|
116
|
+
|
117
|
+
# This value specifies the query parameter identifierType
|
118
|
+
config :identifierType, :validate => :string, :required => false, :default =>'id'
|
119
|
+
|
120
|
+
# This value will be set to eventual identifier according to event(id/alias).
|
121
|
+
config :identifier, :validate => :string, :required => false, :default =>''
|
122
|
+
|
123
|
+
# The value of this field holds the Id of the alert that actions will be executed.
|
124
|
+
# One of "alertId" or "alias" field must be in Event object, except from "create" action
|
125
|
+
config :alertIdAttribute, :validate => :string, :required => false, :default => 'alertId'
|
126
|
+
|
127
|
+
# The value of this field holds the alias of the alert that actions will be executed.
|
128
|
+
# One of "alertId" or "alias" field must be in Event object, except from "create" action
|
129
|
+
config :aliasAttribute, :validate => :string, :required => false, :default => 'alias'
|
130
|
+
|
131
|
+
# The value of this field holds the alert text.
|
132
|
+
config :messageAttribute, :validate => :string, :required => false, :default => 'message'
|
133
|
+
|
134
|
+
# The value of this field holds the list of team names which will be responsible for the alert.
|
135
|
+
config :teamsAttribute, :validate => :string, :required => false, :default => 'teams'
|
136
|
+
|
137
|
+
# The value of this field holds the Teams and users that the alert will become
|
138
|
+
# visible to without sending any notification.
|
139
|
+
config :visibleToAttribute, :validate => :string, :required => false, :default => 'visibleTo'
|
140
|
+
|
141
|
+
# The value of this field holds the detailed description of the alert.
|
142
|
+
config :descriptionAttribute, :validate => :string, :required => false, :default => 'description'
|
143
|
+
|
144
|
+
# The value of this field holds the comma separated list of actions that can be executed on the alert.
|
145
|
+
config :actionsAttribute, :validate => :string, :required => false, :default => 'actions'
|
146
|
+
|
147
|
+
# The value of this field holds the source of alert. By default, it will be assigned to IP address of incoming request.
|
148
|
+
config :sourceAttribute, :validate => :string, :required => false, :default => 'source'
|
149
|
+
|
150
|
+
# The value of this field holds the priority level of the alert
|
151
|
+
config :priorityAttribute, :validate => :string, :required => false, :default => 'priority'
|
152
|
+
|
153
|
+
# The value of this field holds the comma separated list of labels attached to the alert.
|
154
|
+
config :tagsAttribute, :validate => :string, :required => false, :default => 'tags'
|
155
|
+
|
156
|
+
# The value of this field holds the set of user defined properties. This will be specified as a nested JSON map
|
157
|
+
config :detailsAttribute, :validate => :string, :required => false, :default => 'details'
|
158
|
+
|
159
|
+
# The value of this field holds the entity the alert is related to.
|
160
|
+
config :entityAttribute, :validate => :string, :required => false, :default => 'entity'
|
161
|
+
|
162
|
+
# The value of this field holds the default owner of the execution. If user is not specified, owner of account will be used.
|
163
|
+
config :userAttribute, :validate => :string, :required => false, :default => 'user'
|
164
|
+
|
165
|
+
# The value of this field holds the additional alert note.
|
166
|
+
config :noteAttribute, :validate => :string, :required => false, :default => 'note'
|
167
|
+
|
168
|
+
|
169
|
+
public
|
170
|
+
def register
|
171
|
+
end # def register
|
172
|
+
|
173
|
+
public
|
174
|
+
def populateAliasOrId(event, params)
|
175
|
+
alertAlias = event.get(@aliasAttribute) if event.get(@aliasAttribute)
|
176
|
+
if alertAlias == nil then
|
177
|
+
alertId = event.get(@alertIdAttribute) if event.get(@alertIdAttribute)
|
178
|
+
if !(alertId == nil) then
|
179
|
+
@identifierType = 'id'
|
180
|
+
@identifier = alertId
|
181
|
+
end
|
182
|
+
else
|
183
|
+
@identifierType = 'alias'
|
184
|
+
@identifier = alertAlias
|
185
|
+
end
|
186
|
+
end # def populateAliasOrId
|
187
|
+
|
188
|
+
public
|
189
|
+
def executePost(uri, params)
|
190
|
+
unless uri == nil then
|
191
|
+
@logger.info("Executing url #{uri}")
|
192
|
+
url = URI(uri)
|
193
|
+
http = Net::HTTP.new(url.host, url.port, @proxy_address, @proxy_port)
|
194
|
+
if url.scheme == 'https'
|
195
|
+
http.use_ssl = true
|
196
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
197
|
+
end
|
198
|
+
|
199
|
+
retryCount = 0
|
200
|
+
begin
|
201
|
+
request = Net::HTTP::Post.new(
|
202
|
+
url.request_uri,
|
203
|
+
initheader = { "Content-Type" =>"application/json", "Authorization" => "GenieKey #{@apiKey}" }
|
204
|
+
)
|
205
|
+
request.body = params.to_json
|
206
|
+
response = http.request(request)
|
207
|
+
rescue *HTTP_EXCEPTIONS => e
|
208
|
+
@logger.warn("Silencing exception in logstash opsgenie outputs: [#{e.class}: #{e.message}]")
|
209
|
+
return
|
210
|
+
rescue *RETRYABLE_HTTP_EXCEPTIONS => e
|
211
|
+
if retryCount < HTTP_EXCEPTION_RETRIES
|
212
|
+
retryCount += 1
|
213
|
+
@logger.warn("Caught #{e.class}: #{e.message} - Retrying...")
|
214
|
+
exponentialBackoff(retryCount)
|
215
|
+
retry
|
216
|
+
else
|
217
|
+
@logger.warn(
|
218
|
+
"Silencing exception in logstash opsgenie outputs after #{HTTP_EXCEPTION_RETRIES} retries: [#{e.class}: #{e.message}]"
|
219
|
+
)
|
220
|
+
return
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
body = response.body
|
225
|
+
body = JSON.parse(body)
|
226
|
+
@logger.warn("Executed [#{uri}]. Response:[#{body}]")
|
227
|
+
end
|
228
|
+
end # def executePost
|
229
|
+
|
230
|
+
public
|
231
|
+
def receive(event)
|
232
|
+
return unless output?(event)
|
233
|
+
|
234
|
+
@logger.info("processing #{event}")
|
235
|
+
opsGenieAction = event.get(@actionAttribute) if event.get(@actionAttribute)
|
236
|
+
if opsGenieAction then
|
237
|
+
params = {}
|
238
|
+
populateCommonContent(params, event)
|
239
|
+
|
240
|
+
case opsGenieAction.downcase
|
241
|
+
when "create"
|
242
|
+
uri = "#{@opsGenieBaseUrl}"
|
243
|
+
params = populateCreateAlertContent(params, event)
|
244
|
+
when "close"
|
245
|
+
uri = "#{@opsGenieBaseUrl}#{@identifier}#{@closeActionPath}?identifierType=#{@identifierType}"
|
246
|
+
when "acknowledge"
|
247
|
+
uri = "#{@opsGenieBaseUrl}#{@identifier}#{@acknowledgeActionPath}?identifierType=#{@identifierType}"
|
248
|
+
when "note"
|
249
|
+
uri = "#{@opsGenieBaseUrl}#{@identifier}#{@noteActionPath}?identifierType=#{@identifierType}"
|
250
|
+
else
|
251
|
+
@logger.warn("Action #{opsGenieAction} does not match any available action, discarding..")
|
252
|
+
return
|
253
|
+
end
|
254
|
+
|
255
|
+
executePost(uri, params)
|
256
|
+
else
|
257
|
+
@logger.warn("No opsgenie action defined")
|
258
|
+
return
|
259
|
+
end
|
260
|
+
end # def receive
|
261
|
+
|
262
|
+
private
|
263
|
+
def populateCreateAlertContent(params, event)
|
264
|
+
params['message'] = event.get(@messageAttribute) if event.get(@messageAttribute)
|
265
|
+
params['alias'] = event.get(@aliasAttribute) if event.get(@aliasAttribute)
|
266
|
+
params['teams'] = event.get(@teamsAttribute) if event.get(@teamsAttribute)
|
267
|
+
params['visibleTo'] = event.get(@visibleToAttribute) if event.get(@visibleToAttribute)
|
268
|
+
params['description'] = event.get(@descriptionAttribute) if event.get(@descriptionAttribute)
|
269
|
+
params['actions'] = event.get(@actionsAttribute) if event.get(@actionsAttribute)
|
270
|
+
params['tags'] = event.get(@tagsAttribute) if event.get(@tagsAttribute)
|
271
|
+
params['entity'] = event.get(@entityAttribute) if event.get(@entityAttribute)
|
272
|
+
params['priority'] = event.get(@priorityAttribute) if event.get(@priorityAttribute)
|
273
|
+
params['details'] = event.get(@detailsAttribute) if event.get(@detailsAttribute)
|
274
|
+
|
275
|
+
|
276
|
+
return params
|
277
|
+
end
|
278
|
+
|
279
|
+
private
|
280
|
+
def populateCommonContent(params, event)
|
281
|
+
populateAliasOrId(event, params)
|
282
|
+
params['source'] = event.get(@sourceAttribute) if event.get(@sourceAttribute)
|
283
|
+
params['user'] = event.get(@userAttribute) if event.get(@userAttribute)
|
284
|
+
params['note'] = event.get(@noteAttribute) if event.get(@noteAttribute)
|
285
|
+
end
|
286
|
+
|
287
|
+
private
|
288
|
+
def exponentialBackoff(retryCount)
|
289
|
+
nap = (2**retryCount - 1) / 2
|
290
|
+
@logger.info("sleeping for #{'%.2f' % nap} seconds")
|
291
|
+
sleep nap
|
292
|
+
end
|
293
|
+
|
294
|
+
end # class LogStash::Outputs::OpsGenie
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'flexciton-logstash-output-opsgenie'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.licenses = ["Apache License (2.0)"]
|
5
|
+
s.summary = "This output Creates, Closes, Acknowledges alerts and Adds Note to alerts in OpsGenie."
|
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 = ["Elastic"]
|
8
|
+
s.email = "info@elastic.co"
|
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"
|
24
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "logstash/devutils/rspec/spec_helper"
|
2
|
+
require "logstash/outputs/opsgenie"
|
3
|
+
require "logstash/codecs/plain"
|
4
|
+
require "logstash/event"
|
5
|
+
|
6
|
+
describe LogStash::Outputs::OpsGenie do
|
7
|
+
|
8
|
+
subject {LogStash::Outputs::OpsGenie.new( "apiKey" => "my_api_key" )}
|
9
|
+
let(:logger) { subject.logger}
|
10
|
+
|
11
|
+
describe "receive message" do
|
12
|
+
|
13
|
+
it "when opsgenieAction is not specified" do
|
14
|
+
expect(logger).to receive(:warn).with("No opsgenie action defined").once
|
15
|
+
subject.receive({"message" => "test_alert","@version" => "1","@timestamp" => "2015-09-22T11:20:00.250Z"})
|
16
|
+
end
|
17
|
+
|
18
|
+
it "when opsgenieAction is not valid" do
|
19
|
+
action = "invalid"
|
20
|
+
expect(logger).to receive(:warn).with("Action #{action} does not match any available action, discarding..").once
|
21
|
+
subject.receive({"message" => "test_alert","@version" => "1","@timestamp" => "2015-09-22T11:20:00.250Z", "opsgenieAction" => action})
|
22
|
+
end
|
23
|
+
|
24
|
+
it "when opsGenieAction is 'create'" do
|
25
|
+
event = {"message" => "test_alert", "@version" => "1", "@timestamp" => "2015-09-22T11:20:00.250Z", "opsgenieAction" => "create"}
|
26
|
+
expect(logger).to receive(:info).with("processing #{event}").once
|
27
|
+
expect(logger).to receive(:info).with("Executing url #{subject.opsGenieBaseUrl}#{subject.createActionUrl}").once
|
28
|
+
subject.receive(event)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "when opsGenieAction is 'close'" do
|
32
|
+
event = {"message" => "test_alert", "@version" => "1", "@timestamp" => "2015-09-22T11:20:00.250Z", "opsgenieAction" => "close"}
|
33
|
+
expect(logger).to receive(:info).with("processing #{event}").once
|
34
|
+
expect(logger).to receive(:info).with("Executing url #{subject.opsGenieBaseUrl}#{subject.closeActionUrl}").once
|
35
|
+
subject.receive(event)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "when opsGenieAction is 'acknowledge'" do
|
39
|
+
event = {"message" => "test_alert", "@version" => "1", "@timestamp" => "2015-09-22T11:20:00.250Z", "opsgenieAction" => "acknowledge"}
|
40
|
+
expect(logger).to receive(:info).with("processing #{event}").once
|
41
|
+
expect(logger).to receive(:info).with("Executing url #{subject.opsGenieBaseUrl}#{subject.acknowledgeActionUrl}").once
|
42
|
+
subject.receive(event)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "when opsGenieAction is 'note'" do
|
46
|
+
event = {"message" => "test_alert", "@version" => "1", "@timestamp" => "2015-09-22T11:20:00.250Z", "opsgenieAction" => "note"}
|
47
|
+
expect(logger).to receive(:info).with("processing #{event}").once
|
48
|
+
expect(logger).to receive(:info).with("Executing url #{subject.opsGenieBaseUrl}#{subject.noteActionUrl}").once
|
49
|
+
subject.receive(event)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flexciton-logstash-output-opsgenie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elastic
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-01 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'
|
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'
|
61
|
+
description: This gem is a logstash plugin required to be installed on top of the
|
62
|
+
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
63
|
+
gem is not a stand-alone program
|
64
|
+
email: info@elastic.co
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- CHANGELOG.md
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- NOTICE.TXT
|
73
|
+
- README.md
|
74
|
+
- lib/logstash/outputs/opsgenie.rb
|
75
|
+
- logstash-output-opsgenie.gemspec
|
76
|
+
- spec/outputs/opsgenie_spec.rb
|
77
|
+
homepage: http://www.elastic.co/guide/en/logstash/current/index.html
|
78
|
+
licenses:
|
79
|
+
- Apache License (2.0)
|
80
|
+
metadata:
|
81
|
+
logstash_plugin: 'true'
|
82
|
+
logstash_group: output
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubygems_version: 3.3.24
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: This output Creates, Closes, Acknowledges alerts and Adds Note to alerts
|
102
|
+
in OpsGenie.
|
103
|
+
test_files:
|
104
|
+
- spec/outputs/opsgenie_spec.rb
|