oops_genie 0.1.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: 4fec143560a972acc41b8e6f05d96d581d0febb40bba47b4017e392dad5b1e2a
4
+ data.tar.gz: 2712772c20ad403e70713b384946a6d8a419cd53afcfc2868981649a48bbed35
5
+ SHA512:
6
+ metadata.gz: dd35f38582c3ee64193e8b0d00ebc2bd2e323d29d5bde511a65bfddc767e978375924d9e583df7d923ef23fdaaa759fef5fcf6238f746d321366a362caddac7c
7
+ data.tar.gz: 708cab94edc2543fad1f528d7e2936c46ad43fbdfe59ad5878b17c4089b44db31cb698a1a79dfda1ce4fca9530aea53aefa402e8db755893e8b058db6c19e512
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2020 dondeng
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # OopsGenie
2
+ This is a minimal gem that integrates to the OpsGenie API specification.
3
+ Right now only OpsGenie Alerts are implemented. More functionality will follow
4
+ later.
5
+
6
+ ## Usage
7
+ Create an OopsGenieAlert Object minimally providing your OpsGenie api key and a
8
+ message.
9
+ ```ruby
10
+ alert = OopsGenie::OopsGenieAlert.new('your api key here', 'Testing Alerts')
11
+ alert.send_alert
12
+ ```
13
+
14
+ Additionally you can set other configuration parameters to the alert object
15
+ before sending. eg.
16
+ ```ruby
17
+ alert = OopsGenie::OopsGenieAlert.new('your api key here', 'Testing Alerts')
18
+ alert.tags = ['Critical', 'Another tag']
19
+ alert.priority = 'P1'
20
+ alert.send_alert
21
+
22
+ ```
23
+
24
+ Attributes that can be set on the alert oject are:
25
+ - api_key
26
+ - message
27
+ - alias
28
+ - actions
29
+ - tags
30
+ - details
31
+ - entity
32
+ - priority
33
+ - responders
34
+
35
+ See the [OpsGenie API](https://docs.opsgenie.com/docs/api-integration) for more information on these.
36
+ ## Installation
37
+ Add this line to your application's Gemfile:
38
+
39
+ ```ruby
40
+ gem 'oops_genie'
41
+ ```
42
+
43
+ And then execute:
44
+ ```bash
45
+ $ bundle
46
+ ```
47
+
48
+ Or install it yourself as:
49
+ ```bash
50
+ $ gem install oops_genie
51
+ ```
52
+
53
+ ## Contributing
54
+ Contribution directions go here.
55
+
56
+ ## License
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'OopsGenie'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
data/lib/oops_genie.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "oops_genie/railtie"
2
+ require 'oops_genie/oops_genie_client'
3
+ require 'oops_genie/oops_genie_alert'
4
+
5
+ module OopsGenie
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OopsGenie
4
+ # configuration object to hold details of an OpsGenie Alert
5
+ class OopsGenieAlert
6
+ attr_accessor :message, :alias, :description, :responders, :actions, :tags,
7
+ :details, :entity, :priority, :api_key
8
+
9
+ def initialize(api_key, message)
10
+ @api_key = api_key
11
+ @message = message
12
+ @alias = nil
13
+ @actions = nil
14
+ @tags = nil
15
+ @details = { description: message }
16
+ @entity = nil
17
+ @priority = nil
18
+ @responders = nil
19
+ end
20
+
21
+ def alert_hash
22
+ attrs = {}
23
+ instance_variables.each do |var|
24
+ str = var.to_s.gsub /^@/, ''
25
+ if respond_to? "#{str}="
26
+ attrs[str.to_sym] = instance_variable_get var
27
+ end
28
+ end
29
+ attrs
30
+ end
31
+
32
+ def send_alert
33
+ og_client = OopsGenie::OopsGenieClient.new(@api_key)
34
+ response = og_client.send_alert(self)
35
+ puts response
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ module OopsGenie
8
+ # Implement sending an alert to OpsGenie
9
+ #
10
+ class OopsGenieClient
11
+ def initialize(api_key)
12
+ @api_key = api_key
13
+ # TODO: dondeng - Do not hard code this
14
+ @url_prefix = 'https://api.eu.opsgenie.com/v2/alerts'
15
+ end
16
+
17
+ def fetch_json(alert_config)
18
+ uri = URI(@url_prefix)
19
+ https = Net::HTTP.new(uri.host, uri.port)
20
+ https.use_ssl = true
21
+
22
+ request = Net::HTTP::Post.new(uri.request_uri,
23
+ { 'Content-Type' => 'application/json',
24
+ 'Authorization' => "GenieKey #{@api_key}" })
25
+ request.body = alert_config.alert_hash.to_json
26
+ res = https.request(request)
27
+ return JSON.parse(res.body) if res.is_a?(Net::HTTPSuccess)
28
+
29
+ false
30
+ rescue StandardError => e
31
+ puts "Error in oops_genie gem: #{e.message}"
32
+ false
33
+ end
34
+
35
+ def send_alert(alert_config)
36
+ response = fetch_json(alert_config)
37
+ response == false ? 'Alert could not be generated.' : 'Alert generated.'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module OopsGenie
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module OopsGenie
2
+ VERSION = '0.1.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :oops_genie do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oops_genie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - dondeng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: This is a minimal gem that integrates to the OpsGenie API specification.
56
+ Right now only OpsGenie Alerts are implemented. More functionality will follow later.
57
+ email:
58
+ - dondeng2@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/oops_genie.rb
67
+ - lib/oops_genie/oops_genie_alert.rb
68
+ - lib/oops_genie/oops_genie_client.rb
69
+ - lib/oops_genie/railtie.rb
70
+ - lib/oops_genie/version.rb
71
+ - lib/tasks/oops_genie_tasks.rake
72
+ homepage: https://github.com/dondeng/oops_genie
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ allowed_push_host: https://rubygems.org
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.7.10
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Integration to OpsGenie API
97
+ test_files: []