mackerel-client 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/example/01_invitation.rb +12 -0
  4. data/example/02_dashboard.rb +29 -0
  5. data/example/03_host.rb +97 -0
  6. data/example/04_metrics.rb +44 -0
  7. data/example/05_service_role.rb +10 -0
  8. data/example/06_annotation.rb +26 -0
  9. data/example/07_monitoring.rb +100 -0
  10. data/example/08_alert.rb +10 -0
  11. data/example/Gemfile +6 -0
  12. data/lib/mackerel/alert.rb +48 -0
  13. data/lib/mackerel/annotation.rb +61 -0
  14. data/lib/mackerel/api_command.rb +67 -0
  15. data/lib/mackerel/channel.rb +32 -0
  16. data/lib/mackerel/client.rb +30 -154
  17. data/lib/mackerel/dashboard.rb +71 -0
  18. data/lib/mackerel/host.rb +62 -0
  19. data/lib/mackerel/invitation.rb +20 -0
  20. data/lib/mackerel/metadata.rb +15 -47
  21. data/lib/mackerel/metric.rb +50 -0
  22. data/lib/mackerel/monitor.rb +23 -53
  23. data/lib/mackerel/monitoring.rb +13 -0
  24. data/lib/mackerel/notification_group.rb +58 -0
  25. data/lib/mackerel/organization.rb +33 -0
  26. data/lib/mackerel/role.rb +24 -0
  27. data/lib/mackerel/service.rb +51 -0
  28. data/lib/mackerel/user.rb +42 -0
  29. data/lib/mackerel/version.rb +3 -0
  30. data/lib/mackerel.rb +2 -3
  31. data/spec/mackerel/alert_spec.rb +103 -0
  32. data/spec/mackerel/annotation_spec.rb +208 -0
  33. data/spec/mackerel/channel_spec.rb +50 -0
  34. data/spec/mackerel/client_spec.rb +69 -103
  35. data/spec/mackerel/dashboard_spec.rb +252 -0
  36. data/spec/mackerel/invitation_spec.rb +93 -0
  37. data/spec/mackerel/metric_spec.rb +287 -0
  38. data/spec/mackerel/monitor_spec.rb +4 -4
  39. data/spec/mackerel/monitoring_spec.rb +71 -0
  40. data/spec/mackerel/notification_group_spec.rb +274 -0
  41. data/spec/mackerel/organization_spec.rb +47 -0
  42. data/spec/mackerel/service_spec.rb +155 -0
  43. data/spec/mackerel/user_spec.rb +99 -0
  44. metadata +47 -2
