mackerel-client 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/RELEASE.md +7 -0
- data/VERSION +1 -1
- data/lib/mackerel-client.rb +1 -0
- data/lib/mackerel/client.rb +28 -0
- data/lib/mackerel/client/helper.rb +9 -0
- data/spec/mackerel/client/helper_spec.rb +10 -0
- data/spec/mackerel/client_spec.rb +98 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6d04e00e5c2881c62e69107348ec1df67d61c22
|
4
|
+
data.tar.gz: 2e05e0a387d92c2d455bf89dd83682cb5ec03b75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b67df943bbbf9b8b39d10960027201dda2a465184cdb86ead63aa3431e91d1b5d874a2a37aaaaa57b3bf7e30bde9d0937281779697d0a836895d67be34b1783
|
7
|
+
data.tar.gz: 9548aa1b053f7aec2c21b693ecca41bc22f26136ef920b984c91acc327791ae0abf770c7d57cf410d238f7fe9e45204ac170d1078bc21e253186e2cc356326db
|
data/.travis.yml
CHANGED
data/RELEASE.md
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'mackerel'
|
data/lib/mackerel/client.rb
CHANGED
@@ -15,6 +15,20 @@ module Mackerel
|
|
15
15
|
@api_key = args[:mackerel_api_key] || raise(ERROR_MESSAGE_FOR_API_KEY_ABSENCE)
|
16
16
|
end
|
17
17
|
|
18
|
+
def post_host(host)
|
19
|
+
response = client.post "/api/v0/hosts" do |req|
|
20
|
+
req.headers['X-Api-Key'] = @api_key
|
21
|
+
req.headers['Content-Type'] = 'application/json'
|
22
|
+
req.body = host.to_json
|
23
|
+
end
|
24
|
+
|
25
|
+
unless response.success?
|
26
|
+
raise "POST /api/v0/hosts failed: #{response.status}"
|
27
|
+
end
|
28
|
+
|
29
|
+
data = JSON.parse(response.body)
|
30
|
+
end
|
31
|
+
|
18
32
|
def get_host(host_id)
|
19
33
|
response = client.get "/api/v0/hosts/#{host_id}" do |req|
|
20
34
|
req.headers['X-Api-Key'] = @api_key
|
@@ -104,6 +118,20 @@ module Mackerel
|
|
104
118
|
data = JSON.parse(response.body)
|
105
119
|
end
|
106
120
|
|
121
|
+
def define_graphs(graph_defs)
|
122
|
+
response = client.post '/api/v0/graph-defs/create' do |req|
|
123
|
+
req.headers['X-Api-Key'] = @api_key
|
124
|
+
req.headers['Content-Type'] = 'application/json'
|
125
|
+
req.body = graph_defs.to_json
|
126
|
+
end
|
127
|
+
|
128
|
+
unless response.success?
|
129
|
+
raise "POST /api/v0/graph-defs/create failed: #{res.status} #{res.body}"
|
130
|
+
end
|
131
|
+
|
132
|
+
JSON.parse(response.body)
|
133
|
+
end
|
134
|
+
|
107
135
|
def get_hosts(opts = {})
|
108
136
|
response = client.get '/api/v0/hosts.json' do |req|
|
109
137
|
req.headers['X-Api-Key'] = @api_key
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'mackerel/client/helper'
|
2
|
+
|
3
|
+
describe Mackerel::Client::Helper do
|
4
|
+
describe '.as_safe_metric_name' do
|
5
|
+
it 'translates characters that cannot be used as a metric name to safe characters' do
|
6
|
+
name = 'readme.md'
|
7
|
+
expect(Mackerel::Client::Helper.as_safe_metric_name(name)).to eq('readme-md')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -13,6 +13,47 @@ describe Mackerel::Client do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
describe '#post_host' do
|
17
|
+
let(:stubbed_response) {
|
18
|
+
[
|
19
|
+
200,
|
20
|
+
{},
|
21
|
+
JSON.dump(response_object)
|
22
|
+
]
|
23
|
+
}
|
24
|
+
|
25
|
+
let(:test_client) {
|
26
|
+
Faraday.new do |builder|
|
27
|
+
builder.adapter :test do |stubs|
|
28
|
+
stubs.post(api_path) { stubbed_response }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
}
|
32
|
+
|
33
|
+
let(:hostId) { '21obeF4PhZN' }
|
34
|
+
|
35
|
+
let(:api_path) { '/api/v0/hosts' }
|
36
|
+
|
37
|
+
let(:host) {
|
38
|
+
{
|
39
|
+
'name' => 'host001',
|
40
|
+
'meta' => {},
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
let(:response_object) {
|
45
|
+
{ 'id' => hostId }
|
46
|
+
}
|
47
|
+
|
48
|
+
before do
|
49
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "successfully post host" do
|
53
|
+
expect(client.post_host(host)).to eq(response_object)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
16
57
|
describe '#get_host' do
|
17
58
|
let(:stubbed_response) {
|
18
59
|
[
|
@@ -256,6 +297,63 @@ describe Mackerel::Client do
|
|
256
297
|
end
|
257
298
|
end
|
258
299
|
|
300
|
+
describe '#define_graphs' do
|
301
|
+
let(:stubbed_response) {
|
302
|
+
[
|
303
|
+
200,
|
304
|
+
{},
|
305
|
+
JSON.dump(response_object)
|
306
|
+
]
|
307
|
+
}
|
308
|
+
|
309
|
+
let(:test_client) {
|
310
|
+
Faraday.new do |builder|
|
311
|
+
builder.adapter :test do |stubs|
|
312
|
+
stubs.post(api_path) { stubbed_response }
|
313
|
+
end
|
314
|
+
end
|
315
|
+
}
|
316
|
+
|
317
|
+
let(:api_path) { '/api/v0/graph-defs/create' }
|
318
|
+
|
319
|
+
let(:response_object) {
|
320
|
+
{ 'success' => true }
|
321
|
+
}
|
322
|
+
|
323
|
+
let(:defs) { [
|
324
|
+
{
|
325
|
+
name: 'custom.fish-catch',
|
326
|
+
displayName: 'My fish catch',
|
327
|
+
unit: 'integer',
|
328
|
+
metrics: [
|
329
|
+
{
|
330
|
+
name: 'custom.fish-catch.mackerel',
|
331
|
+
displayName: 'Mackerel',
|
332
|
+
isStacked: false,
|
333
|
+
},
|
334
|
+
{
|
335
|
+
name: 'custom.fish-catch.herring',
|
336
|
+
displayName: 'Herring',
|
337
|
+
isStacked: false,
|
338
|
+
},
|
339
|
+
{
|
340
|
+
name: 'custom.fish-catch.salmon',
|
341
|
+
displayName: 'Salmon',
|
342
|
+
isStacked: false,
|
343
|
+
},
|
344
|
+
]
|
345
|
+
}
|
346
|
+
] }
|
347
|
+
|
348
|
+
before do
|
349
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
350
|
+
end
|
351
|
+
|
352
|
+
it "successfully post metrics" do
|
353
|
+
expect(client.define_graphs(defs)).to eq(response_object)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
259
357
|
describe '#get_hosts' do
|
260
358
|
let(:stubbed_response) {
|
261
359
|
[
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mackerel developer team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -81,14 +81,18 @@ files:
|
|
81
81
|
- Gemfile
|
82
82
|
- LICENSE.txt
|
83
83
|
- README.md
|
84
|
+
- RELEASE.md
|
84
85
|
- Rakefile
|
85
86
|
- VERSION
|
86
87
|
- bin/mkr.rb
|
88
|
+
- lib/mackerel-client.rb
|
87
89
|
- lib/mackerel.rb
|
88
90
|
- lib/mackerel/client.rb
|
91
|
+
- lib/mackerel/client/helper.rb
|
89
92
|
- lib/mackerel/host.rb
|
90
93
|
- lib/mackerel/runner.rb
|
91
94
|
- mackerel-client.gemspec
|
95
|
+
- spec/mackerel/client/helper_spec.rb
|
92
96
|
- spec/mackerel/client_spec.rb
|
93
97
|
- spec/spec_helper.rb
|
94
98
|
homepage: https://mackerel.io/
|
@@ -111,10 +115,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
115
|
version: '0'
|
112
116
|
requirements: []
|
113
117
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.2.
|
118
|
+
rubygems_version: 2.2.2
|
115
119
|
signing_key:
|
116
120
|
specification_version: 4
|
117
121
|
summary: Mackerel client implemented by Ruby.
|
118
122
|
test_files:
|
123
|
+
- spec/mackerel/client/helper_spec.rb
|
119
124
|
- spec/mackerel/client_spec.rb
|
120
125
|
- spec/spec_helper.rb
|