opsgenie-heartbeat 0.1.2 → 0.2.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 +5 -5
- data/.rspec +0 -1
- data/CHANGELOG.md +12 -5
- data/lib/opsgenie/heartbeat.rb +75 -54
- data/lib/opsgenie/heartbeat/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: da1c834d20e5005f05c6d801a5bd4f9dac5863731ff2955e797a03df77d0d84d
|
4
|
+
data.tar.gz: c289500bca6f19798e742f8a195fefc67b85836235e1f7f45fd8abfe645c24b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a37ca5d1f7f334b01168188a2b250f726dd043489b4a77dcc9d495990256c426fabdd83d37300fc1cd7e7b907b0609d652ba133d14d01c56ff845bfa8b64cac
|
7
|
+
data.tar.gz: 34bdfde8fa03e238692ddc8b3cdfc0c77389637008a23e67dcaab13b177c37f4cf71787ef4cd901e74b1f2ffd5305d30bee9b50aa2b93d5260869693ade50654
|
data/.rspec
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
|
-
Updates in version 0.
|
1
|
+
## Updates in version 0.2.0:
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
- Allow updating of heartbeats
|
4
|
+
- Allow setting of team
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
##Updates in version 0.1.2:
|
8
|
+
|
9
|
+
- Instead of require 'opsgenie/heartbeat/heartbeat' now is require 'opsgenie/heartbeat'
|
10
|
+
|
11
|
+
## Updates in version 0.1.1:
|
12
|
+
|
13
|
+
- No need to supply name_transformer in initializer file unless wanted.
|
14
|
+
- Now there is default value -> name itself.
|
data/lib/opsgenie/heartbeat.rb
CHANGED
@@ -6,75 +6,96 @@ require 'rack'
|
|
6
6
|
|
7
7
|
module Opsgenie
|
8
8
|
module Heartbeat
|
9
|
+
class << self
|
10
|
+
def 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 ensure(name:, interval:, unit: , description:, enabled: true, team: nil)
|
25
|
+
return unless configuration.enabled
|
26
|
+
original_name = name
|
27
|
+
name = configuration.name_transformer.call(name)
|
9
28
|
|
10
|
-
|
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")
|
29
|
+
uri = URI.parse(url_for_resource(:get, name))
|
15
30
|
http = Net::HTTP.new(uri.host, uri.port)
|
16
31
|
http.use_ssl = true
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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, team: team)
|
35
|
+
end
|
21
36
|
end
|
22
|
-
end
|
23
37
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
name = configuration.name_transformer.call(name)
|
38
|
+
def delete(name)
|
39
|
+
return unless configuration.enabled
|
40
|
+
name = configuration.name_transformer.call(name)
|
28
41
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
unless response.is_a?(Net::HTTPSuccess)
|
34
|
-
create(name: original_name, description: description, interval: interval, unit: unit, enabled: enabled)
|
35
|
-
end
|
36
|
-
end
|
42
|
+
begin
|
43
|
+
uri = URI.parse(url_for_resource(:delete, name))
|
44
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
45
|
+
http.use_ssl = true
|
37
46
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
52
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
53
|
+
def update(name:, interval: nil, unit: nil, description: nil, enabled: nil, team: nil)
|
54
|
+
return unless configuration.enabled
|
55
|
+
create_or_update(:patch, name: name, description: description, interval: interval, unit: unit, enabled: enabled, team: team)
|
56
|
+
end
|
46
57
|
|
47
|
-
|
48
|
-
|
49
|
-
|
58
|
+
def create(name:, interval: nil, unit: nil, description: nil, enabled: nil, team: nil)
|
59
|
+
return unless configuration.enabled
|
60
|
+
create_or_update(:post, name: name, description: description, interval: interval, unit: unit, enabled: enabled, team: team)
|
50
61
|
end
|
51
|
-
end
|
52
62
|
|
53
|
-
private
|
54
63
|
|
55
|
-
|
56
|
-
name = configuration.name_transformer.call(name)
|
64
|
+
private
|
57
65
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
66
|
+
def url_for_resource(verb, name)
|
67
|
+
if verb == :post
|
68
|
+
'https://api.opsgenie.com/v2/heartbeats'
|
69
|
+
else
|
70
|
+
"https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}"
|
71
|
+
end
|
72
72
|
end
|
73
|
-
end
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
def create_or_update(verb, name:,description:,interval:,unit:, enabled:, team:)
|
75
|
+
name = configuration.name_transformer.call(name)
|
76
|
+
|
77
|
+
begin
|
78
|
+
uri = URI.parse(url_for_resource(verb, name))
|
79
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
80
|
+
http.use_ssl = true
|
81
|
+
doc = {
|
82
|
+
name: name,
|
83
|
+
description: description,
|
84
|
+
interval: interval,
|
85
|
+
intervalUnit: unit,
|
86
|
+
enabled: enabled,
|
87
|
+
ownerTeam: team
|
88
|
+
}.reject {|_, value| value.nil?}
|
89
|
+
http.public_send(verb, uri.path, doc.to_json, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
|
90
|
+
rescue => e
|
91
|
+
resolve_exception e
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def resolve_exception e
|
96
|
+
configuration.logger.info("Exception raised during heartbeat: #{e.message} #{e.backtrace}") if configuration.logger
|
97
|
+
raise if configuration.raise_error
|
98
|
+
end
|
78
99
|
end
|
79
100
|
end
|
80
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opsgenie-heartbeat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dressipi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.7.3
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: OpsGenie Heartbeat version 2
|