logstash-output-opsgenie 2.1.0 → 3.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
  SHA1:
3
- metadata.gz: 2ee26d60c05c3c473e778354fa9ec42a40b5fe33
4
- data.tar.gz: 2bc3a2b1db6804848bf87b02773aca6a4e9b6abf
3
+ metadata.gz: 879ee69bcc8c74773d2012eb9c7bd81fc5769ae7
4
+ data.tar.gz: a8875eecceeb87845d71b3742036eb1b94b00f4d
5
5
  SHA512:
6
- metadata.gz: d9980c7494916bee71e1b893dc29adc5d21be7b06c3a4e67c410901f89b8dbcd219e3a8809eefb6dc22cff46cd10fe4dc3b1b1a6c700e9a4c44aba563b56ed87
7
- data.tar.gz: a60009f01a762540a9e060f50645da3246c2b14dac51f4604256b296d3d232ba47d05b5c6bdf01f0c40c05f782515739b2452eae849b0afd8699751a7e9a97cb
6
+ metadata.gz: af122c65f7e74fa4524e969f9f90e16f975f60b0885f79c6b23622b1fcc5551916628b5afb690fec4d465241d8fb3ccf6d710b73f418c08d99da77c84439dd6b
7
+ data.tar.gz: 92ebe7188eb5bdfba10659ae65a70149ca41226722dcb85061923583ef80ee4924c63d07031d3e20062534ceebe61fad9d17e271c6ffcc68e8f922b19b16b8bb
@@ -8,62 +8,62 @@ require "net/https"
8
8
 
9
9
  # The OpsGenie output is used to Create, Close, Acknowledge Alerts and Add Note to alerts in OpsGenie.
10
10
  # For this output to work, your event must contain "opsgenieAction" field and you must configure apiKey field in configuration.
11
- # If opsgenieAction is "create", event must contain "message" field.
12
- # For other actions ("close", "acknowledge" or "note"), event must contain "alias" or "alertId" field.
11
+ # If opsgenieAction is "create", event must contain "message" field.
12
+ # For other actions ("close", "acknowledge" or "note"), event must contain "alias" or "alertId" field.
13
13
  #
14
14
  # If your event have the following fields (If you use default field names).
15
15
  #
16
- # Example JSON-encoded event:
16
+ # Example event:
17
17
  #
18
- # {
19
- # "message": "alert_message",
20
- # "@version": "1",
21
- # "@timestamp": "2015-09-22T11:20:00.250Z",
22
- # "host": "192.168.1.1",
23
- # "opsgenieAction": "create",
24
- # "alias": "alert_alias",
25
- # "teams": ["teams"],
26
- # "recipients": "the-recipients",
27
- # "description": "alert_description",
28
- # "actions": ["actions"],
29
- # "source": "alert_source",
30
- # "tags": ["tags"],
31
- # "entity": "alert_entity",
32
- # "user": "alert_owner",
33
- # "note": "additional_alert_note"
34
- # "details": [
35
- # "extra_prop1:value1",
36
- # "extra_prop2:value2"
37
- # ]
38
- # }
18
+ # {
19
+ # "note" => "test note",
20
+ # "opsgenieAction" => "create",
21
+ # "teams" => ["teams"],
22
+ # "description" => "test description",
23
+ # "source" => "test source",
24
+ # "message" => "test message",
25
+ # "priority" => "P4",
26
+ # "tags" => ["tags"],
27
+ # "@timestamp" => 2017-09-15T13:32:00.747Z,
28
+ # "@version" => "1",
29
+ # "host" => "Neo's-MacBook-Pro.local",
30
+ # "alias" => "test-alias",
31
+ # "details" => {
32
+ # "prop2" => "val2",
33
+ # "prop1" => "val1"
34
+ # },
35
+ # "actions" => ["actions"],
36
+ # "user" => "test user",
37
+ # "entity" => "test entity"
38
+ # }
39
39
  #
40
40
  # An alert with following properties will be created.
41
41
  #
42
42
  # {
43
- # "message": "alert_message",
44
- # "alias": "alert_alias",
43
+ # "message": "test message",
44
+ # "alias": "test alias",
45
45
  # "teams": ["teams"],
46
- # "description": "alert_description",
47
- # "source": "alert_source",
46
+ # "description": "test description",
47
+ # "source": "test source",
48
+ # "note": "test note",
49
+ # "user": "test user",
50
+ # "priority": "P4",
48
51
  # "tags": [
49
52
  # "tags"
50
53
  # ],
51
- # "recipients": [
52
- # "the-recipients"
53
- # ],
54
54
  # "details": {
55
- # "extra_prop1": "value1",
56
- # "extra_prop2": "value2"
55
+ # "prop2": "val2",
56
+ # "prop1": "val1"
57
57
  # },
58
58
  # "actions": [
59
59
  # "actions"
60
60
  # ],
