mackerel-client 0.0.1 → 0.0.2
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 +4 -4
- data/.travis.yml +5 -0
- data/README.md +7 -8
- data/VERSION +1 -1
- data/lib/mackerel/client.rb +16 -0
- data/lib/mackerel/runner.rb +28 -17
- data/spec/mackerel/client_spec.rb +34 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6469f220c097bfce9c5410a1897c517cf498f396
|
4
|
+
data.tar.gz: 1e343adc7d72fd577f2d1a12c2fa022382186114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65fa9d1846465abc5b741b2785fe02a3cc617c34c438f2a51089d3919ea36aeb6aef5661fe5b636a0f9c53ed8f808495c85ea8e26ebbdd21a0d1017be6ebcf18
|
7
|
+
data.tar.gz: 1e26dc9a86fd0118176cad8d3ad11ff0536c4633b06e46dedd29ab331cdde25a8691877faa60c0a7097e6a89a779beb804d7605aca221b2c84526a465c3e8cf5
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
TODO: Write a gem description
|
1
|
+
# mackerel-client [](https://travis-ci.org/mackerelio/mackerel-client-ruby)
|
4
2
|
|
3
|
+
mackerel-client is a ruby library to access Mackerel (https://mackerel.io/). CLI tool `mkr` is also provided.
|
5
4
|
|
6
5
|
# CLI
|
7
6
|
|
@@ -17,6 +16,11 @@ mkr host info [--name foo] [--service service] [--role role]
|
|
17
16
|
mkr host status --host-id foo --status working
|
18
17
|
```
|
19
18
|
|
19
|
+
* Retire a host
|
20
|
+
```
|
21
|
+
mkr host retire --host-id foo
|
22
|
+
```
|
23
|
+
|
20
24
|
* Get status of a host (not implemented yet)
|
21
25
|
```
|
22
26
|
mkr host status --host-id foo
|
@@ -26,8 +30,3 @@ mkr host status --host-id foo
|
|
26
30
|
```
|
27
31
|
export MACKEREL_APIKEY=foobar
|
28
32
|
```
|
29
|
-
|
30
|
-
## reference
|
31
|
-
* http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html
|
32
|
-
* https://github.com/aws/aws-cli
|
33
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/mackerel/client.rb
CHANGED
@@ -48,6 +48,22 @@ module Mackerel
|
|
48
48
|
data = JSON.parse(response.body)
|
49
49
|
end
|
50
50
|
|
51
|
+
def retire_host(host_id)
|
52
|
+
client = http_client
|
53
|
+
|
54
|
+
response = client.post "/api/v0/hosts/#{host_id}/retire" do |req|
|
55
|
+
req.headers['X-Api-Key'] = @api_key
|
56
|
+
req.headers['Content-Type'] = 'application/json'
|
57
|
+
req.body = { }.to_json
|
58
|
+
end
|
59
|
+
|
60
|
+
unless response.success?
|
61
|
+
raise "POST /api/v0/hosts/#{host_id}/retire faild: #{response.status}"
|
62
|
+
end
|
63
|
+
|
64
|
+
data = JSON.parse(response.body)
|
65
|
+
end
|
66
|
+
|
51
67
|
def post_metrics(metrics)
|
52
68
|
client = http_client
|
53
69
|
|
data/lib/mackerel/runner.rb
CHANGED
@@ -36,6 +36,9 @@ module Mackerel
|
|
36
36
|
Set status of a host
|
37
37
|
mkr host status --host-id foo --status working
|
38
38
|
|
39
|
+
Retire a host
|
40
|
+
mkr host retire --host-id foo
|
41
|
+
|
39
42
|
Authentication
|
40
43
|
API key must be set to the environment variable as follows.
|
41
44
|
export MACKEREL_APIKEY=foobar
|
@@ -71,27 +74,35 @@ module Mackerel
|
|
71
74
|
end
|
72
75
|
|
73
76
|
end
|
74
|
-
|
77
|
+
|
78
|
+
when 'retire'
|
79
|
+
opt.parse!(args)
|
80
|
+
begin
|
81
|
+
res = mc.retire_host(params[:hostid])
|
82
|
+
rescue => msg
|
83
|
+
abort "Error: #{msg}"
|
84
|
+
end
|
85
|
+
|
75
86
|
when 'info'
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
rescue => msg
|
88
|
-
abort "Error: #{msg}"
|
87
|
+
opt.on('--service SERVICE'){|v| params[:service] = v }
|
88
|
+
opt.on('--role ROLE') {|v| params[:roles] = v }
|
89
|
+
opt.on('--name NAME') {|v| params[:name] = v }
|
90
|
+
opt.on('--host-id HOSTID') {|v| params[:hostId] = v }
|
91
|
+
opt.parse!(args)
|
92
|
+
begin
|
93
|
+
if params[:hostid]
|
94
|
+
res = [ mc.get_host(params[:hostId]) ]
|
95
|
+
else
|
96
|
+
res = mc.get_hosts(params)
|
89
97
|
end
|
90
|
-
|
91
|
-
|
98
|
+
rescue => msg
|
99
|
+
abort "Error: #{msg}"
|
100
|
+
end
|
101
|
+
res.each do |res|
|
102
|
+
puts <<-EOS
|
92
103
|
name: #{res.name}, status: #{res.status}, id: #{res.id}, roles: #{res.roles}
|
93
104
|
EOS
|
94
|
-
|
105
|
+
end
|
95
106
|
else
|
96
107
|
abort "Error: `#{command}` command not found for host."
|
97
108
|
end
|
@@ -95,6 +95,40 @@ describe Mackerel::Client do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
describe '#retire_host' do
|
99
|
+
let(:stubbed_response) {
|
100
|
+
[
|
101
|
+
200,
|
102
|
+
{},
|
103
|
+
JSON.dump(response_object)
|
104
|
+
]
|
105
|
+
}
|
106
|
+
|
107
|
+
let(:test_client) {
|
108
|
+
Faraday.new do |builder|
|
109
|
+
builder.adapter :test do |stubs|
|
110
|
+
stubs.post(api_path) { stubbed_response }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
}
|
114
|
+
|
115
|
+
let(:hostId) { '21obeF4PhZN' }
|
116
|
+
|
117
|
+
let(:api_path) { "/api/v0/hosts/#{hostId}/retire" }
|
118
|
+
|
119
|
+
let(:response_object) {
|
120
|
+
{ 'success' => true }
|
121
|
+
}
|
122
|
+
|
123
|
+
before do
|
124
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "successfully retire a host" do
|
128
|
+
expect(client.retire_host(hostId)).to eq(response_object)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
98
132
|
describe '#post_metrics' do
|
99
133
|
let(:stubbed_response) {
|
100
134
|
[
|
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.0.2
|
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: 2014-06-
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -77,6 +77,7 @@ extra_rdoc_files: []
|
|
77
77
|
files:
|
78
78
|
- ".gitignore"
|
79
79
|
- ".rspec"
|
80
|
+
- ".travis.yml"
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|