@@ -0,0 +1,155 @@
1
+ require 'mackerel'
2
+ require 'mackerel/host'
3
+ require 'json'
4
+
5
+ describe Mackerel::Client do
6
+ let(:api_key) { 'xxxxxxxx' }
7
+ let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
+
9
+ describe '#get_services' do
10
+
11
+ let(:api_path) { "/api/v0/services" }
12
+ let(:stubbed_response) {
13
+ [
14
+ 200,
15
+ {},
16
+ JSON.dump(response_object)
17
+ ]
18
+ }
19
+
20
+ let(:test_client) {
21
+ Faraday.new do |builder|
22
+ builder.adapter :test do |stubs|
23
+ stubs.get(api_path) { stubbed_response }
24
+ end
25
+ end
26
+ }
27
+
28
+ let(:services) {
29
+ {
30
+ "services" => [
31
+ {
32
+ "name" => "Web",
33
+ "memo" => "store",
34
+ "roles" => [
35
+ "normal role",
36
+ "special role"
37
+ ]
38
+ },
39
+ {
40
+ "name" => "Web",
41
+ "memo" => "store",
42
+ "roles" => [
43
+ "a role",
44
+ "the role"
45
+ ]
46
+ }
47
+ ]
48
+ }
49
+ }
50
+
51
+ let(:response_object) {
52
+ services
53
+ }
54
+
55
+ before do
56
+ allow(client).to receive(:http_client).and_return(test_client)
57
+ end
58
+
59
+ it "successfully get services" do
60
+ expect(client.get_services().map(&:to_h)).to eq(services['services'])
61
+ end
62
+ end
63
+
64
+
65
+ describe '#get_roles' do
66
+
67
+ let(:api_path) { "/api/v0/services/#{serviceName}/roles" }
68
+ let(:stubbed_response) {
69
+ [
70
+ 200,
71
+ {},
72
+ JSON.dump(response_object)
73
+ ]
74
+ }
75
+
76
+ let(:test_client) {
77
+ Faraday.new do |builder|
78
+ builder.adapter :test do |stubs|
79
+ stubs.get(api_path) { stubbed_response }
80
+ end
81
+ end
82
+ }
83
+
84
+ let(:serviceName) { "WebSite" }
85
+ let(:roles) {
86
+ {
87
+ "roles" => [
88
+ {
89
+ "name" => "Web",
90
+ "memo" => "Apache2.2",
91
+ },
92
+ {
93
+ "name" => "DB",
94
+ "memo" => "Relational Database",
95
+ }
96
+ ]
97
+ }
98
+ }
99
+
100
+ let(:response_object) {
101
+ roles
102
+ }
103
+
104
+ before do
105
+ allow(client).to receive(:http_client).and_return(test_client)
106
+ end
107
+
108
+ it "successfully get services" do
109
+ expect(client.get_roles(serviceName).map(&:to_h)).to eq(roles['roles'])
110
+ end
111
+ end
112
+
113
+
114
+ describe '#get_service_metric_names' do
115
+
116
+ let(:api_path) { "/api/v0/services/#{serviceName}/metric-names" }
117
+ let(:stubbed_response) {
118
+ [
119
+ 200,
120
+ {},
121
+ JSON.dump(response_object)
122
+ ]
123
+ }
124
+
125
+ let(:test_client) {
126
+ Faraday.new do |builder|
127
+ builder.adapter :test do |stubs|
128
+ stubs.get(api_path) { stubbed_response }
129
+ end
130
+ end
131
+ }
132
+
133
+ let(:serviceName) { "WebSite" }
134
+ let(:metricNames) {
135
+ {
136
+ "names" => [
137
+ "CPU","Memory","Filesystem"
138
+ ]
139
+ }
140
+ }
141
+
142
+ let(:response_object) {
143
+ metricNames
144
+ }
145
+
146
+ before do
147
+ allow(client).to receive(:http_client).and_return(test_client)
148
+ end
149
+
150
+ it "successfully get services" do
151
+ expect(client.get_service_metric_names(serviceName)).to eq(metricNames['names'])
152
+ end
153
+ end
154
+
155
+ end
@@ -0,0 +1,99 @@
1
+ require 'mackerel'
2
+ require 'mackerel/host'
3
+ require 'json'
4
+
5
+ describe Mackerel::Client do
6
+ let(:api_key) { 'xxxxxxxx' }
7
+ let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
+
9
+ describe '#get_users' do
10
+
11
+ let(:api_path) { "/api/v0/users" }
12
+ let(:stubbed_response) {
13
+ [
14
+ 200,
15
+ {},
16
+ JSON.dump(response_object)
17
+ ]
18
+ }
19
+
20
+ let(:test_client) {
21
+ Faraday.new do |builder|
22
+ builder.adapter :test do |stubs|
23
+ stubs.get(api_path) { stubbed_response }
24
+ end
25
+ end
26
+ }
27
+
28
+ let(:users) {
29
+ {
30
+ "users" => [
31
+ {
32
+ "id" => "XhHAo07",
33
+ "screenName" => "WebServer",
34
+ "email" => "hogehoge-exmaple@example.com"
35
+ },
36
+ {
37
+ "id" => "YkLBo38",
38
+ "screenName" => "DBServer",
39
+ "email" => "fugafuga-exmaple@example.com"
40
+ }
41
+ ]
42
+ }
43
+ }
44
+
45
+ let(:response_object) {
46
+ users
47
+ }
48
+
49
+ before do
50
+ allow(client).to receive(:http_client).and_return(test_client)
51
+ end
52
+
53
+ it "successfully get users" do
54
+ expect(client.get_users().map(&:to_h)).to eq(users['users'])
55
+ end
56
+ end
57
+
58
+ describe '#remove_users' do
59
+
60
+ let(:api_path) { "/api/v0/users/#{user_id}" }
61
+ let(:stubbed_response) {
62
+ [
63
+ 200,
64
+ {},
65
+ JSON.dump(response_object)
66
+ ]
67
+ }
68
+
69
+ let(:test_client) {
70
+ Faraday.new do |builder|
71
+ builder.adapter :test do |stubs|
72
+ stubs.delete(api_path) { stubbed_response }
73
+ end
74
+ end
75
+ }
76
+
77
+ let(:user_id) { "XhHAo07" }
78
+ let(:user) {
79
+ {
80
+ "id" => user_id,
81
+ "screenName" => "WebServer",
82
+ "email" => "hogehoge-exmaple@example.com"
83
+ }
84
+ }
85
+
86
+ let(:response_object) {
87
+ user
88
+ }
89
+
90
+ before do
91
+ allow(client).to receive(:http_client).and_return(test_client)
92
+ end
93
+
94
+ it "successfully delete users" do
95
+ expect(client.remove_user(user_id).to_h).to eq(user)
96
+ end
97
+ end
98
+
99
+ 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.3.0
4
+ version: 0.4.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: 2017-10-05 00:00:00.000000000 Z
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -85,18 +85,52 @@ files:
85
85
  - Rakefile