61
- # "entity": "alert_entity",
61
+ # "entity": "test entity",
62
62
  # }
63
63
  #
64
64
  # Fields with prefix "Attribute" are the keys of the fields will be extracted from Logstash event.
65
65
  # For more information about the api requests and their contents,
66
- # please refer to Alert API("https://www.opsgenie.com/docs/web-api/alert-api") support doc.
66
+ # please refer to Alert API("https://docs.opsgenie.com/docs/alert-api") support doc.
67
67
 
68
68
  class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
69
69
 
@@ -78,25 +78,27 @@ class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
78
78
 
79
79
 
80
80
  # Host of opsgenie api, normally you should not need to change this field.
81
- config :opsGenieBaseUrl, :validate => :string, :required => false, :default => 'https://api.opsgenie.com'
82
-
83
- # Url will be used to create alerts in OpsGenie
84
- config :createActionUrl, :validate => :string, :required => false, :default =>'/v1/json/alert'
81
+ config :opsGenieBaseUrl, :validate => :string, :required => false, :default => 'https://api.opsgenie.com/v2/alerts/'
85
82
 
86
83
  # Url will be used to close alerts in OpsGenie
87
- config :closeActionUrl, :validate => :string, :required => false, :default =>'/v1/json/alert/close'
84
+ config :closeActionPath, :validate => :string, :required => false, :default =>'/close'
88
85
 
89
86
  # Url will be used to acknowledge alerts in OpsGenie
90
- config :acknowledgeActionUrl, :validate => :string, :required => false, :default =>'/v1/json/alert/acknowledge'
87
+ config :acknowledgeActionPath, :validate => :string, :required => false, :default =>'/acknowledge'
91
88
 
92
89
  # Url will be used to add notes to alerts in OpsGenie
93
- config :noteActionUrl, :validate => :string, :required => false, :default =>'/v1/json/alert/note'
94
-
90
+ config :noteActionPath, :validate => :string, :required => false, :default =>'/notes'
95
91
 
96
92
  # The value of this field holds the name of the action will be executed in OpsGenie.
97
93
  # This field must be in Event object. Should be one of "create", "close", "acknowledge" or "note". Other values will be discarded.
98
94
  config :actionAttribute, :validate => :string, :required => false, :default => 'opsgenieAction'
99
95
 
96
+ # This value specifies the query parameter identifierType
97
+ config :identifierType, :validate => :string, :required => false, :default =>'id'
98
+
99
+ # This value will be set to eventual identifier according to event(id/alias).
100
+ config :identifier, :validate => :string, :required => false, :default =>''
101
+
100
102
  # The value of this field holds the Id of the alert that actions will be executed.
101
103
  # One of "alertId" or "alias" field must be in Event object, except from "create" action
102
104
  config :alertIdAttribute, :validate => :string, :required => false, :default => 'alertId'
@@ -111,18 +113,22 @@ class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
111
113
  # The value of this field holds the list of team names which will be responsible for the alert.
112
114
  config :teamsAttribute, :validate => :string, :required => false, :default => 'teams'
113
115
 
116
+ # The value of this field holds the Teams and users that the alert will become
117
+ # visible to without sending any notification.
118
+ config :visibleToAttribute, :validate => :string, :required => false, :default => 'visibleTo'
119
+
114
120
  # The value of this field holds the detailed description of the alert.
115
121
  config :descriptionAttribute, :validate => :string, :required => false, :default => 'description'
116
122
 
117
- # The value of this field holds the optional user, group, schedule or escalation names to calculate which users will receive the notifications of the alert.
118
- config :recipientsAttribute, :validate => :string, :required => false, :default => 'recipients'
119
-
120
123
  # The value of this field holds the comma separated list of actions that can be executed on the alert.
121
124
  config :actionsAttribute, :validate => :string, :required => false, :default => 'actions'
122
125
 
123
126
  # The value of this field holds the source of alert. By default, it will be assigned to IP address of incoming request.
124
127
  config :sourceAttribute, :validate => :string, :required => false, :default => 'source'
125
128
 
129
+ # The value of this field holds the priority level of the alert
130
+ config :priorityAttribute, :validate => :string, :required => false, :default => 'priority'
131
+
126
132
  # The value of this field holds the comma separated list of labels attached to the alert.
127
133
  config :tagsAttribute, :validate => :string, :required => false, :default => 'tags'
128
134
 
@@ -149,16 +155,18 @@ class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
149
155
  if alertAlias == nil then
150
156
  alertId = event.get(@alertIdAttribute) if event.get(@alertIdAttribute)
151
157
  if !(alertId == nil) then
152
- params['alertId'] = alertId;
158
+ @identifierType = 'id'
159
+ @identifier = alertId
153
160
  end
154
161
  else
155
- params['alias'] = alertAlias
162
+ @identifierType = 'alias'
163
+ @identifier = alertAlias
156
164
  end
157
165
  end # def populateAliasOrId
