mackerel-client 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -33
- data/VERSION +1 -1
- data/lib/mackerel.rb +0 -1
- data/lib/mackerel/client.rb +1 -1
- data/lib/mackerel/host.rb +6 -6
- data/lib/mackerel/invitation.rb +3 -3
- data/lib/mackerel/metadata.rb +4 -4
- data/lib/mackerel/metric.rb +3 -3
- data/lib/mackerel/monitoring.rb +1 -1
- data/lib/mackerel/version.rb +1 -1
- data/mackerel-client.gemspec +1 -1
- data/spec/mackerel/client_spec.rb +1 -1
- metadata +4 -8
- data/bin/mkr.rb +0 -7
- data/lib/mackerel/runner.rb +0 -115
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f043c163694280f7233b26cf625bdba0caa646ba55d3c2cba6002772468c7b9
|
4
|
+
data.tar.gz: 7b1c11e80e5126cc8312b3d4695e0bc980f8a9c83ce3f629431a5625e89e5624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f19702d70fa6718924102398852f947f24d11721aa839af55c141819b0e4cb184b0ccf0ebaca5af3fd75c192fb1e77f2e0e72939aaa396c2a262dd9a207a24
|
7
|
+
data.tar.gz: a364791a0b00a4695f654f6fae03002a4e11cfa9e2ba5ff55265e0bffd98fa518970315f80672dfbc21108c17997777a2c744c6950b9a8cfa84e0cc91345a56c
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# mackerel-client [![Build Status](https://travis-ci.org/mackerelio/mackerel-client-ruby.svg?branch=master)](https://travis-ci.org/mackerelio/mackerel-client-ruby) [![Gem Version](https://badge.fury.io/rb/mackerel-client.png)](http://badge.fury.io/rb/mackerel-client)
|
2
2
|
|
3
|
-
mackerel-client is a ruby library to access Mackerel (https://mackerel.io/).
|
3
|
+
mackerel-client is a ruby library to access Mackerel (https://mackerel.io/).
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
@@ -30,35 +30,3 @@ Or install it yourself as:
|
|
30
30
|
```sh
|
31
31
|
gem install mackerel-client
|
32
32
|
```
|
33
|
-
|
34
|
-
# CLI
|
35
|
-
|
36
|
-
## Host
|
37
|
-
|
38
|
-
* Get host(s) information from hostname or service, role.
|
39
|
-
```
|
40
|
-
mkr.rb host info [--name foo] [--service service] [--role role]
|
41
|
-
```
|
42
|
-
|
43
|
-
* Set status of a host
|
44
|
-
```
|
45
|
-
mkr.rb host status --host-id foo --status working
|
46
|
-
```
|
47
|
-
|
48
|
-
* Retire a host
|
49
|
-
```
|
50
|
-
mkr.rb host retire --host-id foo
|
51
|
-
```
|
52
|
-
|
53
|
-
* Get status of a host (not implemented yet)
|
54
|
-
```
|
55
|
-
mkr.rb host status --host-id foo
|
56
|
-
```
|
57
|
-
|
58
|
-
Note: CLI command has been renamed to `mkr.rb` from 0.0.7.
|
59
|
-
Primary CLI `mkr` is implemented in Go (https://github.com/mackerelio/mkr).
|
60
|
-
|
61
|
-
## Authentication
|
62
|
-
```
|
63
|
-
export MACKEREL_APIKEY=foobar
|
64
|
-
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/mackerel.rb
CHANGED
data/lib/mackerel/client.rb
CHANGED
@@ -46,7 +46,7 @@ module Mackerel
|
|
46
46
|
end
|
47
47
|
|
48
48
|
private
|
49
|
-
ERROR_MESSAGE_FOR_API_KEY_ABSENCE = "API key is absent.
|
49
|
+
ERROR_MESSAGE_FOR_API_KEY_ABSENCE = "API key is absent."
|
50
50
|
|
51
51
|
def client
|
52
52
|
@client ||= http_client
|
data/lib/mackerel/host.rb
CHANGED
@@ -45,20 +45,20 @@ module Mackerel
|
|
45
45
|
def post_host(host)
|
46
46
|
command = ApiCommand.new(:post, "/api/v0/hosts", @api_key)
|
47
47
|
command.body = host.to_json
|
48
|
-
|
48
|
+
command.execute(client)
|
49
49
|
end
|
50
50
|
|
51
51
|
def update_host(host_id, host)
|
52
52
|
command = ApiCommand.new(:put, "/api/v0/hosts/#{host_id}", @api_key)
|
53
53
|
command.body = host.to_json
|
54
|
-
|
54
|
+
command.execute(client)
|
55
55
|
end
|
56
56
|
|
57
57
|
def update_host_roles(host_id, roles)
|
58
58
|
roles = [roles] if roles.is_a?(String)
|
59
59
|
command = ApiCommand.new(:put, "/api/v0/hosts/#{host_id}/role-fullnames", @api_key)
|
60
60
|
command.body = { "roleFullnames" => roles }.to_json
|
61
|
-
|
61
|
+
command.execute(client)
|
62
62
|
end
|
63
63
|
|
64
64
|
def get_host(host_id)
|
@@ -71,16 +71,16 @@ module Mackerel
|
|
71
71
|
unless [:standby, :working, :maintenance, :poweroff].include?(status.to_sym)
|
72
72
|
raise "no such status: #{status}"
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
command = ApiCommand.new(:post, "/api/v0/hosts/#{host_id}/status", @api_key)
|
76
76
|
command.body = { "status" => status }.to_json
|
77
|
-
|
77
|
+
command.execute(client)
|
78
78
|
end
|
79
79
|
|
80
80
|
def retire_host(host_id)
|
81
81
|
command = ApiCommand.new(:post, "/api/v0/hosts/#{host_id}/retire", @api_key)
|
82
82
|
command.body = { }.to_json
|
83
|
-
|
83
|
+
command.execute(client)
|
84
84
|
end
|
85
85
|
|
86
86
|
def get_hosts(opts = {})
|
data/lib/mackerel/invitation.rb
CHANGED
@@ -3,17 +3,17 @@ module Mackerel
|
|
3
3
|
module Invitation
|
4
4
|
def post_invitation(email, authority)
|
5
5
|
command = ApiCommand.new(:post, '/api/v0/invitations', @api_key)
|
6
|
-
command.body = {
|
6
|
+
command.body = {
|
7
7
|
email: email.to_s,
|
8
8
|
authority: authority.to_s
|
9
9
|
}.to_json
|
10
|
-
|
10
|
+
command.execute(client)
|
11
11
|
end
|
12
12
|
|
13
13
|
def revoke_invitation(email)
|
14
14
|
command = ApiCommand.new(:post, '/api/v0/invitations/revoke', @api_key)
|
15
15
|
command.body = { email: email.to_s }.to_json
|
16
|
-
|
16
|
+
command.execute(client)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/mackerel/metadata.rb
CHANGED
@@ -3,23 +3,23 @@ module Mackerel
|
|
3
3
|
module Metadata
|
4
4
|
def get_metadata(host_id, namespace)
|
5
5
|
command = ApiCommand.new(:get, "/api/v0/hosts/#{host_id}/metadata/#{namespace}", @api_key)
|
6
|
-
|
6
|
+
command.execute(client)
|
7
7
|
end
|
8
8
|
|
9
9
|
def list_metadata(host_id)
|
10
10
|
command = ApiCommand.new(:get, "/api/v0/hosts/#{host_id}/metadata", @api_key)
|
11
|
-
|
11
|
+
command.execute(client)
|
12
12
|
end
|
13
13
|
|
14
14
|
def update_metadata(host_id, namespace, metadata)
|
15
15
|
command = ApiCommand.new(:put, "/api/v0/hosts/#{host_id}/metadata/#{namespace}", @api_key)
|
16
16
|
command.body = metadata.to_json
|
17
|
-
|
17
|
+
command.execute(client)
|
18
18
|
end
|
19
19
|
|
20
20
|
def delete_metadata(host_id, namespace)
|
21
21
|
command = ApiCommand.new(:delete, "/api/v0/hosts/#{host_id}/metadata/#{namespace}", @api_key)
|
22
|
-
|
22
|
+
command.execute(client)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/mackerel/metric.rb
CHANGED
@@ -4,7 +4,7 @@ module Mackerel
|
|
4
4
|
def post_metrics(metrics)
|
5
5
|
command = ApiCommand.new(:post, '/api/v0/tsdb', @api_key)
|
6
6
|
command.body = metrics.to_json
|
7
|
-
|
7
|
+
command.execute(client)
|
8
8
|
end
|
9
9
|
|
10
10
|
def get_host_metrics(host_id, name, from, to)
|
@@ -27,7 +27,7 @@ module Mackerel
|
|
27
27
|
def post_service_metrics(service_name, metrics)
|
28
28
|
command = ApiCommand.new(:post, "/api/v0/services/#{service_name}/tsdb", @api_key)
|
29
29
|
command.body = metrics.to_json
|
30
|
-
|
30
|
+
command.execute(client)
|
31
31
|
end
|
32
32
|
|
33
33
|
def get_service_metrics(service_name, name, from, to)
|
@@ -42,7 +42,7 @@ module Mackerel
|
|
42
42
|
def define_graphs(graph_defs)
|
43
43
|
command = ApiCommand.new(:post, '/api/v0/graph-defs/create', @api_key)
|
44
44
|
command.body = graph_defs.to_json
|
45
|
-
|
45
|
+
command.execute(client)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
data/lib/mackerel/monitoring.rb
CHANGED
data/lib/mackerel/version.rb
CHANGED
data/mackerel-client.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Mackerel developer team"]
|
9
9
|
spec.email = ["developers@mackerel.io"]
|
10
10
|
spec.summary = 'Mackerel client implemented by Ruby.'
|
11
|
-
spec.description = 'Mackerel client is a library to access Mackerel (https://mackerel.io/).
|
11
|
+
spec.description = 'Mackerel client is a library to access Mackerel (https://mackerel.io/).'
|
12
12
|
spec.homepage = "https://mackerel.io/"
|
13
13
|
spec.license = "Apache 2"
|
14
14
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -8,7 +8,7 @@ describe Mackerel::Client do
|
|
8
8
|
|
9
9
|
describe 'initialization' do
|
10
10
|
it 'display an error message when api_key is absent' do
|
11
|
-
expected_message = "API key is absent.
|
11
|
+
expected_message = "API key is absent."
|
12
12
|
expect { Mackerel::Client.new() }.to raise_error(expected_message)
|
13
13
|
end
|
14
14
|
end
|
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.5.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: 2018-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -67,11 +67,9 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2'
|
69
69
|
description: Mackerel client is a library to access Mackerel (https://mackerel.io/).
|
70
|
-
CLI tool `mkr` is also provided.
|
71
70
|
email:
|
72
71
|
- developers@mackerel.io
|
73
|
-
executables:
|
74
|
-
- mkr.rb
|
72
|
+
executables: []
|
75
73
|
extensions: []
|
76
74
|
extra_rdoc_files: []
|
77
75
|
files:
|
@@ -84,7 +82,6 @@ files:
|
|
84
82
|
- RELEASE.md
|
85
83
|
- Rakefile
|
86
84
|
- VERSION
|
87
|
-
- bin/mkr.rb
|
88
85
|
- example/01_invitation.rb
|
89
86
|
- example/02_dashboard.rb
|
90
87
|
- example/03_host.rb
|
@@ -112,7 +109,6 @@ files:
|
|
112
109
|
- lib/mackerel/notification_group.rb
|
113
110
|
- lib/mackerel/organization.rb
|
114
111
|
- lib/mackerel/role.rb
|
115
|
-
- lib/mackerel/runner.rb
|
116
112
|
- lib/mackerel/service.rb
|
117
113
|
- lib/mackerel/user.rb
|
118
114
|
- lib/mackerel/version.rb
|
@@ -152,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
148
|
version: '0'
|
153
149
|
requirements: []
|
154
150
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.7.6
|
156
152
|
signing_key:
|
157
153
|
specification_version: 4
|
158
154
|
summary: Mackerel client implemented by Ruby.
|
data/bin/mkr.rb
DELETED
data/lib/mackerel/runner.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'json' unless defined? ::JSON
|
3
|
-
|
4
|
-
module Mackerel
|
5
|
-
|
6
|
-
class Runner
|
7
|
-
attr_reader :args
|
8
|
-
|
9
|
-
def initialize(args)
|
10
|
-
|
11
|
-
args.unshift 'help' if args.empty?
|
12
|
-
|
13
|
-
@args = args
|
14
|
-
cmd = args.shift
|
15
|
-
|
16
|
-
if Runner.method_defined?(cmd) and cmd != 'run'
|
17
|
-
send(cmd, args)
|
18
|
-
else
|
19
|
-
puts "Error: `#{cmd}` command not found.\n\n"
|
20
|
-
send('help', args)
|
21
|
-
abort
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Shortcut
|
26
|
-
def self.execute(args)
|
27
|
-
new(args)
|
28
|
-
end
|
29
|
-
|
30
|
-
def help(args)
|
31
|
-
puts <<-EOS
|
32
|
-
#{$0}: Command line interface for Mackerel (https://mackerel.io/).
|
33
|
-
Get host(s) information from hostname or service, role.
|
34
|
-
mkr host info [--name foo] [--service service] [--role role]
|
35
|
-
|
36
|
-
Set status of a host
|
37
|
-
mkr host status --host-id foo --status working
|
38
|
-
|
39
|
-
Retire a host
|
40
|
-
mkr host retire --host-id foo
|
41
|
-
|
42
|
-
Authentication
|
43
|
-
API key must be set to the environment variable as follows.
|
44
|
-
export MACKEREL_APIKEY=foobar
|
45
|
-
|
46
|
-
EOS
|
47
|
-
end
|
48
|
-
|
49
|
-
# mkr host status --host-id foo
|
50
|
-
def host(args)
|
51
|
-
mc = Mackerel::Client.new(:mackerel_api_key => ENV['MACKEREL_APIKEY'])
|
52
|
-
params = {}
|
53
|
-
opt = OptionParser.new
|
54
|
-
opt.on('--host-id HOSTID'){|v| params[:hostid] = v }
|
55
|
-
|
56
|
-
cmd = args.shift
|
57
|
-
case cmd
|
58
|
-
when 'status'
|
59
|
-
opt.on('--status STATUS'){|v| params[:status] = v }
|
60
|
-
opt.parse!(args)
|
61
|
-
if params[:status]
|
62
|
-
begin
|
63
|
-
res = mc.update_host_status(params[:hostid], params[:status])
|
64
|
-
puts "Updated to '#{params[:status]}'"
|
65
|
-
rescue => msg
|
66
|
-
abort "Error: #{msg}"
|
67
|
-
end
|
68
|
-
else
|
69
|
-
begin
|
70
|
-
res = mc.get_hosts(:hostid => params[:hostid])[0]
|
71
|
-
puts "#{res.status}"
|
72
|
-
rescue => msg
|
73
|
-
abort "Error: #{msg}"
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
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
|
-
|
86
|
-
when 'info'
|
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.on('--custom-identifier IDENTIFIER') {|v| params[:customIdentifier] = v }
|
92
|
-
opt.parse!(args)
|
93
|
-
begin
|
94
|
-
if params[:hostid]
|
95
|
-
res = [ mc.get_host(params[:hostId]) ]
|
96
|
-
else
|
97
|
-
res = mc.get_hosts(params)
|
98
|
-
end
|
99
|
-
rescue => msg
|
100
|
-
abort "Error: #{msg}"
|
101
|
-
end
|
102
|
-
res.each do |res|
|
103
|
-
puts <<-EOS
|
104
|
-
name: #{res.name}, status: #{res.status}, id: #{res.id}, roles: #{res.roles}
|
105
|
-
EOS
|
106
|
-
end
|
107
|
-
else
|
108
|
-
abort "Error: `#{command}` command not found for host."
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
|