86
86
  - VERSION
87
87
  - bin/mkr.rb
88
+ - example/01_invitation.rb
89
+ - example/02_dashboard.rb
90
+ - example/03_host.rb
91
+ - example/04_metrics.rb
92
+ - example/05_service_role.rb
93
+ - example/06_annotation.rb
94
+ - example/07_monitoring.rb
95
+ - example/08_alert.rb
96
+ - example/Gemfile
88
97
  - lib/mackerel-client.rb
89
98
  - lib/mackerel.rb
99
+ - lib/mackerel/alert.rb
100
+ - lib/mackerel/annotation.rb
101
+ - lib/mackerel/api_command.rb
102
+ - lib/mackerel/channel.rb
90
103
  - lib/mackerel/client.rb
91
104
  - lib/mackerel/client/helper.rb
105
+ - lib/mackerel/dashboard.rb
92
106
  - lib/mackerel/host.rb
107
+ - lib/mackerel/invitation.rb
93
108
  - lib/mackerel/metadata.rb
109
+ - lib/mackerel/metric.rb
94
110
  - lib/mackerel/monitor.rb
111
+ - lib/mackerel/monitoring.rb
112
+ - lib/mackerel/notification_group.rb
113
+ - lib/mackerel/organization.rb
114
+ - lib/mackerel/role.rb
95
115
  - lib/mackerel/runner.rb
116
+ - lib/mackerel/service.rb
117
+ - lib/mackerel/user.rb
118
+ - lib/mackerel/version.rb
96
119
  - mackerel-client.gemspec
120
+ - spec/mackerel/alert_spec.rb
121
+ - spec/mackerel/annotation_spec.rb
122
+ - spec/mackerel/channel_spec.rb
97
123
  - spec/mackerel/client/helper_spec.rb
98
124
  - spec/mackerel/client_spec.rb
125
+ - spec/mackerel/dashboard_spec.rb
126
+ - spec/mackerel/invitation_spec.rb
127
+ - spec/mackerel/metric_spec.rb
99
128
  - spec/mackerel/monitor_spec.rb
129
+ - spec/mackerel/monitoring_spec.rb
130
+ - spec/mackerel/notification_group_spec.rb
131
+ - spec/mackerel/organization_spec.rb
132
+ - spec/mackerel/service_spec.rb
133
+ - spec/mackerel/user_spec.rb
100
134
  - spec/spec_helper.rb
101
135
  homepage: https://mackerel.io/
102
136
  licenses:
@@ -123,7 +157,18 @@ signing_key:
123
157
  specification_version: 4
124
158
  summary: Mackerel client implemented by Ruby.
125
159
  test_files:
160
+ - spec/mackerel/alert_spec.rb
161
+ - spec/mackerel/annotation_spec.rb
162
+ - spec/mackerel/channel_spec.rb
126
163
  - spec/mackerel/client/helper_spec.rb
127
164
  - spec/mackerel/client_spec.rb
165
+ - spec/mackerel/dashboard_spec.rb
166
+ - spec/mackerel/invitation_spec.rb
167
+ - spec/mackerel/metric_spec.rb
128
168
  - spec/mackerel/monitor_spec.rb
169
+ - spec/mackerel/monitoring_spec.rb
170
+ - spec/mackerel/notification_group_spec.rb
171
+ - spec/mackerel/organization_spec.rb
172
+ - spec/mackerel/service_spec.rb
173
+ - spec/mackerel/user_spec.rb
129
174
  - spec/spec_helper.rb