opsgenie-heartbeat 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cdb4690e39b718efad5667d9a3613a131d76da29
4
+ data.tar.gz: 49fb326700de66e7d731ff083940cf10e0c7b86b
5
+ SHA512:
6
+ metadata.gz: c2d687fac8f6cd626d2f44065c9319d0a021ad6f5b3ffd113001cbdfd00296ffb838d6f4197f78793519ca4f082d755d0bb1ee3e4388da7fceeb2d579a3b6cc0
7
+ data.tar.gz: 432866da5d8672ab90e2e985a796571b72c138901031505e9f4dc27f3cd0761bda3073866f594e2af7d901530d0382d9234d7724a8821b0d4ad8fc0a0818fa2a
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --warnings
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in opsgenie-heartbeat.gemspec
4
+ gemspec
5
+ gem "rails", "~>4.2.0"
6
+
7
+ group :development, :test do
8
+ gem 'webmock', '~> 3.0'
9
+ gem 'rspec-rails'
10
+ gem 'byebug'
11
+ end
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2017 Stylemania
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ # Opsgenie::Heartbeat
2
+
3
+ Use OpsGenie Heartbeat version 2 (REST API) https://docs.opsgenie.com/docs/rest-api/heartbeat-api
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'opsgenie-heartbeat'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install opsgenie-heartbeat
20
+
21
+ ## Usage
22
+
23
+ Ping, create or delete heartbeat requests with personalized name of heartbeat.
24
+
25
+ *Ping is used to ping defined heartbeat in OpsGenie.* <br />
26
+ *Ensure is used to define heartbeats in OpsGenie.* <br />
27
+ *Delete is used to delete monitored heartbeat in OpsGenie.*<br />
28
+
29
+
30
+ In yours initializers folder, define new file with:
31
+ ```ruby
32
+ require "opsgenie/heartbeat/heartbeat"
33
+
34
+ Opsgenie::Heartbeat.configure do |config|
35
+ #define opsgenie_api key in secrets.yml
36
+ config.api_key = Rails.application.secrets.opsgenie_api
37
+ #define environment from which requests should be made
38
+ config.enabled = Rails.env.production?
39
+ #customized method for naming heartbeats, may provide your own method
40
+ config.name_transformer = lambda do |name|
41
+ if Rails.configuration.aws_region == 'eu-west-1'
42
+ name
43
+ else
44
+ "#{name}-#{config.Rails.configuration.aws_region}"
45
+ end
46
+ end
47
+ #handling exceptions:
48
+ # - if logger is provided, error is written there,
49
+ # - if config.raise_error = true is set then it raises error
50
+ # - if nothing is defined, then it ignores error
51
+ config.logger = Rails.logger
52
+ end
53
+ ```
54
+
55
+ ## Development
56
+
57
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
58
+
59
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dressipi/opsgenie-heartbeat.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "opsgenie/heartbeat/heartbeat"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "opsgenie/heartbeat"
@@ -0,0 +1,15 @@
1
+ module Opsgenie
2
+ module Heartbeat
3
+ class<<self
4
+ attr_accessor :configuration
5
+ end
6
+ def self.configure
7
+ self.configuration ||= Config.new
8
+ yield(configuration)
9
+ end
10
+
11
+ class Config
12
+ attr_accessor :enabled, :api_key, :name_transformer, :logger, :raise_error
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,80 @@
1
+ require "opsgenie/heartbeat/config"
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'json'
5
+ require 'rack'
6
+
7
+ module Opsgenie
8
+ module Heartbeat
9
+
10
+ def self.pulse(name)
11
+ return unless configuration.enabled
12
+ name = configuration.name_transformer.call(name)
13
+ begin
14
+ uri = URI.parse("https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}/ping")
15
+ http = Net::HTTP.new(uri.host, uri.port)
16
+ http.use_ssl = true
17
+ data = {name: name}
18
+ http.post(uri.path, data.to_json, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
19
+ rescue => e
20
+ resolve_exception e
21
+ end
22
+ end
23
+
24
+ def self.ensure(name:, interval:, unit: , description:, enabled: true)
25
+ return unless configuration.enabled
26
+ original_name = name
27
+ name = configuration.name_transformer.call(name)
28
+
29
+ uri = URI.parse("https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}")
30
+ http = Net::HTTP.new(uri.host, uri.port)
31
+ http.use_ssl = true
32
+ response = http.get(uri.path)
33
+ unless response.is_a?(Net::HTTPSuccess)
34
+ create(name: original_name, description: description, interval: interval, unit: unit, enabled: enabled)
35
+ end
36
+ end
37
+
38
+ def self.delete(name)
39
+ return unless configuration.enabled
40
+ name = configuration.name_transformer.call(name)
41
+
42
+ begin
43
+ uri = URI.parse("https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}")
44
+ http = Net::HTTP.new(uri.host, uri.port)
45
+ http.use_ssl = true
46
+
47
+ http.delete(uri.path, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
48
+ rescue => e
49
+ resolve_exception e
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def self.create(name:,description:,interval:,unit:, enabled:)
56
+ name = configuration.name_transformer.call(name)
57
+
58
+ begin
59
+ uri = URI.parse('https://api.opsgenie.com/v2/heartbeats')
60
+ http = Net::HTTP.new(uri.host, uri.port)
61
+ http.use_ssl = true
62
+ doc = {
63
+ name: name,
64
+ description: description,
65
+ interval: interval,
66
+ intervalUnit: unit,
67
+ enabled: enabled
68
+ }
69
+ http.post(uri.path, doc.to_json, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
70
+ rescue => e
71
+ resolve_exception e
72
+ end
73
+ end
74
+
75
+ def self.resolve_exception e
76
+ configuration.logger.info("Exception raised during heartbeat: #{e.message} #{e.backtrace}") if configuration.logger
77
+ raise if configuration.raise_error
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module Opsgenie
2
+ module Heartbeat
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'opsgenie/heartbeat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opsgenie-heartbeat"
8
+ spec.version = Opsgenie::Heartbeat::VERSION
9
+ spec.authors = ["Dressipi"]
10
+ spec.email = ["wizards@dressipi.com"]
11
+
12
+ spec.summary = %q{OpsGenie Heartbeat version 2}
13
+ spec.description = %q{OpsGenie Heartbeat version 2}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opsgenie-heartbeat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dressipi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: OpsGenie Heartbeat version 2
56
+ email:
57
+ - wizards@dressipi.com
58
+ executables:
59
+ - opsgenie-heartbeat
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.md
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - exe/opsgenie-heartbeat
73
+ - lib/opsgenie/heartbeat/config.rb
74
+ - lib/opsgenie/heartbeat/heartbeat.rb
75
+ - lib/opsgenie/heartbeat/version.rb
76
+ - opsgenie-heartbeat.gemspec
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: OpsGenie Heartbeat version 2
101
+ test_files: []