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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82cd57e63e053eb6b8b4fd8c0d89c4747fba5937
4
- data.tar.gz: 0394eeecb9618458630f2520a7af71375a4c8d12
3
+ metadata.gz: 6469f220c097bfce9c5410a1897c517cf498f396
4
+ data.tar.gz: 1e343adc7d72fd577f2d1a12c2fa022382186114
5
5
  SHA512:
6
- metadata.gz: 453706639f925b91cfe33bd3cba00f4d797f83ba5d9522e8f608d5b5e5f15b47dfb790fb34d9432f3c2905f807ef8ce3356f8880f3a558eb2c45722c24203e1f
7
- data.tar.gz: a87577caee432f325600cfecf4cd6e934b6f228e62d126358bb5c6a2081bbd3a9a34ccd4b9f8e8928b2f654d3d28fbd1ba1bf44ac232e123322c308b970c3a78
6
+ metadata.gz: 65fa9d1846465abc5b741b2785fe02a3cc617c34c438f2a51089d3919ea36aeb6aef5661fe5b636a0f9c53ed8f808495c85ea8e26ebbdd21a0d1017be6ebcf18
7
+ data.tar.gz: 1e26dc9a86fd0118176cad8d3ad11ff0536c4633b06e46dedd29ab331cdde25a8691877faa60c0a7097e6a89a779beb804d7605aca221b2c84526a465c3e8cf5
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.1.1"
4
+ - "2.0.0"
5
+ - "1.9.3"
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
- # Mackerel::Client
2
-
3
- TODO: Write a gem description
1
+ # mackerel-client [![Build Status](https://travis-ci.org/mackerelio/mackerel-client-ruby.svg?branch=master)](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
1
+ 0.0.2
@@ -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
 
@@ -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
- opt.on('--service SERVICE'){|v| params[:service] = v }
77
- opt.on('--role ROLE') {|v| params[:role] = v }
78
- opt.on('--name NAME') {|v| params[:name] = v }
79
- opt.on('--host-id HOSTID') {|v| params[:hostId] = v }
80
- opt.parse!(args)
81
- begin
82
- if params[:hostid]
83
- res = [ mc.get_host(params[:hostId]) ]
84
- else
85
- res = mc.get_hosts(params)
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
- res.each do |res|
91
- puts <<-EOS
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
- end
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.1
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-13 00:00:00.000000000 Z
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