158
166
 
159
167
  public
160
168
  def executePost(uri, params)
161
- if not uri == nil then
169
+ unless uri == nil then
162
170
  @logger.info("Executing url #{uri}")
163
171
  url = URI(uri)
164
172
  http = Net::HTTP.new(url.host, url.port, @proxy_address, @proxy_port)
@@ -166,7 +174,7 @@ class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
166
174
  http.use_ssl = true
167
175
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
168
176
  end
169
- request = Net::HTTP::Post.new(url.path)
177
+ request = Net::HTTP::Post.new(url.request_uri, initheader = { "Content-Type" =>"application/json", "Authorization" => "GenieKey #{@apiKey}" })
170
178
  request.body = params.to_json
171
179
  response = http.request(request)
172
180
  body = response.body
@@ -178,26 +186,28 @@ class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
178
186
  public
179
187
  def receive(event)
180
188
  return unless output?(event)
189
+
181
190
  @logger.info("processing #{event}")
182
191
  opsGenieAction = event.get(@actionAttribute) if event.get(@actionAttribute)
183
192
  if opsGenieAction then
184
- params = { :apiKey => @apiKey}
193
+ params = {}
194
+ populateCommonContent(params, event)
195
+
185
196
  case opsGenieAction.downcase
186
197
  when "create"
187
- uri = "#{@opsGenieBaseUrl}#{@createActionUrl}"
198
+ uri = "#{@opsGenieBaseUrl}"
188
199
  params = populateCreateAlertContent(params, event)
189
200
  when "close"
190
- uri = "#{@opsGenieBaseUrl}#{@closeActionUrl}"
201
+ uri = "#{@opsGenieBaseUrl}#{@identifier}#{@closeActionPath}?identifierType=#{@identifierType}"
191
202
  when "acknowledge"
192
- uri = "#{@opsGenieBaseUrl}#{@acknowledgeActionUrl}"
203
+ uri = "#{@opsGenieBaseUrl}#{@identifier}#{@acknowledgeActionPath}?identifierType=#{@identifierType}"
193
204
  when "note"
194
- uri = "#{@opsGenieBaseUrl}#{@noteActionUrl}"
205
+ uri = "#{@opsGenieBaseUrl}#{@identifier}#{@noteActionPath}?identifierType=#{@identifierType}"
195
206
  else
196
207
  @logger.warn("Action #{opsGenieAction} does not match any available action, discarding..")
197
208
  return
198
209
  end
199
210
 
200
- populateCommonContent(params, event)
201
211
  executePost(uri, params)
202
212
  else
203
213
  @logger.warn("No opsgenie action defined")
@@ -208,14 +218,17 @@ class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
208
218
  private
209
219
  def populateCreateAlertContent(params, event)
210
220
  params['message'] = event.get(@messageAttribute) if event.get(@messageAttribute)
221
+ params['alias'] = event.get(@aliasAttribute) if event.get(@aliasAttribute)
211
222
  params['teams'] = event.get(@teamsAttribute) if event.get(@teamsAttribute)
223
+ params['visibleTo'] = event.get(@visibleToAttribute) if event.get(@visibleToAttribute)
212
224
  params['description'] = event.get(@descriptionAttribute) if event.get(@descriptionAttribute)
213
- params['recipients'] = event.get(@recipientsAttribute) if event.get(@recipientsAttribute)
214
225
  params['actions'] = event.get(@actionsAttribute) if event.get(@actionsAttribute)
215
226
  params['tags'] = event.get(@tagsAttribute) if event.get(@tagsAttribute)
216
227
  params['entity'] = event.get(@entityAttribute) if event.get(@entityAttribute)
228
+ params['priority'] = event.get(@priorityAttribute) if event.get(@priorityAttribute)
217
229
  params['details'] = event.get(@detailsAttribute) if event.get(@detailsAttribute)
218
230
 
231
+
219
232
  return params
220
233
  end
221
234
 
@@ -227,4 +240,4 @@ class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
227
240
  params['note'] = event.get(@noteAttribute) if event.get(@noteAttribute)
228
241
  end
229
242
 
230
- end # class LogStash::Outputs::OpsGenie
243
+ end # class LogStash::Outputs::OpsGenie
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-opsgenie'
3
- s.version = '2.1.0'
3
+ s.version = '3.0.0'
4
4
  s.licenses = ["Apache License (2.0)"]
5
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/plugin install gemname. This gem is not a stand-alone program"
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
7
  s.authors = ["Elastic"]
8
8
  s.email = "info@elastic.co"
9
9
  s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-opsgenie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2017-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core-plugin-api
@@ -59,8 +59,8 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  description: This gem is a logstash plugin required to be installed on top of the
62
- Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
63
- a stand-alone program
62
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
63
+ gem is not a stand-alone program
64
64
  email: info@elastic.co
65
65
  executables: []
66
66
  extensions: []