mackerel-client 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/RELEASE.md +3 -3
- data/VERSION +1 -1
- data/lib/mackerel/alert.rb +10 -1
- data/lib/mackerel/version.rb +1 -1
- data/spec/mackerel/alert_spec.rb +85 -12
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b8f49f34db204737703ca6814bca0b82f66360060ef9658c31c9937189027a7
|
4
|
+
data.tar.gz: f5f98e1939a2f69794cb43dafb5fb8fd8e21f2784904cbfb8d97b754f8f32857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e120aac91332700d0ef14137b699bef524755c9a8c876bc675486865fd84a50eff070a19da00df18d79dc77e2a2dfbe814a7c3f55ca8fbd0b02423b7b4ab8f1a
|
7
|
+
data.tar.gz: 14a98ef43f4431615b7f2141a54790c5c4177d9126542fd42acffe6ce3d6bc3af05e8cecb95fd2958ee792f6e8a87d868f27643102d40d177b8e923eb2e324bd
|
data/CHANGELOG.md
CHANGED
data/RELEASE.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
RELEASE
|
2
2
|
=======
|
3
3
|
|
4
|
-
1. Create release branch. (`git
|
4
|
+
1. Create release branch. (`git switch -c version-<VERSION>`)
|
5
5
|
1. Bump version `VERSION` and `lib/mackerel/version.rb` files.
|
6
6
|
1. Write changes in CHANGELOG.md
|
7
7
|
1. Push release branch to upstream(GitHub). (`git push -u origin version-<VERSION>`)
|
8
|
-
1. Create Pull-Request on
|
9
|
-
1. Merge Pull-Request to master branch on
|
8
|
+
1. Create Pull-Request on GitHub.
|
9
|
+
1. Merge Pull-Request to master branch on GitHub.
|
10
10
|
1. Tagging and Release. (`rake release`)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.12.0
|
data/lib/mackerel/alert.rb
CHANGED
@@ -31,12 +31,21 @@ module Mackerel
|
|
31
31
|
|
32
32
|
module REST
|
33
33
|
module Alert
|
34
|
-
def get_alerts()
|
34
|
+
def get_alerts(opts = {})
|
35
35
|
command = ApiCommand.new(:get, "/api/v0/alerts", @api_key)
|
36
|
+
command.params['withClosed'] = opts[:with_closed] if opts[:with_closed]
|
37
|
+
command.params['nextId'] = opts[:next_id] if opts[:next_id]
|
38
|
+
command.params['limit'] = opts[:limit] if opts[:limit]
|
36
39
|
data = command.execute(client)
|
37
40
|
data["alerts"].map { |a| Mackerel::Alert.new(a) }
|
38
41
|
end
|
39
42
|
|
43
|
+
def get_alert(alert_id)
|
44
|
+
command = ApiCommand.new(:get, "/api/v0/alerts/#{alert_id}", @api_key)
|
45
|
+
data = command.execute(client)
|
46
|
+
Mackerel::Alert.new(data)
|
47
|
+
end
|
48
|
+
|
40
49
|
def close_alert(alertId, reason)
|
41
50
|
command = ApiCommand.new(:post, "/api/v0/alerts/#{alertId}/close", @api_key)
|
42
51
|
command.body = { reason: reason.to_s }.to_json
|
data/lib/mackerel/version.rb
CHANGED
data/spec/mackerel/alert_spec.rb
CHANGED
@@ -11,15 +11,6 @@ RSpec.describe Mackerel::Client do
|
|
11
11
|
]
|
12
12
|
}
|
13
13
|
|
14
|
-
let(:test_client) {
|
15
|
-
Faraday.new do |builder|
|
16
|
-
builder.response :raise_error
|
17
|
-
builder.adapter :test do |stubs|
|
18
|
-
stubs.get(api_path) { stubbed_response }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
}
|
22
|
-
|
23
14
|
let(:api_path) { '/api/v0/alerts' }
|
24
15
|
|
25
16
|
let(:alertId) { 'abcdefg' }
|
@@ -42,16 +33,98 @@ RSpec.describe Mackerel::Client do
|
|
42
33
|
{ 'alerts' => alerts }
|
43
34
|
}
|
44
35
|
|
36
|
+
context 'no parameters' do
|
37
|
+
let(:test_client) {
|
38
|
+
Faraday.new do |builder|
|
39
|
+
builder.response :raise_error
|
40
|
+
builder.adapter :test do |stubs|
|
41
|
+
stubs.get(api_path) { stubbed_response }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
}
|
45
|
+
|
46
|
+
before do
|
47
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "successfully get alerts" do
|
51
|
+
expect(client.get_alerts().map(&:to_h)).to eq(alerts)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'with parameters' do
|
56
|
+
let(:with_closed) { true }
|
57
|
+
let(:next_id) { alertId }
|
58
|
+
let(:limit) { 100 }
|
59
|
+
|
60
|
+
let(:test_client) {
|
61
|
+
Faraday.new do |builder|
|
62
|
+
builder.response :raise_error
|
63
|
+
builder.adapter :test do |stubs|
|
64
|
+
stubs.get("#{api_path}?limit=#{limit}&nextId=#{next_id}&withClosed=#{with_closed}") { stubbed_response }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
}
|
68
|
+
|
69
|
+
before do
|
70
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "successfully get alerts" do
|
74
|
+
expect(
|
75
|
+
client.get_alerts(with_closed: with_closed, next_id: next_id, limit: limit).map(&:to_h)
|
76
|
+
).to eq(alerts)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#get_alert' do
|
82
|
+
let(:stubbed_response) {
|
83
|
+
[
|
84
|
+
200,
|
85
|
+
{},
|
86
|
+
JSON.dump(response_object)
|
87
|
+
]
|
88
|
+
}
|
89
|
+
|
90
|
+
let(:test_client) {
|
91
|
+
Faraday.new do |builder|
|
92
|
+
builder.response :raise_error
|
93
|
+
builder.adapter :test do |stubs|
|
94
|
+
stubs.get(api_path) { stubbed_response }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
}
|
98
|
+
|
99
|
+
let(:api_path) { "/api/v0/alerts/#{alert_id}" }
|
100
|
+
let(:alert_id) { 'abcdefg' }
|
101
|
+
let(:monitor_id) { 'hijklmnopqr' }
|
102
|
+
let(:reason) { 'Nantonaku' }
|
103
|
+
|
104
|
+
let(:alert) {
|
105
|
+
{
|
106
|
+
'id' => alert_id,
|
107
|
+
'status' => 'OK',
|
108
|
+
'reason' => reason,
|
109
|
+
'monitorId' => monitor_id,
|
110
|
+
'type' => 'check',
|
111
|
+
'openedAt' => 1234567890
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
let(:response_object) {
|
116
|
+
alert
|
117
|
+
}
|
118
|
+
|
45
119
|
before do
|
46
120
|
allow(client).to receive(:http_client).and_return(test_client)
|
47
121
|
end
|
48
122
|
|
49
|
-
it "successfully get
|
50
|
-
expect(client.
|
123
|
+
it "successfully get alert" do
|
124
|
+
expect(client.get_alert(alert_id).to_h).to eq(response_object)
|
51
125
|
end
|
52
126
|
end
|
53
127
|
|
54
|
-
|
55
128
|
describe '#close_alert' do
|
56
129
|
let(:stubbed_response) {
|
57
130
|
[
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mackerel-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mackerel developer team
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -138,7 +138,7 @@ homepage: https://mackerel.io/
|
|
138
138
|
licenses:
|
139
139
|
- Apache 2
|
140
140
|
metadata: {}
|
141
|
-
post_install_message:
|
141
|
+
post_install_message:
|
142
142
|
rdoc_options: []
|
143
143
|
require_paths:
|
144
144
|
- lib
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
156
|
rubygems_version: 3.0.3
|
157
|
-
signing_key:
|
157
|
+
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: Mackerel client implemented by Ruby.
|
160
160
|
test_files:
|