logstash-output-opsgenienm 1.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 222f15826dccac154652a9e879669eba0535adfaf15205125b628ee47b7ed4d8
4
+ data.tar.gz: 45a4239dfbf280bcc8593ffbdb0e15ee9039637f55d23010b2aa3f9c7d058ef7
5
+ SHA512:
6
+ metadata.gz: 5fb7f7c846a81a91677fdd25846b8ecc14992511ff7db3ad4b740ef7900f68bc7684add7054a025f7abe11c45fe39259973a4831bc33d82854403ec1cc37a836
7
+ data.tar.gz: 59740fc4d0b8eaf809ee535dcab73d14e2cc7f91e638b12bb9dbfb9a0494bfd7a080aa79c7e7bd009433bbbe859f8ffdd26dc5c8d28f3d70a5640b7060721dc7
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
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
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # OpsGenie Logstash No Mutate Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash). It's
4
+ base on OpsGenie original plugin. The only difference is that you do not have
5
+ to modify your events to add OpsGenie specific fields to them.
6
+
7
+ ### Install and Run OpsGenie Output Plugin in Logstash
8
+
9
+ OpsGenie Logstash Output plugin is available in
10
+ [RubyGems.org](https://rubygems.org/gems/logstash-output-opsgenienm)
11
+
12
+ - Install plugin
13
+ ```sh
14
+ bin/plugin install logstash-output-opsgenienm
15
+ ```
16
+
17
+ - OpsGenie has Logstash Integration. To use the plugin you need to add a
18
+ [Logstash Integration](https://app.opsgenie.com/integration?add=Logstash) in
19
+ OpsGenie and obtain the API Key.
20
+ - Add the following configuration to your configuration file
21
+
22
+ ```sh
23
+ output {
24
+ opsgenie {
25
+ "api_key" => "logstash_integration_api_key"
26
+ }
27
+ }
28
+ ```
@@ -0,0 +1,117 @@
1
+ # encoding: utf-8
2
+
3
+ require 'logstash/outputs/base'
4
+ require 'logstash/namespace'
5
+ require 'json'
6
+ require 'uri'
7
+ require 'net/http'
8
+ require 'net/https'
9
+
10
+ # For more information about the api requests and their contents,
11
+ # please refer to Alert API("https://www.opsgenie.com/docs/web-api/alert-api") support doc.
12
+
13
+ class LogStash::Outputs::OpsGenie < LogStash::Outputs::Base
14
+
15
+ config_name 'opsgenie'
16
+
17
+ # OpsGenie Logstash Integration API Key
18
+ config :api_key, :validate => :string, :required => true
19
+
20
+ # OpsGenie API action
21
+ config :opsgenie_action, :validate => ["create", "close", "acknowledge", "note"], :default => "create"
22
+
23
+ # Host of opsgenie api, normally you should not need to change this field.
24
+ config :opsgenie_base_url, :validate => :string, :required => false, :default => 'https://api.opsgenie.com'
25
+
26
+ # Url will be used to create alerts in OpsGenie
27
+ config :create_action_url, :validate => :string, :required => false, :default => '/v1/json/alert'
28
+
29
+ # Url will be used to close alerts in OpsGenie
30
+ config :close_action_url, :validate => :string, :required => false, :default => '/v1/json/alert/close'
31
+
32
+ # Url will be used to acknowledge alerts in OpsGenie
33
+ config :acknowledge_action_url, :validate => :string, :required => false, :default => '/v1/json/alert/acknowledge'
34
+
35
+ # Url will be used to add notes to alerts in OpsGenie
36
+ config :note_action_url, :validate => :string, :required => false, :default => '/v1/json/alert/note'
37
+
38
+ # OpsGenie alert id
39
+ config :alert_id, :validate => :string, :required => false
40
+
41
+ # Alias of the alert that actions will be executed.
42
+ config :alert_alias, :validate => :string, :required => false
43
+
44
+ # Alert text.
45
+ config :message, :validate => :string, :required => true
46
+
47
+ # List of team names which will be responsible for the alert.
48
+ config :teams, :validate => :string, :required => false
49
+
50
+ # Detailed description of the alert.
51
+ config :description, :validate => :string, :required => false
52
+
53
+ # Optional user, group, schedule or escalation names to calculate which users will receive the notifications of the alert.
54
+ config :recipients, :validate => :string, :required => false
55
+
56
+ # Comma separated list of actions that can be executed on the alert.
57
+ config :actions, :validate => :string, :required => false
58
+
59
+ # Source of alert.
60
+ config :source, :validate => :string, :required => false
61
+
62
+ # Comma separated list of labels attached to the alert.
63
+ config :tags, :validate => :string, :required => false
64
+
65
+ # Set of user defined alert properties.
66
+ config :details, :validate => :hash, :default => {"description" => "%{description}"}
67
+
68
+ public
69
+ def register
70
+ opsgenie_uri = URI.parse(@opsgenie_base_url)
71
+ @client = Net::HTTP.new(opsgenie_uri.host, opsgenie_uri.port)
72
+ if opsgenie_uri.scheme == 'https'
73
+ @client.use_ssl = true
74
+ @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
75
+ end
76
+ end # def register
77
+
78
+ public
79
+ def receive(event)
80
+ alert = {
81
+ :apiKey => @api_key
82
+ }
83
+ case @opsgenie_action
84
+ when 'create'
85
+ action_path = @create_action_url
86
+ alert[:message] = event.sprintf(@message)
87
+ alert[:teams] = @teams if @teams
88
+ alert[:actions] = @actions if @actions
89
+ alert[:description] = event.sprintf(@description) if @description
90
+ alert[:recipients] = @recipients if @recipients
91
+ alert[:tags] = @tags if @tags
92
+ alert[:details] = {}
93
+ @details.each do |key, value|
94
+ alert[:details]["#{key}"] = event.sprintf(value)
95
+ end
96
+ when 'close'
97
+ action_path = @close_action_url
98
+ when 'acknowledge'
99
+ action_path = @acknowledge_action_url
100
+ when 'note'
101
+ action_path = @note_action_url
102
+ end
103
+
104
+ alert['alias'] = event.sprintf(@alert_alias) if @alert_alias
105
+ alert['id'] = event.sprintf(@alert_id) if @alert_id
106
+
107
+ begin
108
+ request = Net::HTTP::Post.new(action_path)
109
+ request.body = LogStash::Json.dump(alert)
110
+ @logger.debug('OpsGenie Request', :request => request.inspect)
111
+ response = @client.request(request)
112
+ @logger.debug('OpsGenie Response', :response => response.body)
113
+ rescue Exception => e
114
+ @logger.error('OpsGenie Unhandled exception', :og_error => e.backtrace)
115
+ end
116
+ end # def receive
117
+ end # class LogStash::Outputs::OpsGenie
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-opsgenienm'
3
+ s.version = '1.0.1'
4
+ s.licenses = ["Apache-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/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,11 @@
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( "api_key" => "my_api_key" )}
9
+ let(:logger) { subject.logger}
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-opsgenienm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Elastic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-19 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/plugin install gemname. This gem is not
63
+ 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-opsgenienm.gemspec
76
+ - spec/outputs/opsgenie_spec.rb
77
+ homepage: http://www.elastic.co/guide/en/logstash/current/index.html
78
+ licenses:
79
+ - Apache-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
+ rubyforge_project:
99
+ rubygems_version: 2.6.11
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: This output Creates, Closes, Acknowledges alerts and Adds Note to alerts
103
+ in OpsGenie.
104
+ test_files:
105
+ - spec/outputs/opsgenie_spec.rb