opsgenie-heartbeat 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +11 -0
- data/LICENSE.md +7 -0
- data/README.md +63 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/opsgenie-heartbeat +3 -0
- data/lib/opsgenie/heartbeat/config.rb +15 -0
- data/lib/opsgenie/heartbeat/heartbeat.rb +80 -0
- data/lib/opsgenie/heartbeat/version.rb +5 -0
- data/opsgenie-heartbeat.gemspec +27 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -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
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
@@ -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,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: []
|